diff options
Diffstat (limited to 'alot')
-rw-r--r-- | alot/commands/envelope.py | 8 | ||||
-rw-r--r-- | alot/commands/globals.py | 28 | ||||
-rw-r--r-- | alot/commands/search.py | 10 | ||||
-rw-r--r-- | alot/commands/thread.py | 10 | ||||
-rwxr-xr-x | alot/init.py | 15 | ||||
-rw-r--r-- | alot/ui.py | 42 |
6 files changed, 52 insertions, 61 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index da652468..0c2a9e14 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -180,7 +180,7 @@ class EditCommand(Command): if '*' in blacklist: blacklist = set(self.envelope.headers.keys()) self.edit_headers = edit_headers - blacklist - ui.logger.info('editable headers: %s' % blacklist) + logging.info('editable headers: %s' % blacklist) def openEnvelopeFromTmpfile(): # This parses the input from the tempfile. @@ -199,8 +199,7 @@ class EditCommand(Command): translate = settings.config.get_hook('post_edit_translate') if translate: template = translate(template, ui=ui, dbm=ui.dbman, - aman=ui.accountman, log=ui.logger, - config=settings.config) + aman=ui.accountman, config=settings.config) self.envelope.parse_template(template) if self.openNew: ui.buffer_open(buffers.EnvelopeBuffer(ui, self.envelope)) @@ -228,8 +227,7 @@ class EditCommand(Command): translate = settings.config.get_hook('pre_edit_translate') if translate: bodytext = translate(bodytext, ui=ui, dbm=ui.dbman, - aman=ui.accountman, log=ui.logger, - config=settings.config) + aman=ui.accountman, config=settings.config) #write stuff to tempfile tf = tempfile.NamedTemporaryFile(delete=False) diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 99650353..2787de38 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -85,7 +85,7 @@ class PromptCommand(Command): @inlineCallbacks def apply(self, ui): - ui.logger.info('open command shell') + logging.info('open command shell') mode = ui.current_buffer.typename cmdline = yield ui.prompt(prefix=':', text=self.startwith, @@ -96,7 +96,7 @@ class PromptCommand(Command): ), history=ui.commandprompthistory, ) - ui.logger.debug('CMDLINE: %s' % cmdline) + logging.debug('CMDLINE: %s' % cmdline) # interpret and apply commandline if cmdline: @@ -162,7 +162,7 @@ class ExternalCommand(Command): else: ui.notify(data, priority='error') if self.refocus and callerbuffer in ui.buffers: - ui.logger.info('refocussing') + logging.info('refocussing') ui.buffer_focus(callerbuffer) write_fd = ui.mainloop.watch_pipe(afterwards) @@ -183,7 +183,7 @@ class ExternalCommand(Command): 'terminal_cmd'), cmd) cmd = cmd.encode('utf-8', errors='ignore') - ui.logger.info('calling external command: %s' % cmd) + logging.info('calling external command: %s' % cmd) try: if 0 == subprocess.call(shlex.split(cmd)): os.write(write_fd, 'success') @@ -261,10 +261,10 @@ class BufferCloseCommand(Command): selected = ui.current_buffer if len(ui.buffers) == 1: if settings.config.getboolean('general', 'quit_on_last_bclose'): - ui.logger.info('closing the last buffer, exiting') + logging.info('closing the last buffer, exiting') ui.apply_command(ExitCommand()) else: - ui.logger.info('not closing last remaining buffer as ' + logging.info('not closing last remaining buffer as ' 'global.quit_on_last_bclose is set to False') else: ui.buffer_close(selected) @@ -371,7 +371,7 @@ class HelpCommand(Command): self.commandname = commandname def apply(self, ui): - ui.logger.debug('HELP') + logging.debug('HELP') if self.commandname == 'bindings': # get mappings modemaps = dict(settings.config.items('%s-maps' % ui.mode)) @@ -415,7 +415,7 @@ class HelpCommand(Command): ('relative', 70)) ui.show_as_root_until_keypress(overlay, 'cancel') else: - ui.logger.debug('HELP %s' % self.commandname) + logging.debug('HELP %s' % self.commandname) parser = commands.lookup_parser(self.commandname, ui.mode) if parser: ui.notify(parser.format_help(), block=True) @@ -546,14 +546,14 @@ class ComposeCommand(Command): name, addr = email.Utils.parseaddr(self.envelope['From']) a = ui.accountman.get_account_by_address(addr) if a.signature: - ui.logger.debug('has signature') + logging.debug('has signature') sig = os.path.expanduser(a.signature) if os.path.isfile(sig): - ui.logger.debug('is file') + logging.debug('is file') if a.signature_as_attachment: name = a.signature_filename or None self.envelope.attach(sig, filename=name) - ui.logger.debug('attached') + logging.debug('attached') else: sigcontent = open(sig).read() enc = helper.guess_encoding(sigcontent) @@ -576,10 +576,10 @@ class ComposeCommand(Command): allbooks = not settings.config.getboolean('general', 'complete_matching_abook_only') - ui.logger.debug(allbooks) + logging.debug(allbooks) abooks = ui.accountman.get_addressbooks(order=[a], append_remaining=allbooks) - ui.logger.debug(abooks) + logging.debug(abooks) to = yield ui.prompt(prefix='To>', completer=ContactsCompleter(abooks)) if to == None: @@ -590,7 +590,7 @@ class ComposeCommand(Command): if settings.config.getboolean('general', 'ask_subject') and \ not 'Subject' in self.envelope.headers: subject = yield ui.prompt(prefix='Subject>') - ui.logger.debug('SUBJECT: "%s"' % subject) + logging.debug('SUBJECT: "%s"' % subject) if subject == None: ui.notify('canceled') return diff --git a/alot/commands/search.py b/alot/commands/search.py index ede8924c..c4f8ee94 100644 --- a/alot/commands/search.py +++ b/alot/commands/search.py @@ -1,6 +1,8 @@ +import argparse +import logging + from alot.commands import Command, registerCommand from alot.commands.globals import PromptCommand -import argparse from alot.db import DatabaseROError from alot import commands @@ -25,7 +27,7 @@ class OpenThreadCommand(Command): self.thread = ui.current_buffer.get_selected_thread() if self.thread: query = ui.current_buffer.querystring - ui.logger.info('open thread view for %s' % self.thread) + logging.info('open thread view for %s' % self.thread) sb = buffers.ThreadBuffer(ui, self.thread) ui.buffer_open(sb) @@ -73,7 +75,7 @@ class ToggleThreadTagCommand(Command): qs = "(%s) AND thread:%s" % (cb.querystring, self.thread.get_thread_id()) if ui.dbman.count_messages(qs) == 0: - ui.logger.debug('remove: %s' % self.thread) + logging.debug('remove: %s' % self.thread) cb.threadlist.remove(threadwidget) cb.result_count -= self.thread.get_total_messages() ui.update() @@ -166,7 +168,7 @@ class RetagCommand(Command): if not self.thread: return tags = filter(lambda x: x, self.tagsstring.split(',')) - ui.logger.info("got %s:%s" % (self.tagsstring, tags)) + logging.info("got %s:%s" % (self.tagsstring, tags)) try: self.thread.set_tags(tags) except DatabaseROError: diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 209429b4..ba841829 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -48,7 +48,7 @@ class ReplyCommand(Command): if qf: quotestring = qf(name, address, timestamp, ui=ui, dbm=ui.dbman, aman=ui.accountman, - log=ui.logger, config=settings.config) + config=settings.config) else: quotestring = 'Quoting %s (%s)\n' % (name, timestamp) mailcontent = quotestring @@ -153,7 +153,7 @@ class ForwardCommand(Command): if qf: quote = qf(name, address, timestamp, ui=ui, dbm=ui.dbman, aman=ui.accountman, - log=ui.logger, config=settings.config) + config=settings.config) else: quote = 'Forwarded message from %s (%s):\n' % (name, timestamp) mailcontent = quote @@ -285,7 +285,7 @@ class ChangeDisplaymodeCommand(Command): if self.all_headers == 'toggle': self.all_headers = not widget.show_all_headers - ui.logger.debug((self.visible, self.raw, self.all_headers)) + logging.debug((self.visible, self.raw, self.all_headers)) if self.visible is not None: widget.folded = not self.visible if self.raw is not None: @@ -381,7 +381,7 @@ class PipeCommand(Command): # do teh monkey for mail in mailstrings: - ui.logger.debug("%s" % mail) + logging.debug("%s" % mail) out, err, retval = helper.call_cmd(self.cmdlist, stdin=mail) if err: ui.notify(err, priority='error') @@ -430,7 +430,7 @@ class RemoveCommand(Command): except DatabaseError, e: err_msg = str(e) ui.notify(err_msg, priority='error') - ui.logger.debug(err_msg) + logging.debug(err_msg) return # notify diff --git a/alot/init.py b/alot/init.py index 34d3810a..d9405078 100755 --- a/alot/init.py +++ b/alot/init.py @@ -137,15 +137,11 @@ def main(): # setup logging numeric_loglevel = getattr(logging, args['debug-level'].upper(), None) logfilename = os.path.expanduser(args['logfile']) - logging.basicConfig(level=numeric_loglevel, filename=logfilename) - log_formatter = logging.Formatter('%(levelname)s:%(message)s') - log_handler = logging.FileHandler(logfilename, encoding='utf-8') - log_handler.setFormatter(log_formatter) - logger = logging.getLogger() - logger.setLevel(numeric_loglevel) - logger.addHandler(log_handler) - - #logger.debug(commands.COMMANDS) + logformat = '%(levelname)s:%(module)s:%(message)s' + logging.basicConfig(level=numeric_loglevel, filename=logfilename, + format=logformat) + + #logging.debug(commands.COMMANDS) # get ourselves a database manager dbman = DBManager(path=args['mailindex-path'], ro=args['read-only']) @@ -171,7 +167,6 @@ def main(): # set up and start interface UI(dbman, - logger, aman, cmd, args['colour-mode'], @@ -1,4 +1,5 @@ import urwid +import logging from twisted.internet import reactor, defer from twisted.python.failure import Failure @@ -70,15 +71,12 @@ class UI(object): """points to currently active :class:`~alot.buffers.Buffer`""" dbman = None """Database manager (:class:`~alot.db.DBManager`)""" - logger = None - """:class:`logging.Logger` used to write to log file""" accountman = None """account manager (:class:`~alot.account.AccountManager`)""" - def __init__(self, dbman, log, accountman, initialcmd, colourmode): + def __init__(self, dbman, accountman, initialcmd, colourmode): """ :param dbman: :class:`~alot.db.DBManager` - :param log: :class:`logging.Logger` :param accountman: :class:`~alot.account.AccountManager` :param initialcmd: commandline applied after setting up interface :type initialcmd: str @@ -86,12 +84,11 @@ class UI(object): :type colourmode: int in [1,16,256] """ self.dbman = dbman - self.logger = log self.accountman = accountman if not colourmode: colourmode = config.getint('general', 'colourmode') - self.logger.info('setup gui in %d colours' % colourmode) + logging.info('setup gui in %d colours' % colourmode) self.mainframe = urwid.Frame(urwid.SolidFill()) self.inputwrap = InputWrap(self, self.mainframe) self.mainloop = urwid.MainLoop(self.inputwrap, @@ -106,13 +103,13 @@ class UI(object): self.mode = 'global' self.commandprompthistory = [] - self.logger.debug('fire first command') + logging.debug('fire first command') self.apply_command(initialcmd) self.mainloop.run() def unhandeled_input(self, key): """called if a keypress is not handled.""" - self.logger.debug('unhandled input: %s' % key) + logging.debug('unhandled input: %s' % key) def keypress(self, key): """relay all keypresses to our `InputWrap`""" @@ -124,9 +121,9 @@ class UI(object): self.inputwrap.set_root(self.mainframe) self.inputwrap.select_cancel_only = False if callable(afterwards): - self.logger.debug('called') + logging.debug('called') afterwards() - self.logger.debug('relay: %s' % relay_rest) + logging.debug('relay: %s' % relay_rest) helpwrap = widgets.CatchKeyWidgetWrap(w, key, on_catch=oe, relay_rest=relay_rest) self.inputwrap.set_root(helpwrap) @@ -206,9 +203,9 @@ class UI(object): buffers = self.buffers if buf not in buffers: string = 'tried to close unknown buffer: %s. \n\ni have:%s' - self.logger.error(string % (buf, self.buffers)) + logging.error(string % (buf, self.buffers)) elif self.current_buffer == buf: - self.logger.debug('UI: closing current buffer %s' % buf) + logging.debug('UI: closing current buffer %s' % buf) index = buffers.index(buf) buffers.remove(buf) offset = config.getint('general', 'bufferclose_focus_offset') @@ -217,14 +214,14 @@ class UI(object): buf.cleanup() else: string = 'closing buffer %d:%s' - self.logger.debug(string % (buffers.index(buf), buf)) + logging.debug(string % (buffers.index(buf), buf)) buffers.remove(buf) buf.cleanup() def buffer_focus(self, buf): """focus given :class:`~alot.buffers.Buffer`.""" if buf not in self.buffers: - self.logger.error('tried to focus unknown buffer') + logging.error('tried to focus unknown buffer') else: if self.current_buffer != buf: self.current_buffer = buf @@ -437,34 +434,33 @@ class UI(object): if cmd: # call pre- hook if cmd.prehook: - self.logger.debug('calling pre-hook') + logging.debug('calling pre-hook') try: cmd.prehook(ui=self, dbm=self.dbman, aman=self.accountman, - log=self.logger, config=config) + config=config) except: - self.logger.exception('prehook failed') + logging.exception('prehook failed') # define (callback) function that invokes post-hook def call_posthook(retval_from_apply): if cmd.posthook: - self.logger.debug('calling post-hook') + logging.debug('calling post-hook') try: cmd.posthook(ui=self, dbm=self.dbman, - aman=self.accountman, log=self.logger, - config=config) + aman=self.accountman, config=config) except: - self.logger.exception('posthook failed') + logging.exception('posthook failed') # define error handler for Failures/Exceptions # raised in cmd.apply() def errorHandler(failure): - self.logger.debug(failure.getTraceback()) + logging.debug(failure.getTraceback()) msg = "Error: %s,\ncheck the log for details" self.notify(msg % failure.getErrorMessage(), priority='error') # call cmd.apply - self.logger.debug('apply command: %s' % cmd) + logging.debug('apply command: %s' % cmd) try: retval = cmd.apply(self) # if we deal with a InlineCallbacks-decorated method, it |