-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile
executable file
·155 lines (142 loc) · 6.45 KB
/
compile
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/python3
import os
import shutil
import sys
import compileall as Compiler
from os import listdir
from os.path import isfile, join
def boolquestion(question, default="yes"):
"""Ask a yes/no question via input() and return their answer.
"question" is a string that is presented to the user.
"default" is the presumed answer if the user just hits <Enter>.
It must be "yes" (the default), "no" or None (meaning
an answer is required of the user).
The "answer" return value is True for "yes" or False for "no".
"""
valid = {"yes": True, "y": True, "ye": True,
"no": False, "n": False}
if default is None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while True:
sys.stdout.write(question + prompt)
choice = input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' "
"(or 'y' or 'n').\n")
print("Compiling...")
Compiler.compile_dir("src/")
print("./bin Check...")
if os.path.exists("bin"):
shutil.rmtree("bin")
os.makedirs("bin")
os.makedirs("bin/modules")
print("Moving compiled files...")
cachepath = "src/__pycache__"
files = [f for f in listdir(cachepath) if isfile(join(cachepath, f))]
for file in files:
shutil.move(join(cachepath, file), "bin/{}.pyc".format(file.split(".")[0]))
cachepath = "src/modules/__pycache__"
files = [f for f in listdir(cachepath) if isfile(join(cachepath, f))]
for file in files:
shutil.move(join(cachepath, file), "bin/modules/{}.pyc".format(file.split(".")[0]))
print("Renaming gadis-server.pyc...")
os.rename("bin/gadis-server.pyc", "bin/gadis-server")
print("Renaming gadis-remote.pyc...")
os.rename("bin/gadis-remote.pyc", "bin/gadis-remote")
print("Cleaning up...")
shutil.rmtree("src/__pycache__")
shutil.rmtree("src/modules/__pycache__")
install = boolquestion("Install it now?")
if install:
installusers = boolquestion("Install for all users? (requires root)")
if not installusers:
home_dir = os.path.expanduser('~/.gadis/')
if os.path.exists(os.path.join(home_dir, "share/gadis")):
shutil.rmtree(os.path.join(home_dir, "share/gadis"))
os.makedirs(os.path.join(home_dir, "share/gadis"))
if not os.path.exists(os.path.join(home_dir, "bin")):
os.makedirs(os.path.join(home_dir, "bin"))
shutil.move("bin/modules", os.path.join(home_dir, "share/gadis/modules"))
if os.path.exists(os.path.join(home_dir, "bin/gadis")):
os.remove(os.path.join(home_dir, "bin/gadis"))
if os.path.exists(os.path.join(home_dir, "bin/gadisctl")):
os.remove(os.path.join(home_dir, "bin/gadisctl"))
if os.path.exists(os.path.join(home_dir, "bin/gadisdev")):
os.remove(os.path.join(home_dir, "bin/gadisdev"))
if os.path.exists(os.path.join(home_dir, "bin/gadis-server")):
os.remove(os.path.join(home_dir, "bin/gadis-server"))
if os.path.exists(os.path.join(home_dir, "bin/gadis-remote")):
os.remove(os.path.join(home_dir, "bin/gadis-remote"))
shutil.move("bin/gadis-server", os.path.join(home_dir, "bin/"))
os.chmod(os.path.join(home_dir, "bin/gadis-server"), 0o755)
shutil.move("bin/gadis-remote", os.path.join(home_dir, "bin/"))
os.chmod(os.path.join(home_dir, "bin/gadis-remote"), 0o755)
shutil.copy("src/gadis", os.path.join(home_dir, "bin/gadis"))
os.chmod(os.path.join(home_dir, "bin/gadis"), 0o755)
shutil.copy("src/gadisctl", os.path.join(home_dir, "bin/gadisctl"))
os.chmod(os.path.join(home_dir, "bin/gadisctl"), 0o755)
shutil.copy("src/gadisdev", os.path.join(home_dir, "bin/gadisdev"))
os.chmod(os.path.join(home_dir, "bin/gadisdev"), 0o755)
print("As a user only install, you may want to add ~/.gadis/bin to your PATH environment variable.")
print("NOTE: gadisdev was designed toward root use, this can be changed however and requires manually editing ~/.gadis/bin/gadisdev")
print("Future updates will allow for easier detection on environment on gadisdev, apologies for the inconvenience.")
files = [f for f in listdir("bin") if isfile(join("bin", f))]
for file in files:
shutil.move(join("bin", file), join(os.path.join(home_dir, "share/gadis", file)))
else:
instroot = boolquestion("Will root manage Gadis?")
if os.path.exists("/usr/local/share/gadis"):
shutil.rmtree("/usr/local/share/gadis")
os.makedirs("/usr/local/share/gadis")
shutil.move("bin/modules", "/usr/local/share/gadis/modules")
if os.path.exists("/usr/local/sbin/gadis"):
os.remove("/usr/local/sbin/gadis")
if os.path.exists("/usr/local/bin/gadis"):
os.remove("/usr/local/bin/gadis")
if os.path.exists("/usr/local/bin/gadisctl"):
os.remove("/usr/local/bin/gadisctl")
if os.path.exists("/usr/local/bin/gadisdev") and instroot:
os.remove("/usr/local/bin/gadisdev")
if os.path.exists("/usr/local/bin/gadis-server"):
os.remove("/usr/local/bin/gadis-server")
if os.path.exists("/usr/local/bin/gadis-remote"):
os.remove("/usr/local/bin/gadis-remote")
if os.path.exists("/usr/local/sbin/gadisctl"):
os.remove("/usr/local/bin/gadisctl")
if os.path.exists("/usr/local/sbin/gadisdev"):
os.remove("/usr/local/bin/gadisdev")
if os.path.exists("/usr/local/sbin/gadis-server"):
os.remove("/usr/local/bin/gadis-server")
if os.path.exists("/usr/local/sbin/gadis-remote"):
os.remove("/usr/local/bin/gadis-remote")
shutil.move("bin/gadis-server", "/usr/local/bin/")
os.chmod("/usr/local/bin/gadis-server", 0o755)
shutil.move("bin/gadis-remote", "/usr/local/bin/")
os.chmod("/usr/local/bin/gadis-remote", 0o755)
shutil.copy("src/gadis", "/usr/local/bin/gadis")
os.chmod("/usr/local/bin/gadis", 0o755)
if instroot:
shutil.copy("src/gadisctl", "/usr/local/sbin/gadisctl")
os.chmod("/usr/local/sbin/gadisctl", 0o755)
shutil.copy("src/gadisdev", "/usr/local/sbin/gadisdev")
os.chmod("/usr/local/sbin/gadisdev", 0o755)
else:
shutil.copy("src/gadisctl", "/usr/local/bin/gadisctl")
os.chmod("/usr/local/bin/gadisctl", 0o755)
shutil.copy("src/gadisdev", "/usr/local/bin/gadisdev")
os.chmod("/usr/local/bin/gadisdev", 0o755)
print("NOTE: gadisdev was designed toward root use, this can be changed however and requires manually editing /usr/local/bin/gadisdev")
print("Future updates will allow for easier detection on environment on gadisdev, apologies for the inconvenience.")
files = [f for f in listdir("bin") if isfile(join("bin", f))]
for file in files:
shutil.move(join("bin", file), join("/usr/local/share/gadis", file))