-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy.py
310 lines (262 loc) · 12 KB
/
deploy.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
##version: Python 3.6.7
import sys
import os
import datetime
import platform
import subprocess
import argparse
import shutil
import distutils.dir_util
import stat
import tarfile
import zipfile
knownArgs = ""
def argumentReader():
arr = []
parser = argparse.ArgumentParser(description='To allow downloading of EPICS on different Systems')
parser.add_argument('-c', '--changeconfig', nargs='?',help='Allows for you to have a unqiue config file.')
check = parser.parse_known_args()
knownArgs = vars(check[0])
if knownArgs['changeconfig'] is not None:
change_config = knownArgs['changeconfig']
arr.append(str(change_config))
print("I am going to change the config " + str(change_config))
else:
change_config = "configure"
arr.append(change_config)
return arr
list = argumentReader()
change_config = list[0]
arg3 = ""
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Starting Script~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
myCmds = [] ##I created a array that will store all my commands that i want to exectue on the command line
##I have to fgiure out if its a windows OS or a linux OS prior to do thing anything.
OS = platform.system()
## This is for linux command line
myCmds.append('find -name auto_settings.sav_* -exec rm -fv {} \\;')
myCmds.append('find -name auto_settings.savB* -exec rm -fv {} \\;')
myCmds.append('find -name core.* -exec rm -fv {} \\;')
myCmds.append('find -name *.exe.* -exec rm -fv {} \\;')
## The exectution of my commands that I have placed in my array
os.system(myCmds[0])
os.system(myCmds[1])
os.system(myCmds[2])
os.system(myCmds[3])
DATE = datetime.datetime.now()
checkMyOS = "more /etc/issue | cut -d '\\' -f1 | tr ' ' _"
OS = os.popen(checkMyOS).read()
if OS.startswith("Invalid"):
OS = platform.system()
##Naming the tar file to be
NAME = arg3 + "_" + str(OS) + str(DATE)
NAME = NAME.replace("\n","")
NAME = NAME.replace("'","")
NAME = NAME.replace("$","")
NAME = NAME.replace(" ","_")
NAME = NAME.replace(":","-")
## Path to the folder that will be containing the tar
# will be created if it does nto exists
DESTINATION = "DEPLOYMENTS"
myCmds = []
myCmds = ["mkdir " + DESTINATION + "", "rm -rf temp"
,"mkdir temp","cp components/scripts/generateEnvPaths.sh temp",
]
for i in range(len(myCmds)):
temp = myCmds[i]
os.system(temp)
os.chmod("temp/",0o777)
HOME = os.popen("pwd").read()
myCmdHome = "cd "+ HOME + ""
change_config = change_config
change_config = change_config.replace("\n", "")
HOME = HOME.replace("\n","")
AREA_DETECTOR= "areaDetector/"
os.system(HOME)
readMe = "README_"+NAME+".txt"
file = open(DESTINATION+"/"+readMe, "w")
tarFile = NAME + ".tgz"
file.write(tarFile)
file.write("\n")
file.write("Version used in this deployment " + OS)
file.write("\n")
file.write("## FOLDER NAME : GIT TAG COMMIT MESSAGE ##")
##I try to open the file and read in information
try:
with open(change_config, "r") as configChoice:
DetectorArrayFound = False
ModuleArrayFound = False
DictionaryFound = False
detectors = []
module = []
install_path =""
original_path = ""
##for loop for each line in the configure file
for line in configChoice:
line= line.strip()
##I determine which arch they are using
if line.startswith('##EPIC_ARCH'):
t = line.split("=")
arg3 = t[1]
if line.startswith('##Required File Start'):
DictionaryFound = True
elif line.startswith('##Required File End'):
DictionaryFound = False
elif line.startswith('##Detector array start'):
DetectorArrayFound = True
print(install_path)
##Force them to add ADSupport and ADCore
os.makedirs("temp/support/areaDetector/ADSupport")
print("Adding ADSupport")
distutils.dir_util.copy_tree(install_path+AREA_DETECTOR+"ADSupport" ,"temp/support/areaDetector/ADSupport")
os.makedirs("temp/support/areaDetector/ADCore")
print("Adding ADCore")
distutils.dir_util.copy_tree(install_path+AREA_DETECTOR+"ADCore" ,"temp/support/areaDetector/ADCore")
print("Finished here")
elif line.startswith('##Detector array end'):
DetectorArrayFound = False
elif line.startswith('##Modules start'):
ModuleArrayFound = True
elif line.startswith('##Modules end'):
ModuleArrayFound = False
if DictionaryFound and not line.startswith('#') and len(line) > 2:
if line.startswith("INSTALL_PATH"):
##I figure out the install path they have
line = line.strip()
r = line.split("=")
install_path = str(r[1])
original_path = install_path
elif line.startswith("?"):
##I figure out what they want downloaed
install_path = original_path
line = line.strip()
line = line.replace("?","")
line = line.replace("[INSTALL_PATH]","")
k = line.split("=")
install_path = install_path + str(k[1])
print(install_path)
os.makedirs("temp/"+str(k[1]))
else:
if line.startswith("BIN") or line.startswith("LIB"):
line = line.strip()
l = line.split("=")
##I copy the files here and make dirs
partOfInstall = str(l[1])
temp = "temp/" + str(k[1]) +str(l[1]) + "/"+ arg3
os.makedirs(temp)
print("Adding...... " + temp)
distutils.dir_util.copy_tree(install_path+partOfInstall+"/"+arg3,temp)
path = os.popen("pwd").read()
git = os.popen("git -C "+install_path+partOfInstall+" branch").read()
start = git.find("R")
end = git.find(")")
version = git[start:end]
commit_msg = os.popen("git -C "+install_path+partOfInstall+" log").read()
msg = commit_msg.split('\n',1)[0]
msg =msg.replace("commit ", "")
file.write("\n")
file.write(install_path + partOfInstall + "/" + arg3 + " : " + version + " " + msg)
else:
line = line.strip()
l = line.split("=")
##I copy the files here and make dirs
partOfInstall = str(l[1])
temp = "temp/" + str(k[1])+str(l[1])
os.makedirs(temp)
print("Adding....... "+temp)
distutils.dir_util.copy_tree(install_path+partOfInstall, temp)
path = os.popen("pwd").read()
git = os.popen("git -C "+install_path+partOfInstall+" branch").read()
start = git.find("R")
end = git.find(")")
version = git[start:end]
commit_msg = os.popen("git -C "+install_path+partOfInstall+" log").read()
msg = commit_msg.split('\n',1)[0]
msg =msg.replace("commit ", "")
file.write("\n")
file.write(install_path + partOfInstall + " : " + version + " "+ msg)
if DetectorArrayFound and not line.startswith('#') and len(line) > 2:
if line.startswith("INSTALL_PATH"):
line = line.strip()
r = line.split("=")
install_path = str(r[1])
elif line.startswith("?"):
install_path = original_path
line = line.strip()
line = line.replace("?","")
line = line.replace("[INSTALL_PATH]","")
k = line.split("=")
install_path = install_path + str(k[1])
print(install_path)
try:
os.makedirs("temp/"+str(k[1]))
except:
print("")
else:
line = line.strip()
detectors.append(line)
##I copy the files here and make dirs
partOfInstall = line
temp = "temp/support/areaDetector/" +line
print("Adding...... "+temp)
os.makedirs(temp)
distutils.dir_util.copy_tree(install_path+AREA_DETECTOR+partOfInstall, temp)
path = os.popen("pwd").read()
git = os.popen("git -C "+install_path+AREA_DETECTOR+partOfInstall+" branch").read()
start = git.find("R")
end = git.find(")")
version = git[start:end]
git = os.popen("git -C "+install_path+AREA_DETECTOR+partOfInstall+" log").read()
msg = commit_msg.split('\n',1)[0]
msg =msg.replace("commit ", "")
file.write("\n")
file.write(install_path + AREA_DETECTOR +partOfInstall + " : " + version + " "+ msg)
if ModuleArrayFound == True and not line.startswith('#') and len(line) > 2:
line = line.strip()
module.append(line)
if line.startswith("INSTALL_PATH"):
line = line.strip()
r = line.split("=")
install_path = str(r[1])
elif line.startswith("?"):
install_path = original_path
line = line.strip()
line = line.replace("?","")
line = line.replace("[INSTALL_PATH]","")
k = line.split("=")
install_path = install_path + str(k[1])
print(install_path)
try:
os.makedirs("temp/"+str(k[1]))
except:
print("")
else:
line = line.strip()
detectors.append(line)
##I copy the files here and make dirs
partOfInstall = line
print(str(k[1]))
temp = "temp/" + str(k[1]) +line
os.makedirs(temp)
print("Adding........ "+temp)
distutils.dir_util.copy_tree(install_path+partOfInstall, temp)
path = os.popen("pwd").read()
git = os.popen("git -C "+install_path+partOfInstall+" branch").read()
start = git.find("R")
end = git.find(")")
version = git[start:end]
git = os.popen("git -C "+install_path+partOfInstall+" log").read()
msg = commit_msg.split('\n',1)[0]
msg =msg.replace("commit ", "")
file.write("\n")
file.write(install_path +partOfInstall + " : " + version + " "+ msg)
file.close()
print("")
print("TARRING IN PROGRESS")
subprocess.call(["tar", "-czf",DESTINATION+"/"+tarFile,"temp"])
print("TARRING COMPLETED!")
print("Moved Tar into DEPLOYMENT")
except:
print("Make sure your packages are correct!")
print("Crashed at: " +install_path + partOfInstall)
print("Make sure that what's above is correct")
##Error handling