diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2008-06-28 08:09:46 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2008-06-28 08:09:46 (GMT) |
commit | 56f67fe875b908197151227ff964f4dbd0b9acf0 (patch) | |
tree | 01f5e778f4526d435beff333662dddda80015fbe /scripts | |
parent | f98a8d2931bef72b46ee9a92208877930d3a2663 (diff) |
Send proper mail message. Use a type options to specity the report type.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/report.py | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/scripts/report.py b/scripts/report.py index 9a25a27..e15cc3a 100644 --- a/scripts/report.py +++ b/scripts/report.py @@ -9,9 +9,17 @@ import StringIO from jhbuild.commands import Command, register_command -def get_ticket_uri(number): +def _get_ticket_uri(number): return 'http://dev.laptop.org/ticket/' + number +def _send_mail(from_address, to_address, subject, text): + msg = 'From: %s\nTo: %s\nSubject: %s\n%s' % \ + (from_address, to_address, subject, text) + + server = smtplib.SMTP('localhost') + server.sendmail(from_address, to_address, msg) + server.quit() + class TextWriter(object): def __init__(self, out): self.out = out @@ -23,7 +31,7 @@ class TextWriter(object): def write_tickets(self, tickets): for number, summary in tickets: self.out.write(summary + '\n') - self.out.write(get_ticket_uri(number) + '\n\n') + self.out.write(_get_ticket_uri(number) + '\n\n') class ReviewsReport(object): def __init__(self, config): @@ -106,37 +114,42 @@ class cmd_report(Command): def __init__(self): Command.__init__(self, [ + make_option('-t', '--t', action='store', + dest='type', default=None, + help='specify the report type'), make_option('-s', '--sendto', action='append', dest='sendto', default=None, help='send report to the specified mail address') ]) def run(self, config, options, args): - report = None + report_types = [ 'reviews' ] - if args and args[0] == 'reviews': - report = ReviewsReport(config) - report.generate() + if options.type not in report_types: + print 'Available reports:\n' + '\n'.join(report_types) + return 1 - if report: - out = StringIO.StringIO() - report.write(TextWriter(out)) - text = out.getvalue() - out.close() + if options.type == 'reviews': + report = ReviewsReport(config) - if options.sendto: - if text: - print 'Sending to ' + ', '.join(options.sendto) + report.generate() - server = smtplib.SMTP('localhost') - from_address = 'release-team@sugarlabs.org' + out = StringIO.StringIO() + report.write(TextWriter(out)) + text = out.getvalue() + out.close() - for to_address in options.sendto: - server.sendmail(from_address, to_address, text) + if options.sendto: + if text: + print 'Sending to ' + ', '.join(options.sendto) - server.quit() - else: - print 'Empty report, do not send' + for to_address in options.sendto: + _send_mail('release-team@sugarlabs.org', to_address, + 'Reviews report', text) + else: + print 'Empty report, do not send' + else: + print text report.save() |