Changeset 517 for tbroadcast/HEAD/python/tbroadcast.py
- Timestamp:
- Sep 7, 2009, 2:43:28 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tbroadcast/HEAD/python/tbroadcast.py
r508 r517 2 2 # -- Author: V.Garonne 3 3 # -- Mail: garonne@lal.in2p3.fr 4 # -- Date: 08/25/2006 4 # -- Date: 08/25/2006 5 5 # -- Name: tbroadcast 6 6 # -- Description: main class 7 7 #----------------------------------# 8 9 # 21-Jul-2009 compile most used packages first; protect critical sections 8 10 9 11 import os … … 11 13 import time 12 14 import string 13 import random14 15 import os.path 15 import commands16 # import commands 16 17 import traceback 17 18 import exceptions … … 20 21 from threadpool import WorkRequest 21 22 from threadpool import ThreadPool 22 from threadpool import NoResultsPending23 from threadpool import NoWorkersAvailable24 from threadpool import makeRequests25 23 26 24 from subprocess import Popen … … 28 26 class Scheduler: 29 27 30 def __init__(self, num_workers=20, file=None, ignore_cycles=False, local=False, output=None, error=None, silent = False, perf=False, keep_going=True): 31 self.pool = ThreadPool(num_workers=num_workers) 32 self.current_package = self.get_current_package() 28 def __init__(self, num_workers=20, file=None, ignore_cycles=False, local=False, sort=False, 29 output=None, error=None, silent = False, perf=False, keep_going=True): 30 self.pool = ThreadPool(num_workers=num_workers, poll_timeout=3) 31 self.num_workers = num_workers 33 32 self.current_project = {'name': None, 'path': None, 'version': None} 34 33 self.packages = {} … … 36 35 self.semaphore = BoundedSemaphore(1) 37 36 self.local = local 37 self.sort = sort 38 38 self.ignore_cycles = ignore_cycles 39 39 self.output = output … … 42 42 self.perf = perf 43 43 self.keep_going = keep_going 44 if self.sort: 45 print "Compile packages sorted according to use count" 44 46 if self.perf is not False: 45 47 f = open (self.perf, 'w+') … … 47 49 if output is not None: 48 50 if not os.path.exists (output): 49 print "path",output," no exits"51 print "path",output,"does not exists" 50 52 sys.exit(-1) 51 53 if not os.path.isdir(output): 52 print "path",output,"no a valid directory" 53 sys.exit(-1) 54 54 print "path",output,"is not a valid directory" 55 sys.exit(-1) 56 57 # init cmt stuff 55 58 self.get_current_project() 59 self.current_package = self.get_current_package() 56 60 self.instanciate_packages (file) 57 61 if self.local: self.get_local_graph() 58 62 self.check_cycles() 59 60 # status, output = commands.getstatusoutput("cmt broadcast -local 'echo <package>'") 61 # lignes = string.split(output, '\n') 62 # i = 1 63 # for package in lignes: 64 # if package!='' and package[0] != '#': 65 # print i , package 66 # i =i +1 67 # if not self.packages.has_key(package): 68 # print package 69 # print len(self.packages) 70 # sys.exit(-1) 63 self.get_use_count() 71 64 72 65 def get_current_project(self): 73 66 cmd = 'cmt show projects | grep current' 74 status, output = commands.getstatusoutput (cmd) 67 status, output = getstatusoutput (cmd) 68 #status, output = commands.getstatusoutput (cmd) 75 69 if status != 0: 76 70 print output 77 sys.exit(-1) 71 sys.exit(-1) 78 72 lines = string.split(output, '\n') 79 for line in lines: 80 if line!='' and line [0] != '#': 73 for line in lines: 74 if line!='' and line [0] != '#': 81 75 item = string.split (line, ' ') 82 76 self.current_project ['name'] = item[0] … … 87 81 self.current_project ['path'] = os.path.normpath(self.current_project ['path'][:-len(self.current_project ['version'] )]) 88 82 return 89 #print self.current_project 90 83 91 84 def get_counter(self): 92 self.semaphore.acquire () 85 self.semaphore.acquire () 93 86 self.counter = self.counter + 1 94 value = self.counter 87 value = self.counter 95 88 self.semaphore.release() 96 89 return value 97 90 98 91 def check_cycles (self): 99 92 cmd = 'cmt -private show cycles' 100 93 cycle_found = False 101 status, output = commands.getstatusoutput (cmd) 94 status, output = getstatusoutput (cmd) 95 #status, output = commands.getstatusoutput (cmd) 102 96 if status != 0: 103 97 print output 104 sys.exit(-1) 98 sys.exit(-1) 105 99 lines = string.split(output, '\n') 106 cycles = list 107 for line in lines: 108 if line!='' and line [0] != '#': 109 cycles.append (string.split(line)) 110 cercles =list() 100 cycles = list() 101 for line in lines: 102 if line!='' and line [0] != '#': 103 cycles.append (string.split(line)) 104 cercles =list() 111 105 for cycle in cycles: 112 106 cycleInProject = True 113 for package in cycle: 107 for package in cycle: 114 108 if not self.packages.has_key(package): 115 cycleInProject = False 116 if cycleInProject: 109 cycleInProject = False 110 if cycleInProject: 117 111 cercles.append(cycle) 118 112 if len(cercles): … … 120 114 print "# Error: cycles found, not possible to execute broadcast with threads. Please correct the following cycles:" 121 115 for cycle in cercles: 122 loop = "" 116 loop = "" 123 117 for package in cycle: 124 118 loop = loop + package + ' -> ' 125 119 print loop + '...' 126 sys.exit(-1) 120 sys.exit(-1) 127 121 else: 128 122 print "# Warning: There are cycles and you have selected the automatic suppress cycles mode" 129 123 for cycle in cercles: 130 loop = "" 124 loop = "" 131 125 for package in cycle: 132 loop = loop + package + ' -> ' 126 loop = loop + package + ' -> ' 133 127 if cycle[0] in self.packages[cycle[len(cycle)-1]]['uses']: 134 128 print '## In cycle: '+loop + '..., we suppress the dependency '+ cycle[len(cycle)-1]+'->'+cycle[0] … … 151 145 lines = list() 152 146 for ligne in lignes: 153 if ligne[:4] == "use ": 147 if ligne[:4] == "use ": 154 148 lines.append(ligne) 155 149 return lines … … 169 163 if os.path.exists(path[1:-1] + '/' + offset + '/' +name + '/' + version + '/cmt'): 170 164 full_path = path[1:-1] + '/' + offset + '/' +name + '/' + version + '/cmt' 171 elif os.path.exists(path[1:-1] + '/' + offset + '/' +name + '/cmt'): 165 elif os.path.exists(path[1:-1] + '/' + offset + '/' +name + '/cmt'): 172 166 full_path = path[1:-1] + '/' + offset + '/' +name + '/cmt' 173 167 else: 174 168 print '# error path not found for', name 175 sys.exit(-1) 169 sys.exit(-1) 176 170 elif len(result)==5: 177 name, version, offset, path, importation = string.split (line[4:len(line)], " ") 171 name, version, offset, path, importation = string.split (line[4:len(line)], " ") 178 172 if os.path.exists(path[1:-1] + '/' + offset + '/' +name + '/' + version + '/cmt'): 179 173 full_path = path[1:-1] + '/' + offset + '/' +name + '/' + version + '/cmt' 180 elif os.path.exists(path[1:-1] + '/' + offset + '/' +name + '/cmt'): 174 elif os.path.exists(path[1:-1] + '/' + offset + '/' +name + '/cmt'): 181 175 full_path = path[1:-1] + '/' + offset + '/' +name + '/cmt' 182 176 else: 183 177 print '# error path not found for', name 184 sys.exit(-1) 178 sys.exit(-1) 185 179 elif len(result)==3: 186 180 name, version, path = string.split (line[4:len(line)], " ") 187 181 if os.path.exists(path[1:-1] + '/' +name + '/' + version + '/cmt'): 188 182 full_path = path[1:-1] + '/' +name + '/' + version + '/cmt' 189 elif os.path.exists(path[1:-1] + '/' +name + + '/cmt'): 183 elif os.path.exists(path[1:-1] + '/' +name + + '/cmt'): 190 184 full_path = path[1:-1] + '/' +name + + '/cmt' 191 185 else: … … 195 189 print "error:",line 196 190 print str(result) 197 sys.exit(-1) 191 sys.exit(-1) 198 192 self.packages[result[0]]['path'] = os.path.normpath(full_path) 199 193 commonprefix = os.path.commonprefix([self.packages[result[0]]['path'], self.current_project ['path']]) 200 if os.path.normpath(commonprefix) == self.current_project ['path']: 194 if os.path.normpath(commonprefix) == self.current_project ['path']: 201 195 #print result[0], ' belong to project', self.current_project ['name'] 202 196 self.packages[result[0]]['current_project'] = True 203 197 204 def get_uses(self, content): 198 def get_uses(self, content): 205 199 # initiates variables 206 200 lignes = self.format_uses(content) 207 201 if not len(lignes): return 208 self.packages [self.current_package] = {'version': '*', ' client': list(),209 'uses': list(), 'status': 'waiting', 202 self.packages [self.current_package] = {'version': '*', 'use_count': 0, 203 'uses': list(), 'status': 'waiting', 210 204 'current_project': True, 'path': os.getcwd()} 211 205 previous_client = self.current_package 212 206 previous_level = 0 213 207 level_stack = [{'name':previous_client,'level':previous_level},] 214 ligne = lignes.pop() 215 while len(lignes)!=0: 208 ligne = lignes.pop() 209 while len(lignes)!=0: 216 210 current_level = string.find(ligne, 'use') 217 while current_level > previous_level: 211 while current_level > previous_level: 218 212 name = string.split (ligne)[2] 219 version = string.split (ligne)[3] 213 version = string.split (ligne)[3] 220 214 if not self.packages.has_key (name): 221 self.packages [name] = {'version': version, 'use s': list(),222 ' client': list(), 'status': 'waiting',215 self.packages [name] = {'version': version, 'use_count': 0, 216 'uses': list(), 'status': 'waiting', 223 217 'current_project': False, 'path': None} 224 218 if name not in self.packages[previous_client]['uses']:# and name != previous_client: 225 self.packages[previous_client]['uses'].append (name) 219 self.packages[previous_client]['uses'].append (name) 226 220 level_stack.append({'name':previous_client,'level':previous_level}) 227 previous_client = name 228 previous_level = current_level 221 previous_client = name 222 previous_level = current_level 229 223 if len(lignes): 230 224 ligne = lignes.pop() 231 225 #print ligne 232 226 current_level = string.find(ligne, 'use') 233 234 #self.packages [previous_client]['status'] ='queued' 227 235 228 # restore the level 236 229 if len(lignes): 237 if len(level_stack): 238 item = level_stack.pop() 230 if len(level_stack): 231 item = level_stack.pop() 239 232 while item['level'] >= current_level and len(level_stack): 240 233 item = level_stack.pop() … … 248 241 if file is None: 249 242 cmd = 'cmt show uses' 250 else: 251 cmd = 'cat ' + file 252 status, output = commands.getstatusoutput (cmd) 243 else: 244 cmd = 'cat ' + file 245 status, output = getstatusoutput (cmd) 246 #status, output = commands.getstatusoutput (cmd) 253 247 if status != 0: 254 248 print output 255 249 sys.exit(-1) 256 self.get_uses(output) 250 self.get_uses(output) 257 251 self.get_paths(output) 258 #self.check_execution (package=self.current_package)259 252 #self.simulate_execution() 253 254 def get_use_count(self): 255 for key in self.packages: 256 count = 0 257 for parent in self.packages: 258 if key in self.packages[parent]['uses']: count += 1 259 self.packages[key]['use_count'] = count 260 # print "Package",key,"use_count",count 260 261 261 262 def get_local_graph(self): … … 266 267 if key in self.packages[selected]['uses']: 267 268 self.packages[selected]['uses'].remove(key) 268 To_remove.append (key) 269 To_remove.append (key) 269 270 for item in To_remove: 270 271 del self.packages[item] 271 272 272 273 def simulate_execution(self): 273 ok = True 274 indice = 1 275 while ok: 276 runnable = list() 277 for key in self.packages: 278 if self.packages[key]['status']!='done': 279 if len(self.packages[key]['uses']) == 0: 280 runnable.append(key) 281 if len(runnable): 282 print '\n#--------------------------------------------------------------' 283 print "# Execute parallel actions within packages " + str(runnable) 284 for selected in runnable: 285 print '#--------------------------------------------------------------' 286 print '# ('+str(indice)+'/'+str(len(self.packages))+') Now trying [] in '+ self.packages[selected]['path'] 287 print '#--------------------------------------------------------------' 288 self.packages[selected]['status']='done' 289 indice = indice + 1 290 for key in self.packages: 291 if selected in self.packages[key]['uses']: 292 self.packages[key]['uses'].remove(selected) 293 #print 'remove', selected, 'from',key 294 if len(runnable)==0: 295 ok = False 296 297 def check_execution(self, package, path=list(), cycles=list()): 298 #print package,'-->',self.packages[package]['uses'] 299 #print path 300 if package in path: 301 if path[path.index(package):] not in cycles: 302 print 'Cycles:',path[path.index(package):], package 303 cycles = cycles + path[path.index(package):] 304 sys.exit(-1) 305 path.append(package) 306 for item in self.packages[package]['uses']: 307 self.check_execution(package=item, path=path, cycles=cycles) 308 path.pop() 309 310 def get_current_package(self): 274 while True: 275 ndone = self.simulate_requests() 276 if ndone == 0: break 277 278 def simulate_requests(self): 279 runnable = self.get_next_work_units() 280 if len(runnable): 281 print '\n#--------------------------------------------------------------' 282 print "# Execute parallel actions within packages - total", len(runnable) 283 print '#--------------------------------------------------------------' 284 for selected in runnable: 285 use_count = self.packages[selected]['use_count'] 286 path = self.packages[selected]['path'] 287 print '#--------------------------------------------------------------' 288 print '# (%d/%d %d) Now trying [] in %s' % (self.get_counter(), len(self.packages), use_count, path) 289 print '#--------------------------------------------------------------' 290 self.suppress_work_unit(selected) 291 return len(runnable) 292 293 def get_current_package(self): 311 294 cmd = 'cmt show macro package' 312 status, output = commands.getstatusoutput (cmd) 295 status, output = getstatusoutput (cmd) 296 #status, output = commands.getstatusoutput (cmd) 313 297 if status != 0: 314 298 print output 315 sys.exit(-1) 299 sys.exit(-1) 316 300 lines = string.split(output, '\n') 317 301 for line in lines: … … 321 305 return line [start+1:start+end+1] 322 306 323 def get_work_area_path (self, name):324 return self.packages [name]['path']325 326 def get_package_path (self, name):327 #return os.getcwd ()328 cmd = 'cmt -use='+name+' run pwd'329 status, output = commands.getstatusoutput (cmd)330 if status != 0:331 print output332 sys.exit(-1)333 lines = string.split(output, '\n')334 for line in lines:335 if line [0] != '#' and line[:5] != "#CMT>":336 print line337 return line338 339 307 def print_dependencies(self): 340 print '# ------------------------ '341 print '# package --> dependencies '342 print '# ------------------------ '308 print '# -------------------------------------------' 309 print '# package --> dependencies, status, use_count' 310 print '# -------------------------------------------' 343 311 for key in self.packages.keys(): 344 print key, '-->', self.packages[key] ['uses'],',', self.packages[key] ['status'] 312 print key, '-->', self.packages[key] ['uses'],',', self.packages[key] ['status'],',', self.packages[key] ['use_count'] 345 313 346 314 def print_status(self, status): 347 print '# ------------------------' 348 print '# package --> dependencies' 349 print '# ------------------------' 315 print '# ------------------------' 316 print '# package --> dependencies' 317 print '# ------------------------' 350 318 i = 1 351 319 for key in self.packages.keys(): 352 320 if self.packages[key] ['status'] == status: 353 print i , key, '-->', self.packages[key] ['uses'],',', self.packages[key] ['status'] 321 print i , key, '-->', self.packages[key] ['uses'],',', self.packages[key] ['status'] 354 322 i = i + 1 355 323 356 324 def is_work_unit_waiting (self, name): 357 325 return self.packages[name] ['status'] == 'waiting' … … 360 328 self.packages[name] ['status'] = status 361 329 362 def get_dependencies (self, name):363 return self.packages[name] ['uses']364 365 330 def get_next_work_units (self): 366 result = list () 367 for key in self.packages.keys(): 368 if len(self.get_dependencies (key)) == 0 and self.is_work_unit_waiting(key) : 369 result.append(key) 331 # by default returned list is in arbitrary order - may be this is better 332 # if self.sort is set returned list is sorted - most used packages first 333 runnable = list() 334 for key in self.packages: 335 if len(self.packages[key]['uses']) == 0 and self.packages[key]['status'] == 'waiting': 336 use_count = self.packages[key]['use_count'] 337 runnable.append((use_count,key)) 338 if self.sort: 339 runnable.sort() 340 runnable.reverse() 341 result = [ pair[1] for pair in runnable ] 370 342 return result 371 343 372 def is_work_units (self):373 result = list ()374 for key in self.packages.keys():375 if self.is_work_unit_waiting(key) :376 return True377 return False378 379 344 def suppress_work_unit (self, name): 380 #print '# remove', name, 'from schedule' 345 #print '# remove', name, 'from schedule' 346 self.semaphore.acquire() 347 self.packages[name]['status']='done' 381 348 for key in self.packages.keys(): 382 349 if name in self.packages[key]['uses']: 383 350 self.packages[key]['uses'].remove(name) 351 self.semaphore.release() 384 352 385 353 def add_work_unit (self, name, cmd): 386 354 if self.is_work_unit_waiting (name): 387 355 # we create requests 388 arg = {'cmd': cmd , 'package':name} 389 req = WorkRequest(self.do_execute, [arg] , None, callback=self.result_callback) 356 arg = {'cmd': cmd , 'package': name} 357 req = WorkRequest(self.do_execute, [arg] , None, callback=self.result_callback) 358 # req = WorkRequest(self.do_execute, [arg] , None, 359 # callback=self.result_callback, exc_callback=self.handle_exception) 390 360 # then we put the work request in the queue... 391 361 self.set_work_unit_status (name, 'queued') 392 362 self.pool.putRequest(req) 393 # print "# Work request #%s added on %s." % (req.requestID, str(arg['package']))363 # print "# Work request #%s added on %s." % (req.requestID, str(arg['package'])) 394 364 395 365 def execute (self, command): 396 366 #self.print_dependencies () 367 self.semaphore.acquire() 397 368 packages = self.get_next_work_units() 398 if len(packages) !=0: 399 print '\n#--------------------------------------------------------------' 400 print '# Execute parallel actions within packages', packages 369 if len(packages): 370 print '\n#--------------------------------------------------------------' 371 print '# Execute parallel actions within packages (total',len(packages),')',packages 372 print '\n#--------------------------------------------------------------' 401 373 for package in packages: 402 374 self.add_work_unit (package, command) 375 sys.stdout.flush() 376 self.semaphore.release() 403 377 404 378 def execute_all(self,command): … … 406 380 self.execute (command) 407 381 self.wait() 382 if self.counter != len(self.packages): 383 print 'tbroadcast: warning: compiled',self.counter,'out of',len(self.packages),'packages' 384 self.pool.dismissWorkers(self.num_workers, do_join=True) 408 385 #self.print_dependencies () 409 #self.print_status (status='waiting') 410 #while self.is_work_units(): 411 #self.wait() 412 386 #self.print_status (status='waiting') 387 413 388 def wait (self): 414 self.pool.wait() 389 self.pool.wait() 415 390 416 391 # this will be called each time a result is available … … 418 393 #print "**Result: %s from request #%s" % (str(result), request.requestID) 419 394 #print "# Result: %s from request #%s" % (result['package'], request.requestID) 420 #if result['package'] == 'CodeCheck': 421 # sys.exit(-1) 422 self.execute (result['cmd']) 423 424 # the work the threads will have to do 395 self.execute (result['cmd']) 396 397 # the work the threads will have to do 425 398 def do_execute(self, arg): 426 path = self.get_work_area_path (arg['package']) 399 package = arg['package'] 400 path = self.packages[package]['path'] 427 401 if path == None or not os.path.exists(path): 428 raise RuntimeError('Path to package '+ arg['package'] +' not found') 429 self.set_work_unit_status (arg['package'], 'running') 430 #cmd = "cmt -use="+ arg['package'] + " run '"+ arg['cmd'] + "'" 431 #os.chdir(path) 432 #arg['cmd'] = "cd "+ path +";"+ arg['cmd'] 433 header = '#--------------------------------------------------------------\n' 434 header = header + '# ('+str(self.get_counter())+'/'+str(len(self.packages))+') Now trying ['+ arg['cmd']+'] in ' + path + '\n' 402 raise RuntimeError('Path to package '+ package +' not found') 403 self.set_work_unit_status(package, 'running') 404 header = '#--------------------------------------------------------------\n' 405 header = header + '# ('+str(self.get_counter())+'/'+str(len(self.packages))+') Now trying ['+arg['cmd']+'] in '+path+'\n' 435 406 header = header + '#--------------------------------------------------------------\n' 436 407 print header 408 sys.stdout.flush() 437 409 project_path = self.current_project['path']+'/'+self.current_project['version']+'/' 438 410 log_name = string.replace(path, project_path, '') … … 440 412 log_name = string.replace(log_name, '/', '_') 441 413 log_name = log_name+'.loglog' 442 arg['log'] = log_name443 cmd = "cd "+ path +";"+ arg['cmd'] 444 # status, output= commands.getstatusoutput(cmd)414 # arg['log'] = log_name 415 cmd = "cd "+ path +";"+ arg['cmd'] 416 # status, output = commands.getstatusoutput(cmd) 445 417 # init output file 446 418 447 self.packages[ arg['package']] ['startTime'] = time.time ()419 self.packages[package] ['startTime'] = time.time() 448 420 449 421 if self.output is not None: 450 f1 = open (self.output+'/'+ log_name, 'w+') 422 f1 = open (self.output+'/'+ log_name, 'w+') 451 423 f1.write (header) 424 f1.flush() 425 if self.error is not None: 426 f2 = open (self.error+'/error'+log_name, 'w+') 427 fp = Popen(cmd, shell=True, stdout=f1, stderr=f2) 428 fp.communicate() 429 status = fp.wait() 430 f2.close() 431 else: 432 fp = Popen(cmd, shell=True, stdout=f1, stderr=f1) 433 fp.communicate() 434 status = fp.wait() 452 435 f1.close() 453 f1 = open (self.output+'/'+ log_name, 'a')454 if self.error is not None:455 f2 = open (self.error+'/error'+log_name, 'w+')456 Popen(cmd, shell=True, stdout=f1, stderr=f2).communicate()457 f2.close()458 else:459 Popen(cmd, shell=True, stdout=f1, stderr=f1).communicate()460 f1.close()461 436 else: 462 Popen(cmd, shell=True).communicate() 463 437 fp = Popen(cmd, shell=True) 438 fp.communicate() 439 status = fp.wait() 440 sys.stdout.flush() 441 sys.stderr.flush() 442 443 # Error is not handled - exit() is forbidden here 464 444 if not self.keep_going and status > 0: 465 sys.exit(status) 466 467 self.packages[arg['package']] ['endTime'] = time.time () 445 print 'Error',status,'for package',package 446 # sys.exit(status) 447 448 self.packages[package] ['endTime'] = time.time() 468 449 if self.perf: 469 self.semaphore.acquire ()450 self.semaphore.acquire() 470 451 f = open (self.perf, 'a') 471 f.write ( arg['package']+" "+str(self.packages[arg['package']] ['startTime'])+" "+str(self.packages[arg['package']] ['endTime'] )+'\n')452 f.write (package+" "+str(self.packages[package]['startTime'])+" "+str(self.packages[package]['endTime'] )+'\n') 472 453 f.close() 473 454 self.semaphore.release() 474 self.suppress_work_unit (arg['package']) 475 self.set_work_unit_status (arg['package'], 'done') 476 # status, output= commands.getstatusoutput(cmd) 477 #if status != 0: 478 # raise RuntimeError(output) 455 self.suppress_work_unit(package) 479 456 return {'cmd': arg['cmd'], 'package':arg['package']} 480 457 481 458 482 459 # this will be called when an exception occurs within a thread 483 460 def handle_exception(self, request, exc_info): 484 485 print '#--------------------------------------------------------------' 461 #traceback.print_stack() 462 print '#--------------------------------------------------------------' 486 463 #print "# Exception occured in request #%s: %s" %(request.requestID, exc_info[1]) 487 464 if exc_info[0]== exceptions.SystemExit: 488 print "Stop execution (No_keep_going option enabled): exit code == %s " %(exc_info[1]) 489 print '#--------------------------------------------------------------' 465 print "Stop execution (No_keep_going option enabled): exit code == %s " %(exc_info[1]) 466 print '#--------------------------------------------------------------' 490 467 sys.exit(exc_info[1]) 491 print "# Exception occured: %s" %(exc_info[1]) 468 print "# Exception occured: %s" %(exc_info[1]) 492 469 print exc_info 493 print '#--------------------------------------------------------------' 470 print '#--------------------------------------------------------------' 494 471 #sys.exit(-1) 495 472 496 473 497 474 def generate_make (self, file, command): 498 475 makefile = open (file, 'w+') … … 502 479 self.recursive_make (self.current_package, command, makefile, len(self.packages)) 503 480 makefile.close () 504 481 505 482 def recursive_make (self, package, command, makefile, indice,actions=list()): 506 483 lines = self.generate_action_make (package, command, indice) 507 484 makefile.write (lines) 508 #print lines 485 #print lines 509 486 for pkg in self.packages[package] ['uses']: 510 487 if pkg not in actions: … … 512 489 indice = indice - 1 513 490 self.counter = self.counter - 1 514 self.recursive_make(pkg, command,makefile, indice, actions) 515 491 self.recursive_make(pkg, command,makefile, indice, actions) 492 516 493 def generate_action_make (self, package, command, indice): 517 lines = package + ' :: ' 494 lines = package + ' :: ' 518 495 # add dependencies 519 496 for pkg in self.packages[package] ['uses']: 520 lines = lines + ' ' + pkg 497 lines = lines + ' ' + pkg 521 498 522 499 # add the action itself 523 newcommand = string.replace (command, '<package>', package) 500 newcommand = string.replace (command, '<package>', package) 524 501 if command =='': 525 502 newcommand='$(MAKE)' … … 529 506 lines = lines + '\t@echo "#--------------------------------------------------------------"\n' 530 507 lines = lines + 'ifdef LOCATION\n' 531 lines = lines + '\t@echo "#--------------------------------------------------------------"> $(LOCATION)/'+ package +'.loglog\n' 508 lines = lines + '\t@echo "#--------------------------------------------------------------"> $(LOCATION)/'+ package +'.loglog\n' 532 509 lines = lines + '\t@echo "# ('+str(self.counter)+'/'+str(len(self.packages))+') Now trying ['+newcommand+'] in '+ self.packages[package]['path']+'">> $(LOCATION)/'+ package +'.loglog\n' 533 510 lines = lines + '\t@echo "#--------------------------------------------------------------">> $(LOCATION)/'+ package +'.loglog\n' 534 lines = lines + '\t+@cd ' + self.packages[package]['path'] 511 lines = lines + '\t+@cd ' + self.packages[package]['path'] 535 512 lines = lines + ' && ' + newcommand + ' >> $(LOCATION)/'+ package +'.loglog 2>&1\n' 536 513 lines = lines + 'else\n' 537 lines = lines + '\t+@cd ' + self.packages[package]['path'] 514 lines = lines + '\t+@cd ' + self.packages[package]['path'] 538 515 lines = lines + ' && ' + newcommand + '\n' 539 lines = lines + 'endif\n\n' 516 lines = lines + 'endif\n\n' 540 517 return lines 541 518 519 520 # own copy of getstatusoutput 521 def getstatusoutput(cmd): 522 """Return (status, stdout) of executing cmd in a shell. 523 524 A trailing line separator is removed from the output string. 525 The exit status of the command is encoded in the format specified for wait(), 526 when the exit status is zero (termination without errors), 0 is returned. 527 """ 528 import os 529 p = os.popen(cmd, 'r') 530 out = p.read() 531 sts = p.close() 532 if sts is None: sts = 0 533 if out.endswith(os.linesep): 534 out = out[:out.rindex(os.linesep)] 535 return sts, out 536 542 537 #--------- EoF --------#
Note: See TracChangeset
for help on using the changeset viewer.