def importClassFromModuleString(s, verbose=False): if isinstance(s,str): s = s.strip() if(s[0] == "{"): # json string s = cF.jsonParse(s) if verbose: print("Load class: %s in module: %s" % (s["className"],s["moduleName"]) ) return importClassFromModule(**s) # normal string e.g.: JobGenerator.jobGenerators.jobGeneratorMPI.RigidBodySim comps = s.split(".") clName = comps[-1] mdName = ".".join(comps[0:-1]) if verbose: print("Load class: %s in module: %s" % (clName,mdName) ) return importClassFromModule(moduleName=mdName,className=clName) elif isinstance(s,dict): if verbose: print("Load class: %s in module: %s" % (s["className"],s["moduleName"]) ) return importClassFromModule(**s) else: raise NameError("Could no load module by string: %s" % s)
def __checkConfig(self, interact): # expand global and local dirs if not path.exists(self.cTemplates.startJob): raise CE.MyValueError("Start Script template %s does not exist!" % self.cTemplates.startJob) if not path.exists(self.cTemplates.preProcessPerNode): raise CE.MyValueError("Start Script template %s does not exist!" % self.cTemplates.preProcessPerNode) if not path.exists(self.cTemplates.processPerCore): raise CE.MyValueError("Start Script template %s does not exist!" % self.cTemplates.processPerCore) if not path.exists(self.cTemplates.postProcessPerNode): raise CE.MyValueError("Start Script template %s does not exist!" % self.cTemplates.postProcessPerNode) if not path.exists(self.cTemplates.endJob): raise CE.MyValueError("Start Script template %s does not exist!" % self.cTemplates.endJob) if self.cJob.copyLocation and not path.exists(self.cJob.copyLocation): raise CE.MyValueError("Copy location %s does not exist!" % self.cJob.copyLocation) cF.checkNotExisting(self.cJob.globalDir, interact=interact, name="Global dir") # add no tar command if not tarCommandToGlobalDir is not specified if "tarCommandToGlobalDir" not in self.cJob: self.cJob["tarCommandToGlobalDir"] = "" if "pathChecker" in self.cJob: pathChecker = cF.jsonParse(self.cJob.pathChecker) pathChecker = cF.flatten(pathChecker) for s in pathChecker: if not os.path.exists(s) or not os.path.lexists(s): raise CE.MyValueError("file: %s does not exist!" % s) # check executbles with which and return correct path if "executableChecker" in self.cJob: execCheck = cF.jsonParse(self.cJob.executableChecker) for varAccess, ex in execCheck: exec("self.configDict" + varAccess + "= cF.checkExecutable(ex)")
def writeTemplates(self , generator, configDicts ): # iterate over all template strings for k,templ in self.cTemplates.items(): # get output file outFile = self.cTemplatesOut[k] # interprete the string as a json string if the first character is a { # { "inputFile" : "?" , "outputFile": "??" , "configurator" : "??" } # otherwise it is intrepreted as a inputFile which is configurated with the standart # configurator which replaces strings and the output goes into the Job:scriptDir # where the file is made executable templ = templ.strip() configurator = None if templ and templ[0] == "{": templ = cF.jsonParse(templ) settings = {} if "settings" in templ: settings = templ["settings"] inFile = templ["inputFile"] configurator = templ["configurator"] # jobConfigurator.generatorRigidBody.adjuster or what ever # only load each configurator once configuratorHash = self.makeConfiguratorHash(**configurator) # load the special configurator if not loaded yet if configuratorHash not in self.templateConfigurators: print("Instantiate configurator: " , configurator ) moduleType, classType = iH.importClassFromModule(**configurator) self.templateConfigurators[configuratorHash] = classType({"commonFunctions":cF,"importHelpers":iH}) # make instance (hand over modules) configuratorFunc = self.templateConfigurators[configuratorHash]; # configure file configuratorFunc(generator, inFile, outFile, self.configDict, configDicts, **settings ) else: # use standart dictionary adjuster as default inFile = templ #configure file self.defaultTemplateConfigurator(generator,inFile, outFile, self.configDict, configDicts, verbose=self.cCluster.verbose, makeExecutable=True)