-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.py
executable file
·86 lines (65 loc) · 2.14 KB
/
install.py
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
#!/usr/bin/env python3
import sys
import platform
from utils.utils import settings
from utils.chalk import print_banner, Color, print_error
from utils.installer import exec_installer
def run_installer(name, args=[]):
try:
installer = settings["installers"][name]
except AttributeError:
print_error(f"Installer {name} is not defined")
return 1
if "alias" in installer:
alias_name = installer["alias"]
installer = settings["installers"][alias_name]
if "path" not in installer:
installer["path"] = alias_name
if "path" in installer:
return exec_installer(installer["path"], name, args, settings=settings)
else:
return exec_installer(name, name, args, settings=settings)
def main(args):
if platform.system() == "Windows":
print("These dotfiles are written for Linux and macOS only")
return 1
print_banner("LEE'S DOTFILES", Color.BLUE)
if not args: # Install all autorun modules
for name, i in settings["installers"].items():
if "autorun" in i and i["autorun"]:
run_installer(name)
return 0
elif len(args) == 1: # Simple, run one module
return run_installer(args[0], [])
else: # Run multiple modules, possibly with arguments
module_playbook = parse_args(args)
for name, play in module_playbook.items():
exit_code = run_installer(name, play["args"])
if exit_code != 0:
return exit_code
def parse_args(args=[]):
modules = {}
if not args:
return modules
if args[0] == "--":
for arg in args[1:]:
modules[arg] = {"args": []}
return modules
while True:
try:
module_name = args.pop(0)
except:
break
module_args = []
while True:
try:
arg = args.pop(0)
except:
break
if arg == "--":
break
module_args.append(arg)
modules[module_name] = {"args": module_args}
return modules
if __name__ == "__main__":
exit(main(sys.argv[1:]))