-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp.py
More file actions
executable file
·307 lines (256 loc) · 11.3 KB
/
comp.py
File metadata and controls
executable file
·307 lines (256 loc) · 11.3 KB
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
#!/usr/bin/env python
# -*- coding: utf-8; -*-
#
# Script "comp.py":
# - compilation de Metafor
# - lancement automatique de la batterie
from parametricJob import *
# -- repository classes --------------------------------------------------------
class Repo(object):
def __init__(self, name, url):
self.name = name
self.url = url
class GitRepo(Repo):
def __init__(self, name, url):
super(GitRepo, self).__init__(name, url)
def co_cmd(self):
cmd = "git clone --quiet %s %s" % (self.url, self.name)
return cmd
class SVNRepo(Repo):
def __init__(self, name, url):
super(SVNRepo, self).__init__(name, url)
def co_cmd(self):
cmd = "svn co --quiet %s %s" % (self.url, self.name)
return cmd
# -- CompJob class -------------------------------------------------------------
class CompJob(ParametricJob):
""" Manage a compilation + battery.py
"""
def __init__(self, _jobId=''):
# init base class
self.jobId = _jobId
cfgfile = "comp%s.cfg" % self.jobId
ParametricJob.__init__(self, cfgfile)
# list of required repositories
self.repos = []
self.repos.append(SVNRepo('oo_meta', 'svn+ssh://blueberry.ltas.ulg.ac.be/home/metafor/SVN/oo_meta/trunk'))
self.repos.append(SVNRepo('oo_nda', 'svn+ssh://blueberry.ltas.ulg.ac.be/home/metafor/SVN/oo_nda/trunk'))
self.repos.append(GitRepo('linuxbin', 'https://github.com/ulgltas/linuxbin.git'))
self.repos.append(GitRepo('parasolid', 'blueberry.ltas.ulg.ac.be:/home/metafor/GIT/parasolid.git'))
self.loadPars() # RB: semble inutile: deja fait dans classe de base PRMSet??
def setDefaultPars(self):
if len(self.pars)!=0:
return
TextPRM(self.pars, 'MAIL_ADDR', 'e-mail address (reports)', os.getenv('USER'))
TextPRM(self.pars, 'SMTP_SERV', 'SMTP email server', 'smtp.ulg.ac.be')
TextPRM(self.pars, 'ARC_NAME', 'archive name', '~/dev.zip')
TextPRM(self.pars, 'CMAKELIST', 'build options', "%s.cmake" % socket.gethostbyaddr(socket.gethostname())[0].split('.')[0])
YesNoPRM(self.pars, 'DEBUG_MODE', 'debug mode', False)
TextPRM(self.pars, 'NICE_VALUE', 'nice value', "0")
TextPRM(self.pars, 'NB_TASKS', 'nb of task launched in parallel', "1")
TextPRM(self.pars, 'NB_THREADS', 'nb of threads by task', "1")
MultiPRM(self.pars, 'RUNMETHOD', 'Run Method', ["interactive", "at", "batch"], "batch")
TextPRM(self.pars, 'AT_TIME' , 'Delay for at launch (no syntax check, use with care)', "now")
MultiPRM(self.pars, 'UNZIP', 'source', ["zip", "checkout", "present"], "zip")
YesNoPRM(self.pars, 'COMPILE', 'compile', True)
MultiPRM(self.pars, 'BATTERY', 'battery', [True, False, "continue"], True)
PRMAction(self.actions, 'a', self.pars['MAIL_ADDR'])
PRMAction(self.actions, 'b', self.pars['ARC_NAME'])
PRMAction(self.actions, 'c', self.pars['CMAKELIST'])
PRMAction(self.actions, 'd', self.pars['DEBUG_MODE'])
PRMAction(self.actions, 'h', self.pars['NICE_VALUE'])
PRMAction(self.actions, 'j', self.pars['NB_TASKS'])
PRMAction(self.actions, 'k', self.pars['NB_THREADS'])
PRMAction(self.actions, 'm', self.pars['RUNMETHOD'])
# AT paramters
PRMAction(self.actions, 'n', self.pars['AT_TIME'])
# Actions
NoAction(self.actions)
PRMAction(self.actions, '1', self.pars['UNZIP'])
PRMAction(self.actions, '2', self.pars['COMPILE'])
PRMAction(self.actions, '3', self.pars['BATTERY'])
NoAction (self.actions)
GoAction (self.actions, 'G')
SaveAction(self.actions, 'S')
QuitAction(self.actions, 'Q')
def configActions(self):
self.pars['ARC_NAME'].enable(self.pars['UNZIP'].val=="zip")
self.pars['NB_TASKS'].enable(self.pars['COMPILE'].val==True or self.pars['BATTERY'].val!=False)
self.pars['NB_THREADS'].enable(self.pars['COMPILE'].val==True or self.pars['BATTERY'].val!=False)
self.pars['CMAKELIST'].enable(self.pars['COMPILE'].val==True)
self.pars['DEBUG_MODE'].enable(self.pars['COMPILE'].val==True)
self.pars['NICE_VALUE'].enable(self.pars['BATTERY'].val!=False and self.pars['RUNMETHOD'].val!='sge')
# Batch
self.pars['AT_TIME'].enable(self.pars['RUNMETHOD'].val=='at')
def touchFiles(self):
for repo in self.repos:
print "touching %s" % repo.name
for path, dirs, files in os.walk(repo.name):
for file in files:
os.utime(os.path.join(path,file), None) # touch file
def checkOut(self):
for repo in self.repos:
if not os.path.isdir(repo.name):
print 'checking out "%s" from %s...' % (repo.name, repo.url)
cmd = repo.co_cmd()
os.system(cmd)
def doClean(self):
dirs = [ repo.name for repo in self.repos ]
dirs.append('oo_metaB')
for dir in dirs:
if os.path.isdir(dir):
print "removing old %s directory" % dir
shutil.rmtree(dir)
def doUnzip(self):
print "unzipping files..."
file = self.pars['ARC_NAME'].val
if not os.path.isfile(os.path.expanduser(file)):
self.error("archive %s is not here!" % file)
ext = os.path.splitext(file)[1]
if ext==".zip":
# unzip the source and try to convert text files
cmd = 'unzip -a %s -x "*/.svn/*" >/dev/null' % file
sysOutput = os.system(cmd)
if (sysOutput != 0):
self.error("unable to unzip archive %s !" % file)
# no conversion for ".svn" database
cmd = 'unzip %s "*/.svn/*" >/dev/null' % file
sysOutput = os.system(cmd)
if (sysOutput != 0):
self.error("unable to unzip archive %s !" % file)
# convert some text files (if zip "text compression" was disabled)
dos2unix([ repo.name for repo in self.repos ], '*.txt;*.CPE;*.CRE;*.stp;*.l;*.y;*.dat')
elif ext==".tgz" or ext==".tar.gz":
tar = tarfile.open(os.path.expanduser(file),'r:gz')
for tarinfo in tar:
tar.extract(tarinfo)
tar.close()
else:
self.error("archive %s of unknown extension!" % file)
def compileMETAFOR(self):
# release or debug names/flags
exe='bin/Metafor'
dflag=''
if self.pars['DEBUG_MODE'].val:
dflag='-DCMAKE_BUILD_TYPE=Debug'
# first check
if not os.path.isdir('oo_meta'):
self.error('oo_meta not here!')
# create bin dir
if os.path.isdir('oo_metaB'):
print 'removing old %s directory' % 'oo_metaB'
shutil.rmtree('oo_metaB')
os.mkdir('oo_metaB')
os.chdir('oo_metaB')
# configure
print "configuring oo_meta"
cmfile = '../oo_meta/CMake/%s' % self.pars['CMAKELIST'].val
#print cmfile
if not os.path.isfile(cmfile):
msg = '%s not found!' % cmfile
print msg
self.mailmsg(msg)
cmd = 'cmake -C %s %s ../oo_meta >autocf.log 2>&1' % (cmfile, dflag)
#print cmd
os.system(cmd)
# compile
ncpu = int(self.pars['NB_TASKS'].val) * int(self.pars['NB_THREADS'].val)
print 'compiling %s using %s cpu(s) (have a coffee)' % (exe, ncpu)
os.system('make -j %d %s >compile.log 2>&1' % (ncpu, dflag))
# check exe
if os.path.isfile(exe) and os.access(exe, os.X_OK):
msg='compilation of %s OK' % exe
print msg
self.mailmsg(msg, 'compile.log')
else:
msg='compilation of %s FAILED' % exe
self.error(msg, 'compile.log')
os.chdir('..')
def compile(self):
self.compileMETAFOR()
def cleanBattery(self):
os.chdir('oo_metaB/bin')
print "cleaning old results"
os.system("python battery.py clean >/dev/null 2>&1")
os.chdir('../..')
def startBat(self):
now = datetime.datetime.now()
print "starting battery at %s (come back tomorrow)" % now.ctime()
os.chdir('oo_metaB/bin')
cmd="nice -%s python battery.py -j %s -k %s >battery.log 2>&1" % (self.pars['NICE_VALUE'].val, self.pars['NB_TASKS'].val, self.pars['NB_THREADS'].val)
p = subprocess.Popen(cmd, shell=True)
p.wait()
# finish script
now = datetime.datetime.now()
print "battery completed at %s" % now.ctime()
self.mailmsg("battery complete", file='battery.log')
os.chdir('../..')
def checkResults(self): # pars indep
os.chdir('oo_metaB/bin')
print "diff'ing results"
cmd="python battery.py diff"
print "checkResults: cmd = %s" % cmd
os.system(cmd)
file='verif/%s-diffs.html' % machineid()
print "verif file name = %s" % file
#self.mailhtml(file, "html report")
self.mailHtmlAsAttachement(file, "html report")
print "file %s sent as attachement ..." % file
os.chdir('../..')
def getJobName(self):
return os.path.basename(os.getcwd())+".battery"
def run(self):
# kill script that kills running tree
self.killScript(self.jobId, os.getpgrp())
if self.pars['UNZIP'].val=="checkout":
self.doClean()
self.checkOut()
elif self.pars['UNZIP'].val=="zip":
self.doClean()
self.doUnzip()
self.checkOut() # only missing folders
self.touchFiles()
if self.pars['COMPILE'].val:
self.compile()
if self.pars['BATTERY'].val==True:
self.cleanBattery()
if not self.pars['BATTERY'].val==False:
self.startBat()
self.checkResults()
if os.path.isfile("kill%s.py" % self.jobId):
os.remove("kill%s.py" % self.jobId)
if (self.pars['RUNMETHOD'].val == 'at' or
self.pars['RUNMETHOD'].val == 'batch'):
if os.path.isfile("atrm%s.py" % self.jobId):
os.remove("atrm%s.py" % self.jobId)
if os.path.isfile(self.cfgfile):
os.remove(self.cfgfile)
print "done."
# -- main ----------------------------------------------------------------------
if __name__ == "__main__":
try:
import signal
signal.signal(signal.SIGBREAK, sigbreak);
except:
pass
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-d", "--directory", dest="rundir",
metavar="DIR", help="specify run directory (batch mode)")
parser.add_option("-x", "--nogui", action="store_false",
dest="usegui",default=True, help="disable menu")
parser.add_option("-i", "--jobId", dest="jobId", type="str", default='',
help="job id")
(options, args) = parser.parse_args()
#print "options = ", options
#print "args = ", args
if len(args)!=0:
parser.error("too many arguments")
if options.rundir:
os.chdir(options.rundir)
#print "options.jobId = %s"% options.jobId
job = CompJob(options.jobId)
if options.usegui:
job.menu()
else:
job.run()