Package Ganga :: Package Runtime :: Module XML_repository_runtime
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Runtime.XML_repository_runtime

 1  import os 
 2  from Ganga.Utility.logging import getLogger,log_user_exception 
 3  logger = getLogger() 
 4  import Ganga.Utility.Config 
 5  config = Ganga.Utility.Config.makeConfig('LocalXML_Repository','Parameters of the local XML-based job repository') 
 6  config.addOption('DEBUG_startup_profile',False,'(ADVANCED DEBUGGING) enable/disable profiling of job repository at startup') 
 7   
 8  c_config = Ganga.Utility.Config.getConfig('Configuration') 
 9   
10  # this is set by the Repository_runtime module 
11  getLocalRoot = None 
12   
13  #keep the (names,regs) 
14  names=[] 
15  regs=[] 
16   
17 -def requiresGridProxy():
18 return False
19
20 -def bootstrap():
21 global names,regs 22 23 names = ['jobs','templates'] 24 docstrings = ['default job registry', 'default registry of job templates'] 25 26 from Ganga.Core.JobRepositoryXML import factory, version 27 28 from Ganga.Core.exceptions import RepositoryError 29 30 def print_error(x): 31 for c in config: 32 logger.error('%s = %s',c,config[c]) 33 s = 'Cannot connect to the repository: '+str(x) 34 logger.error(s) 35 return s
36 37 reps = [] 38 try: 39 for n in names: 40 reps.append(factory(dir = os.path.join(getLocalRoot(),version,n))) 41 except RepositoryError,x: 42 s = print_error(x) 43 raise 44 except Exception,x: 45 s = print_error(x) 46 log_user_exception(logger) 47 raise 48 49 from Ganga.GPIDev.Lib.JobRegistry import JobRegistryInstance, JobRegistryInterface, allJobRegistries 50 51 regs = map(lambda x: JobRegistryInstance(*x), zip(names,reps)) 52 53 for n,r in zip(names,regs): 54 allJobRegistries['native_'+n] = r 55 if n == 'jobs' and config['DEBUG_startup_profile']: 56 PROFN = 'xml.startup.profile.txt' 57 print 'profiling ON, saving status to',PROFN 58 import profile 59 profile.runctx('r._scan_repository()',globals(),{'r':r},PROFN) 60 else: 61 try: 62 r._scan_repository() 63 except Exception,x: 64 s = print_error(x) 65 log_user_exception(logger) 66 logger.critical('the repository cannot be loaded (dir=%s)',r.repository.dir) 67 import tempfile, tarfile 68 fn = tempfile.mktemp(suffix='.tgz',prefix='Ganga-Repository-XML') 69 tf = tarfile.open(fn,mode='w:gz') 70 tf.add(r.repository.dir,"Ganga-Repository-XML",recursive=True) 71 tf.close() 72 logger.critical('the repository was dumped to %s (%s) for debugging',fn,Ganga.Utility.util.hostname()) 73 raise x 74 75 # commit the migrated jobs (if any) 76 #r._flush(migrated_jobs) 77 #migrated_jobs[:] = [] 78 79 proxies = map(lambda x: JobRegistryInterface(x), regs) 80 81 logger.debug('registred repository atexit handler') 82 83 import atexit 84 atexit.register(shutdown) 85 86 return zip(names,proxies,docstrings) 87 88
89 -def shutdown():
90 global names,regs 91 from Ganga.Runtime.Repository_runtime import _shutdown 92 _shutdown(names,regs)
93