From 814ab083bde51c17e3fe445d4f3cb68939b77f71 Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Tue, 2 Jun 2015 11:16:24 -0700 Subject: [PATCH] Added account registration message and fixed double output --- letsencrypt/cli.py | 2 +- letsencrypt/client.py | 9 +++++++++ letsencrypt/reporter.py | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/letsencrypt/cli.py b/letsencrypt/cli.py index 169b55aff..798a816af 100644 --- a/letsencrypt/cli.py +++ b/letsencrypt/cli.py @@ -377,7 +377,7 @@ def main(args=sys.argv[1:]): # Reporter report = reporter.Reporter() zope.component.provideUtility(report) - atexit.register(report.print_messages) + atexit.register(report.atexit_print_messages) # Logging level = -args.verbose_count * 10 diff --git a/letsencrypt/client.py b/letsencrypt/client.py index c4b8ef40c..bb0a6d01f 100644 --- a/letsencrypt/client.py +++ b/letsencrypt/client.py @@ -99,6 +99,15 @@ class Client(object): raise errors.LetsEncryptClientError("Must agree to TOS") self.account.save() + reporter = zope.component.getUtility(interfaces.IReporter) + reporter.add_message( + "Your account credentials have been saved in your Let's Encrypt " + "configuration directory at {0}. You should make a secure backup " + "of this folder now. This configuration directory will also " + "contain certificates and private keys obtained by Let's Encrypt " + "so making regular backups of this folder is ideal.".format( + self.config.config_dir), + reporter.HIGH_PRIORITY, True) def obtain_certificate(self, domains, csr=None): """Obtains a certificate from the ACME server. diff --git a/letsencrypt/reporter.py b/letsencrypt/reporter.py index 7dfacaf14..947643d48 100644 --- a/letsencrypt/reporter.py +++ b/letsencrypt/reporter.py @@ -1,5 +1,7 @@ """Collects and displays information to the user.""" import collections +import logging +import os import Queue import sys import textwrap @@ -46,6 +48,16 @@ class Reporter(object): """ assert self.HIGH_PRIORITY <= priority <= self.LOW_PRIORITY self.messages.put(self._msg_type(priority, msg, on_crash)) + logging.info("Reporting to user: %s", msg) + + def atexit_print_messages(self, pid=os.getpid()): + """Function to be registered with atexit to print messages. + + :param int pid: Process ID + + """ + if pid == os.getpid(): + self.print_messages() def print_messages(self): """Prints messages to the user and clears the message queue. @@ -59,7 +71,7 @@ class Reporter(object): no_exception = sys.exc_info()[0] is None bold_on = sys.stdout.isatty() if bold_on: - sys.stdout.write(self._BOLD) + print self._BOLD print 'IMPORTANT NOTES:' wrapper = textwrap.TextWrapper(initial_indent=' - ', subsequent_indent=(' ' * 3))