-
Notifications
You must be signed in to change notification settings - Fork 7
/
reload.py
52 lines (45 loc) · 1.03 KB
/
reload.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
import os
import sys
if __name__=='__main__':
if len(sys.argv)!=3:
print 'Usage: python reload.py <General Folder> <Model to Reload>'
exit(0)
if os.name!='posix':
print 'Unix/Linux Only'
exit(0)
folder=sys.argv[1]
model=sys.argv[2]
if folder[-1]=='/':
folder=folder[:-1]
if 'tmp' in os.listdir('.'):
os.system('rm -rf tmp')
os.system('mkdir tmp')
os.system('cp -r %s/* tmp/'%folder)
with open(model,'r') as fopen:
command=fopen.readline()
currentFile=''
data=''
for line in fopen:
if line[:4]=='####':
if currentFile!='':
with open('tmp/%s'%currentFile,'w') as fwrite:
fwrite.write(data)
data=''
pt1=0;pt2=len(line)
state=0
for i in xrange(len(line)):
if state==0 and line[i]!='#':
state=1
pt1=i
elif state==1 and line[i]=='#':
pt2=i
break
currentFile=line[pt1:pt2]
else:
data+=line
with open('tmp/%s'%currentFile,'w') as fwrite:
fwrite.write(data)
os.chdir('tmp')
print command
os.system(command)
print 'reload completed!'