Ignore:
Timestamp:
Sep 7, 2009, 2:43:28 PM (15 years ago)
Author:
rybkin
Message:

Version v2.0.6_rc4 from Igor Kachaev

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tbroadcast/HEAD/python/tbroadcast.py

    r508 r517  
    22# -- Author: V.Garonne
    33# -- Mail: garonne@lal.in2p3.fr
    4 # -- Date: 08/25/2006 
     4# -- Date: 08/25/2006
    55# -- Name: tbroadcast
    66# -- Description: main class
    77#----------------------------------#
     8
     9# 21-Jul-2009 compile most used packages first; protect critical sections
    810
    911import os
     
    1113import time
    1214import string
    13 import random
    1415import os.path
    15 import commands
     16# import commands
    1617import traceback
    1718import exceptions
     
    2021from threadpool  import WorkRequest
    2122from threadpool  import ThreadPool
    22 from threadpool  import NoResultsPending
    23 from threadpool  import NoWorkersAvailable
    24 from threadpool  import  makeRequests
    2523
    2624from  subprocess import Popen
     
    2826class Scheduler:
    2927
    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
    3332        self.current_project = {'name': None, 'path': None, 'version': None}
    3433        self.packages        = {}
     
    3635        self.semaphore       = BoundedSemaphore(1)
    3736        self.local           = local
     37        self.sort            = sort
    3838        self.ignore_cycles   = ignore_cycles
    3939        self.output          = output
     
    4242        self.perf            = perf
    4343        self.keep_going      = keep_going
     44        if self.sort:
     45            print "Compile packages sorted according to use count"
    4446        if self.perf is not False:
    4547            f = open (self.perf, 'w+')
     
    4749        if output is not None:
    4850            if not os.path.exists (output):
    49                 print "path",output,"no exits"       
     51                print "path",output,"does not exists"
    5052                sys.exit(-1)
    5153            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
    5558        self.get_current_project()
     59        self.current_package = self.get_current_package()
    5660        self.instanciate_packages (file)
    5761        if self.local: self.get_local_graph()
    5862        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()
    7164
    7265    def get_current_project(self):
    7366        cmd = 'cmt show projects | grep current'
    74         status, output = commands.getstatusoutput (cmd)
     67        status, output = getstatusoutput (cmd)
     68        #status, output = commands.getstatusoutput (cmd)
    7569        if status != 0:
    7670            print output
    77             sys.exit(-1)   
     71            sys.exit(-1)
    7872        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] != '#':
    8175                item  = string.split (line, ' ')
    8276                self.current_project ['name']    = item[0]
     
    8781                    self.current_project ['path'] =  os.path.normpath(self.current_project ['path'][:-len(self.current_project ['version'] )])
    8882                return
    89                 #print self.current_project     
    90        
     83
    9184    def get_counter(self):
    92         self.semaphore.acquire ()       
     85        self.semaphore.acquire ()
    9386        self.counter = self.counter + 1
    94         value = self.counter 
     87        value = self.counter
    9588        self.semaphore.release()
    9689        return value
    97        
     90
    9891    def check_cycles (self):
    9992        cmd = 'cmt -private show cycles'
    10093        cycle_found = False
    101         status, output = commands.getstatusoutput (cmd)
     94        status, output = getstatusoutput (cmd)
     95        #status, output = commands.getstatusoutput (cmd)
    10296        if status != 0:
    10397            print output
    104             sys.exit(-1)   
     98            sys.exit(-1)
    10599        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()
    111105        for cycle in cycles:
    112106            cycleInProject = True
    113             for package in cycle:           
     107            for package in cycle:
    114108                if not self.packages.has_key(package):
    115                     cycleInProject = False       
    116             if cycleInProject: 
     109                    cycleInProject = False
     110            if cycleInProject:
    117111              cercles.append(cycle)
    118112        if len(cercles):
     
    120114                print "# Error: cycles found, not possible to execute broadcast with threads. Please correct the following cycles:"
    121115                for cycle in cercles:
    122                     loop = ""                   
     116                    loop = ""
    123117                    for package in cycle:
    124118                        loop = loop + package + ' -> '
    125119                    print loop + '...'
    126                 sys.exit(-1)       
     120                sys.exit(-1)
    127121            else:
    128122                print "# Warning: There are cycles and you have selected the automatic suppress cycles mode"
    129123                for cycle in cercles:
    130                     loop = ""                   
     124                    loop = ""
    131125                    for package in cycle:
    132                         loop = loop + package + ' -> '                     
     126                        loop = loop + package + ' -> '
    133127                    if cycle[0] in self.packages[cycle[len(cycle)-1]]['uses']:
    134128                        print '## In cycle: '+loop + '..., we suppress the dependency '+ cycle[len(cycle)-1]+'->'+cycle[0]
     
    151145        lines   = list()
    152146        for ligne in lignes:
    153             if ligne[:4] == "use ":             
     147            if ligne[:4] == "use ":
    154148               lines.append(ligne)
    155149        return lines
     
    169163                        if os.path.exists(path[1:-1] + '/' + offset + '/' +name + '/' + version + '/cmt'):
    170164                            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'):
    172166                            full_path = path[1:-1] + '/' + offset + '/' +name + '/cmt'
    173167                        else:
    174168                            print '# error path not found for', name
    175                             sys.exit(-1)   
     169                            sys.exit(-1)
    176170                    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)], " ")
    178172                        if os.path.exists(path[1:-1] + '/' + offset + '/' +name + '/' + version + '/cmt'):
    179173                            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'):
    181175                            full_path = path[1:-1] + '/' + offset + '/' +name + '/cmt'
    182176                        else:
    183177                            print '# error path not found for', name
    184                             sys.exit(-1)                                                                                                   
     178                            sys.exit(-1)
    185179                    elif len(result)==3:
    186180                        name, version, path = string.split (line[4:len(line)], " ")
    187181                        if os.path.exists(path[1:-1] + '/' +name + '/' + version + '/cmt'):
    188182                            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'):
    190184                            full_path = path[1:-1] + '/' +name + + '/cmt'
    191185                        else:
     
    195189                        print "error:",line
    196190                        print str(result)
    197                         sys.exit(-1) 
     191                        sys.exit(-1)
    198192                    self.packages[result[0]]['path'] = os.path.normpath(full_path)
    199193                    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']:
    201195                        #print result[0], ' belong to project', self.current_project ['name']
    202196                        self.packages[result[0]]['current_project'] = True
    203197
    204     def get_uses(self, content):       
     198    def get_uses(self, content):
    205199        # initiates variables
    206200        lignes = self.format_uses(content)
    207201        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',
    210204                                                'current_project': True, 'path': os.getcwd()}
    211205        previous_client = self.current_package
    212206        previous_level  = 0
    213207        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:
    216210            current_level = string.find(ligne, 'use')
    217             while current_level > previous_level:               
     211            while current_level > previous_level:
    218212                name    = string.split (ligne)[2]
    219                 version = string.split (ligne)[3]                             
     213                version = string.split (ligne)[3]
    220214                if not self.packages.has_key (name):
    221                   self.packages [name] = {'version': version, 'uses': list(),
    222                                           'client': list(), 'status': 'waiting',
     215                  self.packages [name] = {'version': version, 'use_count': 0,
     216                                          'uses': list(), 'status': 'waiting',
    223217                                          'current_project': False, 'path': None}
    224218                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)
    226220                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
    229223                if len(lignes):
    230224                    ligne = lignes.pop()
    231225                    #print ligne
    232226                    current_level = string.find(ligne, 'use')
    233                                            
    234             #self.packages [previous_client]['status'] ='queued'
     227
    235228            # restore the level
    236229            if len(lignes):
    237                 if len(level_stack):                       
    238                     item = level_stack.pop()               
     230                if len(level_stack):
     231                    item = level_stack.pop()
    239232                    while item['level'] >= current_level and len(level_stack):
    240233                             item = level_stack.pop()
     
    248241        if file is None:
    249242            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)
    253247        if status != 0:
    254248            print output
    255249            sys.exit(-1)
    256         self.get_uses(output)   
     250        self.get_uses(output)
    257251        self.get_paths(output)
    258         #self.check_execution (package=self.current_package)
    259252        #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
    260261
    261262    def get_local_graph(self):
     
    266267                    if key in self.packages[selected]['uses']:
    267268                       self.packages[selected]['uses'].remove(key)
    268                 To_remove.append (key) 
     269                To_remove.append (key)
    269270        for item in To_remove:
    270              del self.packages[item]
     271            del self.packages[item]
    271272
    272273    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):
    311294        cmd            = 'cmt show macro package'
    312         status, output = commands.getstatusoutput (cmd)
     295        status, output = getstatusoutput (cmd)
     296        #status, output = commands.getstatusoutput (cmd)
    313297        if status != 0:
    314298            print output
    315             sys.exit(-1)   
     299            sys.exit(-1)
    316300        lines = string.split(output, '\n')
    317301        for line in lines:
     
    321305                return line [start+1:start+end+1]
    322306
    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 output
    332             sys.exit(-1)   
    333         lines = string.split(output, '\n')
    334         for line in lines:
    335             if line [0] != '#' and line[:5] != "#CMT>":
    336                 print line
    337                 return line
    338  
    339307    def print_dependencies(self):
    340         print '# ------------------------'
    341         print '# package --> dependencies'
    342         print '# ------------------------'
     308        print '# -------------------------------------------'
     309        print '# package --> dependencies, status, use_count'
     310        print '# -------------------------------------------'
    343311        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']
    345313
    346314    def print_status(self, status):
    347         print '# ------------------------' 
    348         print '# package --> dependencies' 
    349         print '# ------------------------' 
     315        print '# ------------------------'
     316        print '# package --> dependencies'
     317        print '# ------------------------'
    350318        i = 1
    351319        for key in self.packages.keys():
    352320            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']
    354322                i = i + 1
    355            
     323
    356324    def is_work_unit_waiting (self, name):
    357325        return self.packages[name] ['status'] == 'waiting'
     
    360328        self.packages[name] ['status'] = status
    361329
    362     def get_dependencies (self, name):
    363         return self.packages[name] ['uses']
    364    
    365330    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 ]
    370342        return result
    371343
    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 True
    377         return False       
    378 
    379344    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'
    381348        for key in self.packages.keys():
    382349            if name in self.packages[key]['uses']:
    383350                self.packages[key]['uses'].remove(name)
     351        self.semaphore.release()
    384352
    385353    def add_work_unit (self, name, cmd):
    386354        if self.is_work_unit_waiting (name):
    387355            # 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)
    390360            # then we put the work request in the queue...
    391361            self.set_work_unit_status (name, 'queued')
    392362            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']))
    394364
    395365    def execute (self, command):
    396366        #self.print_dependencies ()
     367        self.semaphore.acquire()
    397368        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#--------------------------------------------------------------'
    401373            for package in packages:
    402374                self.add_work_unit (package, command)
     375            sys.stdout.flush()
     376        self.semaphore.release()
    403377
    404378    def execute_all(self,command):
     
    406380        self.execute (command)
    407381        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)
    408385        #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
    413388    def wait (self):
    414        self.pool.wait()   
     389       self.pool.wait()
    415390
    416391    # this will be called each time a result is available
     
    418393      #print "**Result: %s from request #%s" % (str(result), request.requestID)
    419394      #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
    425398    def do_execute(self, arg):
    426       path = self.get_work_area_path (arg['package'])
     399      package = arg['package']
     400      path = self.packages[package]['path']
    427401      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'
    435406      header = header + '#--------------------------------------------------------------\n'
    436407      print header
     408      sys.stdout.flush()
    437409      project_path = self.current_project['path']+'/'+self.current_project['version']+'/'
    438410      log_name     = string.replace(path, project_path, '')
     
    440412      log_name     = string.replace(log_name, '/', '_')
    441413      log_name     = log_name+'.loglog'
    442       arg['log']   = log_name
    443       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)
    445417      # init output file
    446418
    447       self.packages[arg['package']] ['startTime'] = time.time ()                           
     419      self.packages[package] ['startTime'] = time.time()
    448420
    449421      if self.output is not None:
    450            f1 = open (self.output+'/'+ log_name, 'w+')           
     422           f1 = open (self.output+'/'+ log_name, 'w+')
    451423           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()
    452435           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()               
    461436      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
    464444      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()
    468449      if self.perf:
    469           self.semaphore.acquire ()       
     450          self.semaphore.acquire()
    470451          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')
    472453          f.close()
    473454          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)
    479456      return {'cmd': arg['cmd'], 'package':arg['package']}
    480457
    481              
     458
    482459    # this will be called when an exception occurs within a thread
    483460    def handle_exception(self, request, exc_info):
    484         #traceback.print_stack()
    485       print '#--------------------------------------------------------------'       
     461      #traceback.print_stack()
     462      print '#--------------------------------------------------------------'
    486463      #print "# Exception occured in request #%s: %s" %(request.requestID, exc_info[1])
    487464      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 '#--------------------------------------------------------------'
    490467        sys.exit(exc_info[1])
    491       print "# Exception occured: %s" %(exc_info[1])     
     468      print "# Exception occured: %s" %(exc_info[1])
    492469      print exc_info
    493       print '#--------------------------------------------------------------'   
     470      print '#--------------------------------------------------------------'
    494471      #sys.exit(-1)
    495472
    496    
     473
    497474    def generate_make (self, file, command):
    498475        makefile = open (file, 'w+')
     
    502479        self.recursive_make (self.current_package, command, makefile, len(self.packages))
    503480        makefile.close ()
    504        
     481
    505482    def recursive_make (self, package, command, makefile, indice,actions=list()):
    506483        lines = self.generate_action_make (package, command, indice)
    507484        makefile.write (lines)
    508         #print lines               
     485        #print lines
    509486        for pkg in self.packages[package] ['uses']:
    510487            if pkg not in actions:
     
    512489                indice = indice - 1
    513490                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
    516493    def generate_action_make (self, package, command, indice):
    517         lines = package + ' :: '       
     494        lines = package + ' :: '
    518495        # add dependencies
    519496        for pkg in self.packages[package] ['uses']:
    520             lines = lines + ' ' + pkg           
     497            lines = lines + ' ' + pkg
    521498
    522499        # add the action itself
    523         newcommand = string.replace (command, '<package>', package)       
     500        newcommand = string.replace (command, '<package>', package)
    524501        if command =='':
    525502            newcommand='$(MAKE)'
     
    529506        lines = lines +  '\t@echo "#--------------------------------------------------------------"\n'
    530507        lines = lines +  'ifdef LOCATION\n'
    531         lines = lines +  '\t@echo "#--------------------------------------------------------------"> $(LOCATION)/'+ package +'.loglog\n'       
     508        lines = lines +  '\t@echo "#--------------------------------------------------------------"> $(LOCATION)/'+ package +'.loglog\n'
    532509        lines = lines +  '\t@echo "# ('+str(self.counter)+'/'+str(len(self.packages))+') Now trying ['+newcommand+'] in '+ self.packages[package]['path']+'">> $(LOCATION)/'+ package +'.loglog\n'
    533510        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']
    535512        lines = lines + ' && ' + newcommand + ' >> $(LOCATION)/'+ package +'.loglog 2>&1\n'
    536513        lines = lines + 'else\n'
    537         lines = lines + '\t+@cd ' + self.packages[package]['path']           
     514        lines = lines + '\t+@cd ' + self.packages[package]['path']
    538515        lines = lines + ' && ' + newcommand + '\n'
    539         lines = lines + 'endif\n\n'               
     516        lines = lines + 'endif\n\n'
    540517        return lines
    541        
     518
     519
     520# own copy of getstatusoutput
     521def 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
    542537#--------- EoF --------#
Note: See TracChangeset for help on using the changeset viewer.