+class PipelineRun(object):
+ """
+ Capture "interesting" information about a pipeline run
+ """
+ def __init__(self, pathname, firecrest, bustard, gerald):
+ self.pathname = pathname
+ self._name = None
+ self._flowcell_id = None
+ self.firecrest = firecrest
+ self.bustard = bustard
+ self.gerald = gerald
+
+ def _get_flowcell_id(self):
+ # extract flowcell ID
+ if self._flowcell_id is None:
+ config_dir = os.path.join(self.pathname, 'Config')
+ flowcell_id_path = os.path.join(config_dir, 'FlowcellId.xml')
+ flowcell_id_tree = ElementTree.parse(flowcell_id_path)
+ self._flowcell_id = flowcell_id_tree.findtext('Text')
+ return self._flowcell_id
+ flowcell_id = property(_get_flowcell_id)
+
+ def _get_xml(self):
+ """
+ make one master xml file from all of our sub-components.
+ """
+ root = ElementTree.Element('PipelineRun')
+ flowcell = ElementTree.SubElement(root, 'FlowcellID')
+ flowcell.text = self.flowcell_id
+ root.append(self.firecrest.elements)
+ root.append(self.bustard.elements)
+ root.append(self.gerald.elements)
+ return root
+
+ def _get_pretty_xml(self):
+ """
+ Generate indented xml file
+ """
+ root = self._get_xml()
+ indent(root)
+ return root
+ xml = property(_get_pretty_xml)
+
+ def _get_run_name(self):
+ """
+ Given a run tuple, find the latest date and use that as our name
+ """
+ if self._name is None:
+ tmax = max(self.firecrest.time, self.bustard.time, self.gerald.time)
+ timestamp = time.strftime('%Y-%m-%d', time.localtime(tmax))
+ self._name = 'run_'+self.flowcell_id+"_"+timestamp+'.xml'
+ return self._name
+ name = property(_get_run_name)
+
+ def save(self):
+ logging.info("Saving run report "+ self.name)
+ ElementTree.ElementTree(self.xml).write(self.name)
+