"""Interface to the config_workflow.xml file. This class inherits from GenericXML.py"""fromCIME.XML.standard_module_setupimport*fromCIME.XML.generic_xmlimportGenericXMLfromCIME.XML.filesimportFilesfromCIME.utilsimportexpectlogger=logging.getLogger(__name__)
[docs]classWorkflow(GenericXML):def__init__(self,infile=None,files=None):""" initialize an object """iffilesisNone:files=Files()ifinfileisNone:infile=files.get_value("WORKFLOW_SPEC_FILE")expect(infile,"No workflow file defined in {}".format(files.filename))schema=files.get_schema("WORKFLOW_SPEC_FILE")GenericXML.__init__(self,infile,schema=schema)# Append the contents of $HOME/.cime/config_workflow.xml if it exists# This could cause problems if node matchs are repeated when only one is expectedinfile=os.path.join(os.environ.get("HOME"),".cime","config_workflow.xml")ifos.path.exists(infile):GenericXML.read(self,infile)
[docs]defget_workflow_jobs(self,machine,workflowid="default"):""" Return a list of jobs with the first element the name of the script and the second a dict of qualifiers for the job """jobs=[]bnodes=[]findmore=Trueprepend=Falsewhilefindmore:bnode=self.get_optional_child("workflow_jobs",attributes={"id":workflowid})expect(bnode,"No workflow {} found in file {}".format(workflowid,self.filename),)ifprepend:bnodes=[bnode]+bnodeselse:bnodes.append(bnode)prepend=Falseworkflow_attribs=self.attrib(bnode)if"prepend"inworkflow_attribs:workflowid=workflow_attribs["prepend"]prepend=Trueelif"append"inworkflow_attribs:workflowid=workflow_attribs["append"]else:findmore=Falseforbnodeinbnodes:forjnodeinself.get_children(root=bnode):ifself.name(jnode)=="job":name=self.get(jnode,"name")jdict={}forchildinself.get_children(root=jnode):ifself.name(child)=="runtime_parameters":attrib=self.attrib(child)ifattribandattrib=={"MACH":machine}:forrtchildinself.get_children(root=child):jdict[self.name(rtchild)]=self.text(rtchild)elifnotattrib:forrtchildinself.get_children(root=child):ifself.name(rtchild)notinjdict:jdict[self.name(rtchild)]=self.text(rtchild)else:jdict[self.name(child)]=self.text(child)jobs.append((name,jdict))returnjobs