def insertClassIntoGPI(class_): """ Insert a given class object into the GPI Args: class_ (class): This is the class object to insert into the GPI """ exportToGPI(_getName(class_), class_, "Objects") allPlugins.add(class_, class_._category, _getName(class_)) allPlugins._prev_found = {}
def __init__(cls, name, bases, this_dict): from Ganga.GPIDev.Base.Proxy import GPIProxyClassFactory super(ObjectMetaclass, cls).__init__(name, bases, this_dict) # all Ganga classes must have (even empty) schema if cls._schema is None: cls._schema = Schema.Schema(None, None) this_schema = cls._schema # Add all class members of type `Schema.Item` to the _schema object # TODO: We _could_ add base class's Items here by going through `bases` as well. # We can't just yet because at this point the base class' Item has been overwritten with a Descriptor for member_name, member in this_dict.items(): if isinstance(member, Schema.Item): this_schema.datadict[member_name] = member # sanity checks for schema... if '_schema' not in this_dict.keys(): s = "Class %s must _schema (it cannot be silently inherited)" % (name,) logger.error(s) raise ValueError(s) # If a class has not specified a '_name' then default to using the class '__name__' if not cls.__dict__.get('_name'): cls._name = name if this_schema._pluginclass is not None: logger.warning('Possible schema clash in class %s between %s and %s', name, getName(cls), getName(this_schema._pluginclass)) # export visible properties... do not export hidden properties for attr, item in this_schema.allItems(): setattr(cls, attr, cls._descriptor(attr, item)) # additional check of type # bugfix #40220: Ensure that default values satisfy the declared types # in the schema for attr, item in this_schema.simpleItems(): if not item['getter']: item._check_type(item['defvalue'], '.'.join([name, attr]), enableGangaList=False) # create reference in schema to the pluginclass this_schema._pluginclass = cls # if we've not even declared this we don't want to use it! if not cls._declared_property('hidden') or cls._declared_property('enable_plugin'): allPlugins.add(cls, cls._category, getName(cls)) # create a configuration unit for default values of object properties if not cls._declared_property('hidden') or cls._declared_property('enable_config'): this_schema.createDefaultConfig() # store generated proxy class setattr(cls, '_proxyClass', GPIProxyClassFactory(name, cls))
logger.warning("do not understand option %s in [Plugins]", opt) logger.debug('Reason: want %s' % str(err)) else: if tag == 'default': try: allPlugins.setDefault(category, default_plugins_cfg[opt]) except Ganga.Utility.Plugin.PluginManagerError as x: logger.warning('cannot set the default plugin "%s": %s' % (opt, x)) else: logger.warning("do not understand option %s in [Plugins]", opt) # set alias for default Batch plugin (it will not appear in the # configuration) batch_default_name = getConfig('Configuration').getEffectiveOption('Batch') try: batch_default = allPlugins.find('backends', batch_default_name) except Exception as x: raise Ganga.Utility.Config.ConfigError('Check configuration. Unable to set default Batch backend alias (%s)' % str(x)) else: allPlugins.add(batch_default, 'backends', 'Batch') from Ganga.Runtime.GPIexport import exportToInterface if not my_interface: import Ganga.GPI my_interface = Ganga.GPI exportToInterface(my_interface, 'Batch', batch_default, 'Classes')
'''Merger for XML summary files.''' _category = 'mergers' _exportmethods = ['merge'] _name = 'GaudiXMLSummaryMerger' _schema = AbstractMerger._schema.inherit_copy() def __init__(self): super(GaudiXMLSummaryMerger, self).__init__(_GaudiXMLSummaryMergeTool()) def merge(self, jobs, outputdir=None, ignorefailed=None, overwrite=None): from Ganga.GPIDev.Lib.Job import Job gaudi_env = {} if isinstance(jobs, GPIProxyObject) and isinstance(jobs._impl, Job): gaudi_env = jobs.application.getenv() elif len(jobs) > 0: gaudi_env = jobs[0].application.getenv() self.merge_tool.env_var = gaudi_env['XMLSUMMARYBASEROOT'] #needed as exportmethods doesn't seem to cope with inheritance return super(GaudiXMLSummaryMerger, self).merge(jobs, outputdir, ignorefailed, overwrite) #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\# # Add it to the list of plug-ins allPlugins.add(_GaudiXMLSummaryMergeTool, 'merge_tools', '_GaudiXMLSummaryMergeTool') #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
opts_file.close() if not os.path.exists(opts_file_name): msg = "Failed to write temporary options file '%s' during merge" raise PostProcessException(msg % opts_file_name) import EnvironFunctions script_file_name = EnvironFunctions.construct_merge_script(self.version, opts_file_name) return_code = subprocess.call(['/bin/sh', script_file_name]) if return_code != 0: msg = 'The LHCbFileMerger returned %i when calling gaudirun' logger.warning(msg % return_code) # finally clean up os.unlink(script_file_name) os.unlink(opts_file_name) if not os.path.exists(output_file): msg = "The output file '%s' was not created" raise PostProcessException(msg % output_file) # needed as exportmethods doesn't seem to cope with inheritance #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\# # Add it to the list of plug-ins allPlugins.add(LHCbFileMerger, 'postprocessor', 'LHCbFileMerger') #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
super(MockExeApplication, self).__init__() self.called = False def transition_update(self, new_status): if new_status in expected_minimal_states: expected_minimal_states.remove(new_status) self.called = True from Ganga.GPIDev.Adapters.ApplicationRuntimeHandlers import allHandlers allHandlers.add('MockExeApplication', 'Local', RTHandler) from Ganga.Utility.Plugin import allPlugins allPlugins.add(MockExeApplication, 'applications', 'MockExeApplication') from GangaTest.Framework.tests import GangaGPITestCase from GangaTest.Framework.utils import sleep_until_completed class TestTransitions(GangaGPITestCase): def testTransitionsCalled(self): m = MockExeApplication() j = Job(backend=Local()) j.application = m j.submit()
if not os.path.exists(opts_file_name): msg = "Failed to write temporary options file '%s' during merge" raise PostProcessException(msg % opts_file_name) import EnvironFunctions script_file_name = EnvironFunctions.construct_merge_script( self.version, opts_file_name) return_code = subprocess.call(['/bin/sh', script_file_name]) if return_code != 0: msg = 'The LHCbFileMerger returned %i when calling gaudirun' logger.warning(msg % return_code) # finally clean up os.unlink(script_file_name) os.unlink(opts_file_name) if not os.path.exists(output_file): msg = "The output file '%s' was not created" raise PostProcessException(msg % output_file) # needed as exportmethods doesn't seem to cope with inheritance #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\# # Add it to the list of plug-ins allPlugins.add(LHCbFileMerger, 'postprocessor', 'LHCbFileMerger') #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
def __init__(cls, name, bases, dict): super(ObjectMetaclass, cls).__init__(name, bases, dict) # ignore the 'abstract' base class # FIXME: this mechanism should be based on explicit cls._name or alike if name == 'GangaObject': return logger.debug("Metaclass.__init__: class %s name %s bases %s",cls,name,bases) # all Ganga classes must have (even empty) schema assert(not cls._schema is None) # produce a GPI class (proxy) proxyClass = GPIProxyClassFactory(name,cls) # export public methods of this class and also of all the bases # this class is scanned last to extract the most up-to-date docstring dictlist = [b.__dict__ for b in cls.__mro__] for di in range(0, len(dictlist)): d = dictlist[len(dictlist)-1-di] for k in d: if k in cls._exportmethods: try: internal_name = "_export_"+k method = d[internal_name] except KeyError: internal_name = k method = d[k] if not (type(method) == types.FunctionType): continue f = ProxyMethodDescriptor(k,internal_name) f.__doc__ = method.__doc__ setattr(proxyClass, k, f) # sanity checks for schema... if not '_schema' in dict.keys(): s = "Class %s must _schema (it cannot be silently inherited)" % (name,) logger.error(s) raise ValueError(s) if not cls._schema._pluginclass is None: logger.warning('Possible schema clash in class %s between %s and %s',name,cls._name,cls._schema._pluginclass._name) # export visible properties... do not export hidden properties for attr, item in cls._schema.allItems(): setattr(cls, attr, cls._descriptor(attr, item)) if not item['hidden']: setattr(proxyClass, attr, ProxyDataDescriptor(attr)) # additional check of type # bugfix #40220: Ensure that default values satisfy the declared types in the schema for attr, item in cls._schema.simpleItems(): if not item['getter']: item._check_type(item['defvalue'],'.'.join([name,attr]),enableGangaList=False) # create reference in schema to the pluginclass cls._schema._pluginclass = cls # store generated proxy class cls._proxyClass = proxyClass # register plugin class if not cls._declared_property('hidden') or cls._declared_property('enable_plugin'): allPlugins.add(cls,cls._category,cls._name) # create a configuration unit for default values of object properties if not cls._declared_property('hidden') or cls._declared_property('enable_config'): cls._schema.createDefaultConfig()
docstr = 'The version of DaVinci to use when merging. (e.g. v19r14)' _schema.datadict['version'] = SimpleItem(defvalue='', doc=docstr) def __init__(self): super(DSTMerger,self).__init__(_DSTMergeTool()) def merge(self, jobs, outputdir=None, ignorefailed=None, overwrite=None): self.merge_tool.merge_opts = self.merge_opts self.merge_tool.version = self.version logger.debug("zhangxm log: begin to register file!\n") # do file registering for sj in jobs: if sj.status=='completed': sj.application.register() # do file registering with BDRegister #bdr = BDRegister() #bdr.registerFile(jobs) #needed as exportmethods doesn't seem to cope with inheritance #return super(DSTMerger,self).merge(jobs, outputdir, ignorefailed, #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\# # Add it to the list of plug-ins allPlugins.add(_DSTMergeTool,'merge_tools','_DSTMergeTool') #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
class GaudiXMLSummaryMerger(AbstractMerger): '''Merger for XML summary files.''' _category = 'mergers' _exportmethods = ['merge'] _name = 'GaudiXMLSummaryMerger' _schema = AbstractMerger._schema.inherit_copy() def __init__(self): super(GaudiXMLSummaryMerger,self).__init__(_GaudiXMLSummaryMergeTool()) def merge(self,jobs,outputdir=None,ignorefailed=None,overwrite=None): from Ganga.GPIDev.Lib.Job import Job gaudi_env = {} if isinstance(jobs,GPIProxyObject) and isinstance(jobs._impl,Job): gaudi_env = jobs.application.getenv() elif len(jobs) > 0: gaudi_env = jobs[0].application.getenv() self.merge_tool.env_var = gaudi_env['XMLSUMMARYBASEROOT'] #needed as exportmethods doesn't seem to cope with inheritance return super(GaudiXMLSummaryMerger,self).merge(jobs,outputdir, ignorefailed,overwrite) #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\# # Add it to the list of plug-ins allPlugins.add(_GaudiXMLSummaryMergeTool,'merge_tools', '_GaudiXMLSummaryMergeTool') #\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
def __init__(self): super(MockExeApplication, self).__init__() self.called = False def transition_update(self, new_status): if new_status in expected_minimal_states: expected_minimal_states.remove(new_status) self.called = True from Ganga.GPIDev.Adapters.ApplicationRuntimeHandlers import allHandlers allHandlers.add('MockExeApplication', 'Local', RTHandler) from Ganga.Utility.Plugin import allPlugins allPlugins.add(MockExeApplication, 'applications', 'MockExeApplication') from GangaTest.Framework.tests import GangaGPITestCase from GangaTest.Framework.utils import sleep_until_completed class TestTransitions(GangaGPITestCase): def testTransitionsCalled(self): m = MockExeApplication() j = Job(backend=Local()) j.application = m j.submit()
""" _category = 'mergers' _exportmethods = ['merge'] _name = 'CustomMerger' _schema = AbstractMerger._schema.inherit_copy() _schema.datadict['module'] = FileItem(defvalue = None, doc='Path to a python module to perform the merge.') def __init__(self): super(CustomMerger,self).__init__(_CustomMergeTool()) def merge(self, jobs, outputdir = None, ignorefailed = None, overwrite = None): if self.module is None or not self.module: logger.error('No custom module specified. The merge will end now') return AbstractMerger.success self.merge_tool.module = self.module #needed as exportmethods doesn't seem to cope with inheritance return super(CustomMerger,self).merge(jobs, outputdir, ignorefailed, overwrite) #configure the plugins allPlugins.add(_CustomMergeTool,'merge_tools','_CustomMergeTool') allPlugins.add(_TextMergeTool,'merge_tools','_TextMergeTool') allPlugins.add(_RootMergeTool,'merge_tools','_RootMergeTool') #we need a default, but don't care much what it is allPlugins.setDefault('merge_tools','_TextMergeTool')