diff options
Diffstat (limited to 'alot')
-rw-r--r-- | alot/command.py | 19 | ||||
-rw-r--r-- | alot/db.py | 2 | ||||
-rwxr-xr-x | alot/init.py | 36 | ||||
-rw-r--r-- | alot/settings.py | 38 | ||||
-rw-r--r-- | alot/ui.py | 11 | ||||
-rw-r--r-- | alot/widgets.py | 9 |
6 files changed, 71 insertions, 44 deletions
diff --git a/alot/command.py b/alot/command.py index 18131893..86e8cc9a 100644 --- a/alot/command.py +++ b/alot/command.py @@ -24,7 +24,7 @@ import subprocess import buffer import hooks -import settings +from settings import config import completion @@ -109,13 +109,14 @@ class EditCommand(Command): """ def __init__(self, path, spawn=False, **kwargs): self.path = path - self.spawn = settings.spawn_editor or spawn + self.spawn = config.get('general', 'spawn_pager') or spawn Command.__init__(self, **kwargs) def apply(self, ui): def afterwards(): ui.logger.info('Editor was closed') - cmd = ExternalCommand(settings.editor_cmd % self.path, + editor_cmd = config.get('general', 'editor_cmd') + cmd = ExternalCommand(editor_cmd + ' ' +self.path, spawn=self.spawn, onExit=afterwards) ui.apply_command(cmd) @@ -126,13 +127,14 @@ class PagerCommand(Command): def __init__(self, path, spawn=False, **kwargs): self.path = path - self.spawn = settings.spawn_pager or spawn + self.spawn = config.get('general', 'spawn_pager') or spawn Command.__init__(self, **kwargs) def apply(self, ui): def afterwards(): ui.logger.info('pager was closed') - cmd = ExternalCommand(settings.pager_cmd % self.path, + pager_cmd = config.get('general', 'pager_cmd') + cmd = ExternalCommand(pager_cmd + ' ' + self.path, spawn=self.spawn, onExit=afterwards) ui.apply_command(cmd) @@ -140,6 +142,7 @@ class PagerCommand(Command): class ExternalCommand(Command): """calls external command""" + # TODO: separate spawn from fork def __init__(self, commandstring, spawn=False, refocus=True, onExit=None, **kwargs): self.commandstring = commandstring @@ -151,18 +154,18 @@ class ExternalCommand(Command): def apply(self, ui): def call(onExit, popenArgs): callerbuffer = ui.current_buffer - ui.logger.info('CALLERBUFFER: %s' % callerbuffer) proc = subprocess.Popen(*popenArgs, shell=True) proc.wait() if callable(onExit): onExit() if self.refocus and callerbuffer in ui.buffers: - ui.logger.info('TRY TO REFOCUS: %s' % callerbuffer) + ui.logger.info('trying to refocus after external command: %s' % callerbuffer) ui.buffer_focus(callerbuffer) return if self.spawn: - cmd = settings.terminal_cmd % self.commandstring + cmd = config.get('general', 'terminal_cmd') + ' ' + self.commandstring + ui.logger.info('calling external command: %s' % cmd) thread = threading.Thread(target=call, args=(self.onExit, (cmd,))) thread.start() else: @@ -148,7 +148,7 @@ class Thread: return self.subject def _build_messages(self, acc, msg): - M = Message(self.dbman,msg) + M = Message(self.dbman, msg) acc[M] = {} r = msg.get_replies() if r is not None: diff --git a/alot/init.py b/alot/init.py index fcf42c2d..775c6a6d 100755 --- a/alot/init.py +++ b/alot/init.py @@ -18,14 +18,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. """ import argparse import logging +import os -from alot.db import DBManager -from alot.ui import UI +from db import DBManager +from ui import UI +import settings def parse_args(): parser = argparse.ArgumentParser() - parser.add_argument('-c', dest='colours', + parser.add_argument('-c', dest='configfile', + default='~/.alot.rc', + help='config file') + parser.add_argument('-C', dest='colours', type=int, choices=[1, 16, 88, 256], default=16, @@ -49,15 +54,26 @@ def parse_args(): def main(): + # interpret cml arguments args = parse_args() - dbman = DBManager(path=args.db_path, ro=args.read_only) - numeric_level = getattr(logging, args.debug_level.upper(), None) - logging.basicConfig(level=numeric_level, filename=args.logfile) + + #read config file + configfilename = os.path.expanduser(args.configfile) + settings.setup(configfilename) + + + # setup logging + numeric_loglevel = getattr(logging, args.debug_level.upper(), None) + logging.basicConfig(level=numeric_loglevel, filename=args.logfile) logger = logging.getLogger() - ui = UI(db=dbman, - log=logger, - initialquery=args.query, - colourmode=args.colours, + + # get ourselves a database manager + dbman = DBManager(path=args.db_path, ro=args.read_only) + # setup and start interface + ui = UI(dbman, + logger, + args.query, + args.colours, ) if __name__ == "__main__": diff --git a/alot/settings.py b/alot/settings.py index 39ab748d..cb16a298 100644 --- a/alot/settings.py +++ b/alot/settings.py @@ -16,11 +16,29 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>. Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com> """ -editor_cmd = "/usr/bin/vim -f -c 'set filetype=mail' %s" -pager_cmd = "/usr/bin/view -f -c 'set filetype=mail' %s" -terminal_cmd = 'urxvt -T notmuch -e %s' -spawn_editor = True -spawn_pager = True +from ConfigParser import SafeConfigParser + + +class ListConfigParser(SafeConfigParser): + def getstringlist(self, section, option, **kwargs): + value = SafeConfigParser.get(self, section, option, **kwargs) + return [s.strip() for s in value.split(',')] + +DEFAULTS = { + 'editor_cmd': "/usr/bin/vim -f -c 'set filetype=mail' ", + 'pager_cmd': "/usr/bin/view -f -c 'set filetype=mail' ", + 'terminal_cmd': 'urxvt -T notmuch -e', + 'spawn_editor': 'True', + 'spawn_pager': 'True', + 'displayed_headers': 'From,To,Cc,Bcc,Subject', + 'authors_maxlength': '30', +} + +config = ListConfigParser(DEFAULTS) +config.add_section('general') + +def setup(configfilename): + config.read(configfilename) # colour palette. # id, fg16, bg16, mono, fg256, bg256 @@ -58,16 +76,6 @@ palette = [ ('taglist_tag', 'light gray', 'black', '', '', ''), ('taglist_focus', 'white', 'dark gray', '', '#ffa', 'g38'), ] -displayed_headers = [ - 'From', - 'To', - 'Cc', - 'Bcc', - 'Subject', -] - -authors_maxlength = 30 - hooks = { 'pre-shutdown': lambda ui: ui.logger.info('goodbye!'), @@ -18,10 +18,11 @@ Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com> """ import urwid -import settings -from alot import command -from alot.widgets import PromptWidget -from alot.buffer import BufferListBuffer +from settings import config +from settings import palette +import command +from widgets import PromptWidget +from buffer import BufferListBuffer class UI: @@ -35,7 +36,7 @@ class UI: self.logger.debug('setup gui: %d' % colourmode) self.mainframe = urwid.Frame(urwid.SolidFill(' ')) self.mainloop = urwid.MainLoop(self.mainframe, - settings.palette, + palette, handle_mouse=False, unhandled_input=self.keypress) self.mainloop.screen.set_terminal_properties(colors=colourmode) diff --git a/alot/widgets.py b/alot/widgets.py index 65af5433..4d73123f 100644 --- a/alot/widgets.py +++ b/alot/widgets.py @@ -27,9 +27,8 @@ from urwid import WidgetWrap from urwid import ListBox from urwid import SimpleListWalker from datetime import datetime -import logging -import settings +from settings import config from helper import shorten from helper import pretty_datetime @@ -58,7 +57,8 @@ class ThreadlineWidget(AttrMap): cols.append(('fixed', len(tagsstring), self.tags_w)) authors = self.thread.get_authors() or '(None)' - authorsstring = shorten(authors, settings.authors_maxlength) + maxlength = config.getint('general', 'authors_maxlength') + authorsstring = shorten(authors, maxlength) self.authors_w = AttrMap(Text(authorsstring), 'threadline_authors') cols.append(('fixed', len(authorsstring), self.authors_w)) @@ -255,7 +255,6 @@ class MessageWidget(WidgetWrap): def _get_spacer(self, bars_at): prefixchars = [] - logging.info(bars_at) length = len(bars_at) for b in bars_at: if b: @@ -332,7 +331,7 @@ class MessageHeaderWidget(AttrMap): def __init__(self, eml): self.eml = eml headerlines = [] - for line in settings.displayed_headers: + for line in config.getstringlist('general', 'displayed_headers'): if line in eml: headerlines.append('%s:%s' % (line, eml.get(line))) headertxt = '\n'.join(headerlines) |