diff --git a/docs/api/reporter.rst b/docs/api/reporter.rst new file mode 100644 index 000000000..03260f9cd --- /dev/null +++ b/docs/api/reporter.rst @@ -0,0 +1,5 @@ +:mod:`letsencrypt.reporter` +--------------------------- + +.. automodule:: letsencrypt.reporter + :members: diff --git a/letsencrypt/cli.py b/letsencrypt/cli.py index 59e99648d..70a0d82ee 100644 --- a/letsencrypt/cli.py +++ b/letsencrypt/cli.py @@ -1,7 +1,7 @@ """Let's Encrypt CLI.""" # TODO: Sanity check all input. Be sure to avoid shell code etc... -import atexit import argparse +import atexit import logging import os import sys diff --git a/letsencrypt/reporter.py b/letsencrypt/reporter.py index 26269e3f8..7dfacaf14 100644 --- a/letsencrypt/reporter.py +++ b/letsencrypt/reporter.py @@ -12,16 +12,22 @@ from letsencrypt import interfaces class Reporter(object): """Collects and displays information to the user. - :ivar `Queue.PriorityQueue` messages: Messages to be displayed to the user. + :ivar `Queue.PriorityQueue` messages: Messages to be displayed to + the user. """ - zope.interface.implements(interfaces.IReporter) - HIGH_PRIORITY, MEDIUM_PRIORITY, LOW_PRIORITY = xrange(3) + HIGH_PRIORITY = 0 + """High priority constant. See `add_message`.""" + MEDIUM_PRIORITY = 1 + """Medium priority constant. See `add_message`.""" + LOW_PRIORITY = 2 + """Low priority constant. See `add_message`.""" + _RESET = '\033[0m' _BOLD = '\033[1m' - _msg_type = collections.namedtuple('Msg', 'priority, text, on_crash') + _msg_type = collections.namedtuple('ReporterMsg', 'priority text on_crash') def __init__(self): self.messages = Queue.PriorityQueue() @@ -31,21 +37,21 @@ class Reporter(object): :param str msg: Message to be displayed to the user. - :param int priority: One of HIGH_PRIORITY, MEDIUM_PRIORITY, or - LOW_PRIORITY. + :param int priority: One of `HIGH_PRIORITY`, `MEDIUM_PRIORITY`, + or `LOW_PRIORITY`. - :param bool on_crash: Whether or not the message should be printed if - the program exits abnormally. + :param bool on_crash: Whether or not the message should be + printed if the program exits abnormally. """ - assert priority >= self.HIGH_PRIORITY and priority <= self.LOW_PRIORITY + assert self.HIGH_PRIORITY <= priority <= self.LOW_PRIORITY self.messages.put(self._msg_type(priority, msg, on_crash)) def print_messages(self): """Prints messages to the user and clears the message queue. - If there is an unhandled exception, only messages for which on_crash is - True are printed. + If there is an unhandled exception, only messages for which + ``on_crash`` is ``True`` are printed. """ bold_on = False @@ -56,7 +62,7 @@ class Reporter(object): sys.stdout.write(self._BOLD) print 'IMPORTANT NOTES:' wrapper = textwrap.TextWrapper(initial_indent=' - ', - subsequent_indent=' '*3) + subsequent_indent=(' ' * 3)) while not self.messages.empty(): msg = self.messages.get() if no_exception or msg.on_crash: diff --git a/letsencrypt/tests/acme_util.py b/letsencrypt/tests/acme_util.py index 93cc35e47..48e3beba7 100644 --- a/letsencrypt/tests/acme_util.py +++ b/letsencrypt/tests/acme_util.py @@ -1,4 +1,4 @@ -"""Class helps construct valid ACME messages for testing.""" +"""ACME utilities for testing.""" import datetime import itertools import os diff --git a/letsencrypt/tests/continuity_auth_test.py b/letsencrypt/tests/continuity_auth_test.py index 1b14718fe..829af736d 100644 --- a/letsencrypt/tests/continuity_auth_test.py +++ b/letsencrypt/tests/continuity_auth_test.py @@ -1,4 +1,4 @@ -"""Test the ContinuityAuthenticator dispatcher.""" +"""Test for letsencrypt.continuity_auth.""" import unittest import mock diff --git a/letsencrypt/tests/notify_test.py b/letsencrypt/tests/notify_test.py index c6f76c42e..1ccfdbf87 100644 --- a/letsencrypt/tests/notify_test.py +++ b/letsencrypt/tests/notify_test.py @@ -1,4 +1,4 @@ -"""Tests for letsencrypt/notify.py""" +"""Tests for letsencrypt.notify.""" import mock import socket diff --git a/letsencrypt/tests/proof_of_possession_test.py b/letsencrypt/tests/proof_of_possession_test.py index b420c972c..3635b5ead 100644 --- a/letsencrypt/tests/proof_of_possession_test.py +++ b/letsencrypt/tests/proof_of_possession_test.py @@ -1,4 +1,4 @@ -"""Tests for proof_of_possession.py""" +"""Tests for letsencrypt.proof_of_possession.""" import Crypto.PublicKey.RSA import os import pkg_resources diff --git a/letsencrypt/tests/reporter_test.py b/letsencrypt/tests/reporter_test.py index df9790256..e6a8c9005 100644 --- a/letsencrypt/tests/reporter_test.py +++ b/letsencrypt/tests/reporter_test.py @@ -1,10 +1,12 @@ -"""Tests for letsencrypt/reporter.py""" +"""Tests for letsencrypt.reporter.""" import StringIO import sys import unittest class ReporterTest(unittest.TestCase): + """Tests for letsencrypt.reporter.Reporter.""" + def setUp(self): from letsencrypt import reporter self.reporter = reporter.Reporter() @@ -70,4 +72,4 @@ class ReporterTest(unittest.TestCase): if __name__ == "__main__": - unittest.main() # pragma: no cover + unittest.main() # pragma: no cover