mirror of
https://github.com/certbot/certbot.git
synced 2026-04-29 18:19:51 -04:00
Minor fixes for #453 and reporter API docs.
This commit is contained in:
parent
2027110512
commit
e5dd4ba70c
4 changed files with 21 additions and 14 deletions
5
docs/api/reporter.rst
Normal file
5
docs/api/reporter.rst
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
:mod:`letsencrypt.reporter`
|
||||
---------------------------
|
||||
|
||||
.. automodule:: letsencrypt.reporter
|
||||
:members:
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue