|
|
|
@ -20,11 +20,14 @@
|
|
|
|
|
import textwrap |
|
|
|
|
import locale |
|
|
|
|
import getpass |
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
from mitterlib.network.networkbase import NetworkData |
|
|
|
|
|
|
|
|
|
from timesince import timesince |
|
|
|
|
|
|
|
|
|
_log = logging.getLogger('mitterlib.ui.helpers.console_utils') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def encode_print(text): |
|
|
|
|
"""Try to print the text; if we get any UnicodeEncodeError, we print it |
|
|
|
@ -143,3 +146,44 @@ def authorization(options, config):
|
|
|
|
|
if value: |
|
|
|
|
config[namespace][name] = value |
|
|
|
|
print |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _thread(thread_list, connection, message_id, network): |
|
|
|
|
"""Build a conversation thread.""" |
|
|
|
|
_log.debug('Requesting message %s.%s' % (message_id, network)) |
|
|
|
|
try: |
|
|
|
|
message = connection.message(message_id, network) |
|
|
|
|
except NetworkError, exc: |
|
|
|
|
_log.debug('Network error:') |
|
|
|
|
_log.debug(exc) |
|
|
|
|
thread_list.insert(0, 'Network error') |
|
|
|
|
return thread_list |
|
|
|
|
# TODO: Catch a permission denied exception and add a proper message |
|
|
|
|
# for it. |
|
|
|
|
|
|
|
|
|
thread_list.insert(0, message) |
|
|
|
|
if message.parent: |
|
|
|
|
_log.debug('Following parent %s', message.parent) |
|
|
|
|
_thread(thread_list, connection, message.parent, network) |
|
|
|
|
return thread_list |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_thread(initial_message, connection): |
|
|
|
|
"""Retrieves a conversation thread, when possible. Returns a list of |
|
|
|
|
:obj:`NetworkData` objects, with the initial_message as the last element |
|
|
|
|
(so parents are in the top of the list.)""" |
|
|
|
|
|
|
|
|
|
thread = [initial_message] |
|
|
|
|
return _thread(thread, connection, initial_message.parent, |
|
|
|
|
initial_message.network) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def print_thread(thread_list, connection): |
|
|
|
|
"""Given a thread created by :func:`fetch_thread`, display the data using |
|
|
|
|
the default console functions.""" |
|
|
|
|
pos = 0 |
|
|
|
|
_log.debug('%d messages in thread', len(thread_list)) |
|
|
|
|
for message in thread_list: |
|
|
|
|
print_messages(message, connection, show_numbers=False, indent=pos) |
|
|
|
|
pos += 1 |
|
|
|
|
return |
|
|
|
|