from CCP4ReportParser import *
import sys
from lxml import etree

class coot_rebuild_report(Report):
    # Specify which gui task and/or pluginscript this applies to
    TASKNAME = 'coot_rebuild'
    RUNNING = False
    def __init__(self,xmlnode=None,jobInfo={},jobStatus=None,**kw):
        Report. __init__(self,xmlnode=xmlnode,jobInfo=jobInfo,**kw)
        self.addText(text='Happily finished')
        pdbsWrittenPath = '//coot_rebuild/number_output_files'
        pdbsWrittenStringS = xmlnode.xpath(pdbsWrittenPath)
        if len(pdbsWrittenStringS) > 0:
            pdbsWrittenString = xmlnode.xpath(pdbsWrittenPath)[0].text
            self.append('<br/>')
            self.addText(text='Number of PDBs written: ' + pdbsWrittenString)
        dictsWrittenPath = '//coot_rebuild/number_output_dicts'
        dictsWrittenStringS = xmlnode.xpath(dictsWrittenPath)
        if len(dictsWrittenStringS) > 0:
            dictsWrittenString = xmlnode.xpath(dictsWrittenPath)[0].text
            self.append('<br/>')
            self.addText(text='Number of DICTs written: ' + dictsWrittenString)
        self.drawWarnings()

    def drawWarnings(self, parent=None):
        if parent is None: parent = self
        warnings = self.xmlnode.xpath('//Warnings/Warning')
        warningsFolder = parent.addFold(label='Warnings', initiallyOpen=True)
        if len(warnings)>0:
            for warning in warnings:
                warningsFolder.addText(text=warning.text,style='color:red;')
                warningsFolder.append('<br/>')
        else:
            warningsFolder.addText(text='No warnings from coot_rebuild')
        return
