Merge pull request #465 from kuba/reporter-cleanup

Reporter cleanup
This commit is contained in:
schoen 2015-06-01 14:47:19 -07:00
commit 171e37894b
8 changed files with 32 additions and 19 deletions

5
docs/api/reporter.rst Normal file
View file

@ -0,0 +1,5 @@
:mod:`letsencrypt.reporter`
---------------------------
.. automodule:: letsencrypt.reporter
:members:

View file

@ -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

View file

@ -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:

View file

@ -1,4 +1,4 @@
"""Class helps construct valid ACME messages for testing."""
"""ACME utilities for testing."""
import datetime
import itertools
import os

View file

@ -1,4 +1,4 @@
"""Test the ContinuityAuthenticator dispatcher."""
"""Test for letsencrypt.continuity_auth."""
import unittest
import mock

View file

@ -1,4 +1,4 @@
"""Tests for letsencrypt/notify.py"""
"""Tests for letsencrypt.notify."""
import mock
import socket

View file

@ -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

View file

@ -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