Example #1
-1
def _send_output_by_mail_if_necessary(mail_sender, email_subject, output):
    """Returns True if an e-mail was sent.
    @param mail_sender: Instance of impl.mail.MailSender.
    @param output: Dependency. Inject an instance of impl.output.Output.
    """
    if output.echoed.count("\n") <= 1:
        return False
    email_content = output.echoed + "\nSent from %s.\n" % (os.uname()[1])
    mail_sender.send_email(email_subject, email_content)
    output.echo("Sent by e-mail to %s" % ", ".join(mail_sender.dest))
    return True
Example #2
-1
def main():
    mail_sender = impl.mail.MailSender()
    output = impl.output.Output(_print)
    cli = Cli(sys.argv[1:], mail_sender, output)
    try:
        cli.run()
    except Exception as e:
        error_msg = "Oops, an error occured.\n" + "\n".join(unicode(i) for i in e.args) + "\n\n"
        error_msg += traceback.format_exc()
        try:
            output.echo(error_msg)
            if cli.errorto is not None:
                mail_sender.dest.add(cli.errorto)
            if len(mail_sender.dest):
                _send_output_by_mail_if_necessary(mail_sender, "error.", output)
        except:
            _print(error_msg)
        raise