-
Notifications
You must be signed in to change notification settings - Fork 0
/
vogon
executable file
·99 lines (77 loc) · 2.62 KB
/
vogon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python3
import argparse
import json
import pathlib
import sys
from bureaucracy import VogonBuilder, VogonExplorer, VogonPoet
subcommands = ["poet", "explorer", "build"]
parser = argparse.ArgumentParser(description="~@ vogon @~")
subparsers = parser.add_subparsers()
subparser_poet = subparsers.add_parser("poet")
subparser_explorer = subparsers.add_parser("explorer")
for name, subparser in {"poet": subparser_poet, "explorer": subparser_explorer}.items():
subparser.set_defaults(variant=name)
subparser.add_argument(
"-i",
"--image",
help="Name of Docker image to start the vogon container, if not using the vogon default.",
)
subparser.add_argument(
"-r",
"--repo",
help="Mount a local host directory to /repos within the container. Defaults to the current directory.",
default=".",
)
subparser.add_argument(
"-m",
"--mnt-dir",
help="Mount a local host directory to /mnt within the container.",
)
subparser.add_argument(
"-j",
"--jupyterlab",
help="Run a JupyterLab session out of the container, using /mnt.",
action="store_true",
)
subparser.add_argument(
"-s",
"--ssh",
help="Mount local host ~/.ssh folder within the container.",
action="store_true",
)
subparser_build = subparsers.add_parser("build")
subparser_build.set_defaults(variant="build")
def main():
args = parser.parse_args()
vogon_config_file = pathlib.Path.home() / ".vogonconfig"
if vogon_config_file.exists():
with open(vogon_config_file, "r") as fh:
vogon_config = json.load(fh)
else:
vogon_config = {}
if args.variant == "build":
vogon = VogonBuilder()
else:
if args.image:
image = args.image
elif vogon_config.get("default_image", None):
image = vogon_config["default_image"]
else:
raise Exception(
"No image name specified. Either use the -i flag or define a default_image in your ~/.vogonconfig file."
)
if args.variant == "poet":
vogon = VogonPoet(
docker_image_name=image,
repo_dir=args.repo,
mnt_dir=args.mnt_dir,
start_jupyter_lab=args.jupyterlab,
mount_ssh_dir=args.ssh
)
elif args.variant == "explorer":
raise NotImplementedError(
"VogonExplorer is currently under intergalactic highway construction."
)
vogon.launch()
if __name__ == "__main__":
sys.exit(main())