def execute(self, runid): """Send files as an email. Keyword arguments: runid -- A UTC ID string which identifies the run. The following parameters are loaded from the Robot configuration: FileEmailer_Host e.g. localhost or localhost:25 FileEmailer_Type e.g. text or html FileEmailer_From e.g. [email protected] FileEmailer_Recipients e.g. [email protected], [email protected] FileEmailer_Subject e.g. Report ${runid}. FileEmailer_TextFile e.g. ~/gangadir/robot/report/${runid}.txt FileEmailer_HtmlFile e.g. ~/gangadir/robot/report/${runid}.html If Recipients are not specified then no email is sent. In Subject, TextFile and HtmlFile the token ${runid} is replaced by the runid argument. If Type is text, then TextFile is sent. If Type is html, then HtmlFile is sent, or if TextFile is also specified then a multipart message is sent containing TextFile and HtmlFile. """ # get configuration properties host = self.getoption('FileEmailer_Host') type = self.getoption('FileEmailer_Type') from_ = self.getoption('FileEmailer_From') # extract recipients ignoring blank entries recipients = [recipient.strip() for recipient in \ self.getoption('FileEmailer_Recipients').split(',') \ if recipient.strip()] subject = Utility.expand(self.getoption('FileEmailer_Subject'), runid = runid) textfilename = Utility.expand(self.getoption('FileEmailer_TextFile'), runid = runid) htmlfilename = Utility.expand(self.getoption('FileEmailer_HtmlFile'), runid = runid) if not recipients: logger.warn('No recipients specified. Email will not be sent.') return logger.info('Emailing files to %s.', recipients) # build message if type == 'html': msg = self._gethtmlmsg(textfilename, htmlfilename) else: msg = self._gettextmsg(textfilename) msg['Subject'] = subject msg['From'] = from_ msg['To'] = ', '.join(recipients) # send message session = SMTP() try: session.connect(host) session.sendmail(from_, recipients, msg.as_string()) session.quit() finally: session.close() logger.info('Files emailed.')
def _savereport(self, report, runid): #text textfilename = Utility.expand(self.getoption('BaseReporter_TextFile'), runid = runid) textcontent = str(report) Utility.writefile(textfilename, textcontent) #html htmlfilename = Utility.expand(self.getoption('BaseReporter_HtmlFile'), runid = runid) htmlcontent = report.tohtml() Utility.writefile(htmlfilename, htmlcontent)
def _savereport(self, report, runid): #text textfilename = Utility.expand(self.getoption('BaseReporter_TextFile'), runid=runid) textcontent = str(report) Utility.writefile(textfilename, textcontent) #html htmlfilename = Utility.expand(self.getoption('BaseReporter_HtmlFile'), runid=runid) htmlcontent = report.tohtml() Utility.writefile(htmlfilename, htmlcontent)
def handlereport(self, report, runnode): """Add statistics on generic data to the report. Keyword arguments: report -- A Report.Report for the run, to be emailed. runnode -- A the extracted data for the run. If the report title is undefined a title 'CoreReporter ${runid}' is set. If the configurable option CoreReporter_ExtractUrl is defined then a link is added from 'Run id', replacing ${runid} with the current run id. e.g. http://localhost/robot/extract/${runid}.xml Example of report generated (plain text version): CoreReporter 2007-06-27_10.49.40 ******************************** Core Analysis ************* Run id : 2007-06-27_10.49.40 (http://localhost/robot/extract/2007-06-27_10.49.40.xml) Start time : 2007/06/27 10:49:40 Extract time : 2007/06/27 10:49:55 Status | Subtotal ------------------------------- completed | 3 submitted | 1 failed | 1 Total | 5 ActualCE | Completed | Total ------------------------------------------------------------------------------- lx09.hep.ph.ic.ac.uk | 3 | 5 Non-completed Jobs ================== Id | Status | Backend | Backend.id | ActualCE ------------------------------------------------------------------------------- 51 | failed | Local | 13418 | lx09.hep.ph.ic.ac.uk 53 | submitted | Local | None | lx09.hep.ph.ic.ac.uk """ runid = runnode.getvalue('core.id') # get configuration options extracturl = Utility.expand(self.getoption('CoreReporter_ExtractUrl'), runid=runid) #CoreReporter id if not report.title: report.title = 'CoreReporter ' + runid #Core Analysis report.addline(Heading('Core Analysis', 2)) report.addline() #Run id : ... report.addline('Run id :') if extracturl: report.addelement(Link(runid, extracturl)) else: report.addelement(runid) #Start time : ... #Extract time : ... report.addline('Start time : ' + runnode.getvalue('core.start-time')) report.addline('Extract time : ' + runnode.getvalue('core.extract-time')) report.addline() #Status | Subtotal #... #Total 10 report.addline(self._getstatustable(runnode)) report.addline() #ActualCE | Completed | Total #... report.addline(self._getcetable(runnode)) report.addline() #Non-completed Jobs report.addline(Heading('Non-completed Jobs')) #Id | Status | Backend | Backend.id | ActualCE #... report.addline(self._getnoncompletedtable(runnode)) report.addline()
def _loadextract(self, runid): filename = Utility.expand(self.getoption('BaseExtractor_XmlFile'), runid = runid) content = Utility.readfile(filename) return Node.fromxml(content)
def test_expand_repeated_occurrences(self): """Test expand() replaces repeated tokens in text.""" text = 'The following token ${mytoken1} should be replaced, as should ${mytoken1}.' expected = 'The following token 1111 should be replaced, as should 1111.' actual = Utility.expand(text, mytoken1 = '1111') assert expected == actual, 'the text was not modified as expected'
def test_expand_multiple_occurrences(self): """Test expand() replaces multiple tokens in text.""" text = 'The following token ${mytoken1} should be replaced, as should ${mytoken2}.' expected = 'The following token 1111 should be replaced, as should 2222.' actual = Utility.expand(text, mytoken1 = '1111', mytoken2 = '2222') assert expected == actual, 'the text was not modified as expected'
def test_expand_no_replacements(self): """Test expand() does not replace tokens in text when no replacements parameter.""" text = 'The following token ${runid} should not be replaced.' expected = text actual = Utility.expand(text) assert expected == actual, 'the text was modified'
def execute(self, runid): """Send files as an email. Keyword arguments: runid -- A UTC ID string which identifies the run. The following parameters are loaded from the Robot configuration: FileEmailer_Host e.g. localhost or localhost:25 FileEmailer_Type e.g. text or html FileEmailer_From e.g. [email protected] FileEmailer_Recipients e.g. [email protected], [email protected] FileEmailer_Subject e.g. Report ${runid}. FileEmailer_TextFile e.g. ~/gangadir/robot/report/${runid}.txt FileEmailer_HtmlFile e.g. ~/gangadir/robot/report/${runid}.html If Recipients are not specified then no email is sent. In Subject, TextFile and HtmlFile the token ${runid} is replaced by the runid argument. If Type is text, then TextFile is sent. If Type is html, then HtmlFile is sent, or if TextFile is also specified then a multipart message is sent containing TextFile and HtmlFile. """ # get configuration properties host = self.getoption('FileEmailer_Host') type = self.getoption('FileEmailer_Type') from_ = self.getoption('FileEmailer_From') # extract recipients ignoring blank entries recipients = [recipient.strip() for recipient in \ self.getoption('FileEmailer_Recipients').split(',') \ if recipient.strip()] subject = Utility.expand(self.getoption('FileEmailer_Subject'), runid=runid) textfilename = Utility.expand(self.getoption('FileEmailer_TextFile'), runid=runid) htmlfilename = Utility.expand(self.getoption('FileEmailer_HtmlFile'), runid=runid) if not recipients: logger.warn('No recipients specified. Email will not be sent.') return logger.info('Emailing files to %s.', recipients) # build message if type == 'html': msg = self._gethtmlmsg(textfilename, htmlfilename) else: msg = self._gettextmsg(textfilename) msg['Subject'] = subject msg['From'] = from_ msg['To'] = ', '.join(recipients) # send message session = SMTP() try: session.connect(host) session.sendmail(from_, recipients, msg.as_string()) session.quit() finally: session.close() logger.info('Files emailed.')
def _saveextract(self, runnode, runid): filename = Utility.expand(self.getoption('BaseExtractor_XmlFile'), runid = runid) content = runnode.toprettyxml() Utility.writefile(filename, content)
def test_expand_repeated_occurrences(self): """Test expand() replaces repeated tokens in text.""" text = 'The following token ${mytoken1} should be replaced, as should ${mytoken1}.' expected = 'The following token 1111 should be replaced, as should 1111.' actual = Utility.expand(text, mytoken1='1111') assert expected == actual, 'the text was not modified as expected'
def test_expand_multiple_occurrences(self): """Test expand() replaces multiple tokens in text.""" text = 'The following token ${mytoken1} should be replaced, as should ${mytoken2}.' expected = 'The following token 1111 should be replaced, as should 2222.' actual = Utility.expand(text, mytoken1='1111', mytoken2='2222') assert expected == actual, 'the text was not modified as expected'
def _loadextract(self, runid): filename = Utility.expand(self.getoption('BaseExtractor_XmlFile'), runid=runid) content = Utility.readfile(filename) return Node.fromxml(content)
def handlereport(self, report, runnode): """Add statistics on generic data to the report. Keyword arguments: report -- A Report.Report for the run, to be emailed. runnode -- A the extracted data for the run. If the report title is undefined a title 'CoreReporter ${runid}' is set. If the configurable option CoreReporter_ExtractUrl is defined then a link is added from 'Run id', replacing ${runid} with the current run id. e.g. http://localhost/robot/extract/${runid}.xml Example of report generated (plain text version): CoreReporter 2007-06-27_10.49.40 ******************************** Core Analysis ************* Run id : 2007-06-27_10.49.40 (http://localhost/robot/extract/2007-06-27_10.49.40.xml) Start time : 2007/06/27 10:49:40 Extract time : 2007/06/27 10:49:55 Status | Subtotal ------------------------------- completed | 3 submitted | 1 failed | 1 Total | 5 ActualCE | Completed | Total ------------------------------------------------------------------------------- lx09.hep.ph.ic.ac.uk | 3 | 5 Non-completed Jobs ================== Id | Status | Backend | Backend.id | ActualCE ------------------------------------------------------------------------------- 51 | failed | Local | 13418 | lx09.hep.ph.ic.ac.uk 53 | submitted | Local | None | lx09.hep.ph.ic.ac.uk """ runid = runnode.getvalue('core.id') # get configuration options extracturl = Utility.expand(self.getoption('CoreReporter_ExtractUrl'), runid = runid) #CoreReporter id if not report.title: report.title = 'CoreReporter ' + runid #Core Analysis report.addline(Heading('Core Analysis', 2)) report.addline() #Run id : ... report.addline('Run id :') if extracturl: report.addelement(Link(runid, extracturl)) else: report.addelement(runid) #Start time : ... #Extract time : ... report.addline('Start time : ' + runnode.getvalue('core.start-time')) report.addline('Extract time : ' + runnode.getvalue('core.extract-time')) report.addline() #Status | Subtotal #... #Total 10 report.addline(self._getstatustable(runnode)) report.addline() #ActualCE | Completed | Total #... report.addline(self._getcetable(runnode)) report.addline() #Non-completed Jobs report.addline(Heading('Non-completed Jobs')) #Id | Status | Backend | Backend.id | ActualCE #... report.addline(self._getnoncompletedtable(runnode)) report.addline()