Minor fixes for #453 and reporter API docs.

This commit is contained in:
Jakub Warmuz 2015-06-01 19:06:15 +00:00
parent 2027110512
commit e5dd4ba70c
No known key found for this signature in database
GPG key ID: 2A7BAD3A489B52EA
4 changed files with 21 additions and 14 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,16 @@ 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)
_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 +31,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 +56,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,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