-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildServerConnect.py
executable file
·180 lines (147 loc) · 4.35 KB
/
buildServerConnect.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python3
from zipfile import ZipFile, ZIP_BZIP2
import os, sys, shutil, platform
target = "connect.py"
rootDir = os.path.dirname(os.path.realpath(__file__)) + "/"
srcDir = rootDir+"src"
winPackage = rootDir+"Server_Connect-Windows"
winPackageZip = winPackage + ".zip"
unixPackage = rootDir+"Server_Connect-macOS_Linux"
unixPackageZip = unixPackage + ".zip"
def build():
os.chdir(srcDir)
files = os.listdir()
with ZipFile(target,'w') as zip:
for file in files:
zip.write(file)
shutil.move(target, f"{rootDir}{target}")
os.chdir(rootDir)
def package(isWindows):
folderName = ""
installUninstallPath = "Install_Uninstall_Scripts/"
runScript = "run_scripts/connect"
installScript = "install"
uninstallScript = "uninstall"
if(isWindows):
folderName = winPackage
runScript += ".bat"
prefix = installUninstallPath + "Windows" + "/"
installScript = prefix + installScript + ".bat"
uninstallScript = prefix + uninstallScript + ".bat"
else:
folderName = unixPackage
runScript += ".sh"
prefix = installUninstallPath + "macOS_Linux" + "/"
installScript = prefix + installScript
uninstallScript = prefix + uninstallScript
filesList = [
target,
"README.md",
"LICENSE",
runScript,
installScript,
uninstallScript
]
if(os.path.isdir(folderName)):
shutil.rmtree(folderName)
os.mkdir(folderName)
for f in filesList:
shutil.copy2(f, folderName)
def packageAll():
package(True)
package(False)
def zipPackage(isWindows):
packageDir = unixPackage
zipPack = unixPackageZip
if(isWindows):
packageDir = winPackage
zipPack = winPackageZip
os.chdir(packageDir)
files = os.listdir()
with ZipFile(zipPack,'w', ZIP_BZIP2, True, 9) as zip:
for file in files:
zip.write(file)
os.chdir(rootDir)
def zipAll():
zipPackage(True)
zipPackage(False)
def installServerConnect(isWindows):
packageDir = unixPackage
installCMD = "./install"
if(isWindows):
packageDir = winPackage
installCMD = "install.bat"
os.chdir(packageDir)
os.system(installCMD)
os.chdir(rootDir)
def clean():
objsToRemove = [
target,
winPackage,
winPackageZip,
unixPackage,
unixPackageZip
]
for o in objsToRemove:
try:
if(os.path.isdir(o)):
shutil.rmtree(o)
else:
os.remove(o)
except:
pass
def printHelp():
print(f"Usage: {sys.argv[0]} [option]\n\n")
print('''Options:
build Create the connect.py file (default)
Note: if no option is passed this will be run
package Create a package bundle of all the files needed for
your given operating system
package-all Create packages for both Windows and Unix
zip Create a zip containing all the files needed for
your given operating system
zip-all Create zips for both Windows and Unix
install Installs Server Connect
clean Remove the package bundles, zip's, and connect.py
''')
if __name__ == "__main__":
if(len(sys.argv) < 2):
build()
exit()
if(len(sys.argv) == 2):
arg = sys.argv[1].lower()
isWindows = platform.system() == "Windows"
if(arg == "-h" or arg == "--help" or arg == "help"):
printHelp()
exit()
elif(arg == "build"):
build()
exit()
elif(arg == "clean"):
clean()
exit()
elif(arg == "package"):
build()
package(isWindows)
exit()
elif(arg == "package-all"):
build()
packageAll()
exit()
elif(arg == "zip"):
build()
package(isWindows)
zipPackage(isWindows)
exit()
elif(arg == "zip-all"):
build()
packageAll()
zipAll()
exit()
elif(arg == "install"):
build()
package(isWindows)
installServerConnect(isWindows)
exit()
print(f"Unrecognized rule \'{sys.argv[1]}\'")
printHelp()