-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·194 lines (160 loc) · 5.64 KB
/
setup.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
#!/usr/bin/env python2
import os,time,sys,re
def checkhost(rh):
'''
Fuction the checks the host name is different from accessdev.nci.org.au
which should be given with the command parameter
Vriables:
rh (str-object): default value if no parameter is given
'''
try:
args=sys.argv[1:]
if args[0].startwith('-h'):
try:
rh = args[1]
except IndexError:
sys.exit('Please indicate the host where umui is running')
else:
args=args[0].split('=')
if len(args != 2):
sys.exit('Please indicate the host where umui is running')
else:
rh=args[-1]
except IndexError:
pass
return rh
def read(string):
'''
Function that waits until the user hits yes
'''
ans = 'n'
while True:
print string," \r"
#sys.stdout.write(string)
ans=raw_input()
#sys.stdout.write('\r')
#sys.stdout.flush()
try:
ans=ans.lower()[0]
except IndexError:
ans='y'
if ans == 'y':
break
time.sleep(1)
def get_path():
'''
Returns the directory of the this script
'''
return os.path.dirname(os.path.abspath(sys.argv[0])) #The the path of this script
def copy(sources,remotehost,remotepath):
'''
Function to copy (via scp) important files from the remote host
'''
for s,t in sources.iteritems():
cmd='scp -q %s:%s/%s %s' %(remotehost,remotepath,s,t)
os.system(cmd) #Copy the stuff
def read_info(f1,remotehost,old,thepath):
'''
This function opens the downloaded files and looks for important
information in within them
Variables:
f1 (str-object): filename of the file containing the info in the
EXTR_SCR script that has been created by the umui
remotehost (str-obj): The name of the host where the um source is stored
thepath (str-object): The name of the path of this script
'''
old=old.split('\n') #Convert strng the list for later use
#Read the original EXTR_SCR script (copied as .tmp)
with open(f1) as f:
jobsheet = f.readlines()
export=[]
svn_serv=[''],['']
#Get all important variables that are created here (like UM_SVN_URL)
for ii,j in enumerate(jobsheet):
if 'UM_SVN_BIND=' in j: #The svn url
svn_serv=[j.strip()]
elif 'UM_ROUTDIR' in j: #The dir's of the source
export.append('export %s'%j.strip())
elif 'UM_VN' in j :
vn=j.strip().split('=')[-1].replace('vn','')
export.append('export UM_VN=vn%s'%vn)
export.append('export VN=%s'%vn)
elif 'DATAW' in j:
dataw=j.strip().split('=')[-1]
if dataw[-1] == '/' :
dataw=dataw[:-1]
datadir=os.path.dirname(dataw)
export.append('export DATAW=%s'%dataw)
export.append('export DATADIR=%s'%datadir)
elif 'PROCESSED_DIR' in j:
export.append('export PROCESSED_DIR=%s'%thepath)
elif j.startswith('export'): #Any other important variable
export.append(j.strip())
if 'Local Script Variables' in j or 'Loop through' in j : #From here on we are done, exit
break
#Create also a variable (extr_host) containig the info about the remotehost
extr_host=['export extr_host=%s'%remotehost]
#Merge all the relevant info
if len(svn_serv):
export = svn_serv+export+extr_host
else:
export = export+extr_host
if len(old) == 1:
export =[('#Environment variables for FCM bindings and repositories\n'\
'#and also data paths for the run environment\n')]+export
#Delete f1 because it is not needed
os.remove(f1)
src = []
for l in export:
if l not in old:
src.append(l)
return '\n'.join(old+src)
def get_remote_path(question):
'''
This function asks the usere where the infromation about the um job
is stored
Variables:
question (str-object): The prompt that the user is asked to type the
directory name
Returns:
str-object
'''
remotepath = raw_input(question).strip()
if len(remotepath) < 10: #Thats not a full path, exit
sys.exit('Error path to short please give the full path name')
return remotepath.rstrip('/')
if __name__ == '__main__':
#First get the server name hosting the umui environment
remotehost = checkhost('accessdev.nci.org.au')
#Get the name of this directory
thepath = get_path()
#Wait until the user confirms that umui has been processed
read('It is time to process your umui job! Hit the "Process" button and wait until the job has finished. Continue? [Y|n] ')
#Ask the user for the path of the umui job script output
remotepath = get_remote_path('The output of the umui process should give a output path (output in directory). Copy and paste that path\n')
#What are the important files in the remotepath on the remote_server?
sources = {'FCM_*_CFG':thepath,
'EXTR_SCR':'%s/.tmp'%thepath,
'MAIN_SCR':'%s/.tmp2'%thepath,
'*CNTL*':thepath,
'FCM_*':thepath,
'*INIT*':thepath,
'COMP_SWITCHES':thepath,
'JOBSHEET':thepath,
'PRESM_A':thepath,
'RECONA':thepath,
'SCRIPT':thepath,
'SHARED':thepath,
'SIZES':thepath,
'STASHC':thepath,
'USR_*':thepath}
#Copy some of the files that contain vital info from the remote_host
copy(sources,remotehost,remotepath)
#Get all the important information from the just copied files
info = read_info(os.path.join(thepath,'.tmp'),remotehost,'',thepath)
info = read_info(os.path.join(thepath,'.tmp2'),remotehost,info,thepath)
#And save the info to the DIR_SCR file
with open(os.path.join(thepath,'DIR_SCR'),'w') as f:
f.write(info+'\n')
#We are done let the user know
print 'Installation done: You can now run main.sh --extr extract the code on create a git repo'