On 2014-12-26 13:00:11, Muri Nicanor wrote: > attached is a patch that add -o or --output which allows you to save the > output to a file. > diff --git a/monkeysign/ui.py b/monkeysign/ui.py > index c9b6a30..43d15ed 100644 > --- a/monkeysign/ui.py > +++ b/monkeysign/ui.py > @@ -93,6 +93,7 @@ class MonkeysignUi(object): > help=_('do not send email at all (default: use > sendmail)')) > parser.add_option('-t', '--to', dest='to', > help=_('override destination email for testing > (default: send individually encrypted email to each uid chosen)')) > + parser.add_option('-o', '--output', dest='output', help=_('save the > output email to a file')) > return parser > > def parse_args(self, args): > @@ -381,6 +382,18 @@ expects an EmailFactory email, but will not mail if > nomail is set""" > not sending email to %s, as requested, here's the email message: > > %s""") % (msg.mailto, msg.create_mail_from_block())) > + if self.options.output is not None: > + if not os.path.exists(self.options.output): > + try: > + f = open(self.options.output, 'w'); > + f.write(str(msg.create_mail_from_block())) > + except IOError: > + self.warn(_('Error opening or writing file %s') % > self.options.output); > + else: > + f.close() > + self.warn(_('Mail has been written to %s') % > self.options.output) > + else: > + self.warn(_('Didn\'t write to %s, because file exists') > % self.options.output) > > > class EmailFactory:
Thanks for the patch, it's a great idea! Can you redo the patch with the "with" construct instead of manual exception handling? Also, I'd suggest the message "Could not write to %s: file exists" as an error message. Thanks! a. -- Le péché est né avant la vertu, comme le moteur avant le frein. - Jean-Paul Sartre -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org