def _FormatFormData(self, webform): """Make dictionary of webform data""" for keys in webform: # Make a plugin centeric dictionary of all key/value pairs pl, op = keys.split('.') if not self.formdata.has_key(pl): self.formdata[pl] = {} self.formdata[pl][op] = webform[keys] for keys in self.formdata: # get default values from workflow xml file for options in self.formdata[keys]: if self.formdata[keys][options] == 'submit': if os.path.isfile("%s/workflows/%s.xml" % (self.DARTDIR, keys)): self.xml = Xpath("%s/workflows/%s.xml" % (self.DARTDIR, keys)) self._MainXMLdataHandler() self._PluginXMLdataHandler() for plugin in self.pluginoptions: # Check formdata against default workflow. Missing values for options in self.pluginoptions[ plugin]: # are set to there default ones. if self.formdata.has_key(str(plugin)): if not self.formdata[str(plugin)].has_key(options): self.formdata[str(plugin)][ options] = self.pluginoptions[plugin][options] #if self.pluginform[plugin][options] == 'checkbox': # self.formdata[str(plugin)][options] = False #else: # self.formdata[str(plugin)][options] = self.pluginoptions[plugin][options] else: self.formdata[str(plugin)] = self.pluginoptions[ plugin] # If complete plugin is missing in formdata than
def MakeWebForm(self, verbose=False, xml=None): """Control module for generating a webform from XMLdata""" self.xml = Xpath(xml) self.verbose = verbose self._MainXMLdataHandler() self._PluginXMLdataHandler() self._WriteHTML()
def _ParamDictHandler(self, mainxml, plugin, step): """Returns dictionary with parameter data""" """Get all option attributes""" mainxml.Evaluate( query={ 1: { 'element': 'plugin', 'attr': { 'job': step } }, 2: { 'element': 'parameters', 'attr': None }, 3: { 'element': 'option', 'attr': None } }) for data in mainxml.nodeselection[3]: mainxml.getAttr(node=data, selection='type', export='string') attributelist = mainxml.result mainxml.ClearResult() """Get all values belonging to options""" paramdict = {} for data in mainxml.nodeselection[3]: query = Xpath(data.toxml()) for attribute in attributelist: query.Evaluate(query={ 1: { 'element': 'option', 'attr': { 'type': attribute } } }) for node in query.nodeselection[1]: query.getData(node=node, export='list') if len(query.result) > 0: paramdict[attribute] = query.result[0][0] else: paramdict[attribute] = None query.ClearResult() """Print data as info to user""" if paramdict['useplugin']: print "--> Variables defined for executing the plugin core:" for parameter in paramdict: print(" * Variable %s: %s" % (parameter, paramdict[parameter])) else: print "--> Use this plugin set to: False" return paramdict
def PluginExecutor(self): """Get meta data from workflow xml file""" mainxml = Xpath(self.opt_dict['workflow']) self.maindict = self._MainXMLdataHandler(mainxml) """Make main workflow directory""" self._MakeRundir( os.path.basename(os.path.splitext(self.maindict['name'])[0])) shutil.copy(self.opt_dict['workflow'], self.rundir) os.chdir(self.rundir) """Write job output to xml file""" self.xmlroot = Node("container", ID="filelist") """Executing all plugins""" steps = len(self.maindict['workflowsequence'].keys()) step = 1 while step < (steps + 1): plugin = self.maindict['workflowsequence'][float(step)] outputlist = self._Executor(plugin, mainxml, step) self._WriteOutput(outputlist, plugin, step) step = step + 1 self._OutputToFile()
def _GetInput(self, paramdict): rawxml = self.xmlroot.rawxml() inputlist = [] if paramdict['inputfrom'] == "self": xml = Xpath(rawxml) xml.Evaluate( query={ 1: { 'element': 'plugin', 'attr': { 'nr': '1' } }, 2: { 'element': None, 'attr': None } }) for elements in xml.nodeselection[2]: xml.getElem(node=elements, export='string') data = xml.result xml.ClearResult() return data elif paramdict['inputfrom'] == "None": return inputlist else: try: inputfrom = paramdict['inputfrom'].split(',') except: inputfrom = [(paramdict['inputfrom'])] data = [] for n in inputfrom: xml = Xpath(rawxml) xml.Evaluate( query={ 1: { 'element': 'plugin', 'attr': { 'nr': str(int(n)) } }, 2: { 'element': 'file', 'attr': None } }) for elements in xml.nodeselection[2]: xml.getData(node=elements, export='string') for result in xml.result: data.append(result) xml.ClearResult() return data
def WorkflowXML(self): """Generate workflow.xml file at startup. This file allways needs to be present. The source can be a pregenerated workflow file or a sequence of plugins supplied on the command line with the -p or --plugin option.""" if not self.option_dict['pluginseq'] == None: workflow_dict = self.WorkflowSequence() print " * Generate workflow from command line constructed plugin batch sequence" print " * Check if all plugins are present and of a valid type" plugins = [] for n in workflow_dict.values(): if not n in plugins: plugins.append(n) self._TryPluginImport(n) print " * Writing workflow XML file as workflow.xml" outfile = file('workflow.xml', 'w') outfile.write("""<?xml version="1.0" encoding="iso-8859-1"?>\n""") outfile.write("""<main id="DARTworkflow">\n""") outfile.write("<meta>\n") outfile.write("<name>workflow.xml</name>\n") outfile.write("<datetime>" + ctime() + "</datetime>\n") outfile.write("</meta>\n") for key in workflow_dict: outfile.write("<plugin id='" + workflow_dict[key] + "' job='" + str(key) + "'>") exec "from plugins import " + workflow_dict[key] exec "outfile.write(\n" + workflow_dict[key] + ".PluginXML())" outfile.write("\n</plugin>\n") outfile.write("</main>\n") outfile.close() self.option_dict['workflow'] = 'workflow.xml' if self.option_dict['dry'] == True: print " * Option 'dry' is True, only write workflow.xml file" sys.exit(0) elif not self.option_dict['workflow'] == None: print " * Check if all plugins in pre-supplied 3D-DART workflow", self.option_dict[ 'workflow'], "are present and of a valid type" if os.path.isfile(self.option_dict['workflow']): pass elif os.path.isfile( RenameFilepath(self.option_dict['workflow'], path=self.DARTdir + "/workflows/", extension=".xml")): self.option_dict['workflow'] = RenameFilepath( self.option_dict['workflow'], path=self.DARTdir + "/workflows", extension=".xml") else: print " * ERROR: the workflow:", self.option_dict[ 'workflow'], "cannot be found" sys.exit(0) query = Xpath(self.option_dict['workflow']) query.Evaluate(query={1: {'element': 'plugin', 'attr': None}}) for job in query.nodeselection[1]: query.getAttr(node=job, selection=['id'], export='string') workflow = query.result query.ClearResult() plugins = [] for n in workflow: if not n in plugins: plugins.append(n) self._TryPluginImport(n) print " * Plugin sequence is valid"
def _PluginXMLdataHandler(self): """Make a dictionary of all plugin data""" for job in self.metadata['workflowsequence']: plugindata = {} #Get all Elements self.xml.Evaluate( query={ 1: { 'element': 'plugin', 'attr': { 'job': str(job) } }, 2: { 'element': 'metadata', 'attr': None }, 3: { 'element': None, 'attr': None } }) for data in self.xml.nodeselection[3]: self.xml.getElem(node=data, export='string') elementlist = self.xml.result self.xml.ClearResult() #For element get data for element in self.xml.nodeselection[3]: self.xml.getData(node=element, export='string') elementdata = self.xml.result self.xml.ClearResult() for element in elementlist: plugindata[element] = elementdata[elementlist.index(element)] #Get all option attributes self.xml.Evaluate( query={ 1: { 'element': 'plugin', 'attr': { 'job': str(job) } }, 2: { 'element': 'parameters', 'attr': None }, 3: { 'element': 'option', 'attr': None } }) for data in self.xml.nodeselection[3]: self.xml.getAttr(node=data, selection='type', export='string') optionlist = self.xml.result self.xml.ClearResult() options = {} formdata = {} default = {} text = {} #Get all values belonging to options for data in self.xml.nodeselection[3]: query = Xpath(data.toxml()) for option in optionlist: query.Evaluate(query={ 1: { 'element': 'option', 'attr': { 'type': option } } }) for node in query.nodeselection[1]: query.getData(node=node, export='list') if len(query.result) > 0: if query.result[0][0] == None: options[option] = '' else: options[option] = query.result[0][0] else: options[option] = '' query.ClearResult() query.getAttr(node=node, selection='form', export='string') if len(query.result) > 0: formdata[option] = query.result[0] else: formdata[option] = None query.ClearResult() query.getAttr(node=node, selection='default', export='string') if len(query.result) > 0: default[option] = query.result[0] else: default[option] = None query.ClearResult() query.getAttr(node=node, selection='text', export='string') if len(query.result) > 0: text[option] = query.result[0] else: text[option] = None query.ClearResult() self.pluginmeta[job] = plugindata self.pluginoptions[job] = options self.pluginform[job] = formdata self.plugindefault[job] = default self.plugintext[job] = text