summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--alot/command.py19
-rw-r--r--alot/db.py2
-rwxr-xr-xalot/init.py36
-rw-r--r--alot/settings.py38
-rw-r--r--alot/ui.py11
-rw-r--r--alot/widgets.py9
-rw-r--r--config/example.rc10
8 files changed, 82 insertions, 46 deletions
diff --git a/TODO b/TODO
index 1a56cc21..e4a7743c 100644
--- a/TODO
+++ b/TODO
@@ -4,8 +4,7 @@ Sending mails
loads the mail into the notmuch index and maybe refreshes open buffers accordingly
configuration
- * a config mechanism needs to be discussed/implemented. i don't think a single settings.py like in django
- is a good approach.
+ * use offlineimaps LocalEval approach to load colour palette/hooks
searchbuffer:
* unseen tag -> msg bold
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:
diff --git a/alot/db.py b/alot/db.py
index 4868d7a7..765ee986 100644
--- a/alot/db.py
+++ b/alot/db.py
@@ -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!'),
diff --git a/alot/ui.py b/alot/ui.py
index 2034c8f1..71430b4f 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -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)
diff --git a/config/example.rc b/config/example.rc
new file mode 100644
index 00000000..7eef658c
--- /dev/null
+++ b/config/example.rc
@@ -0,0 +1,10 @@
+[general]
+colourpalette = palette.py
+hooks = hooks.py
+editor_cmd = /usr/bin/vim -f -c 'set filetype=mail'
+pager_cmd = /usr/bin/view -f -c 'set filetype=mail'
+terminal_cmd = /usr/bin/urxvt -T notmuch -e
+spawn_editor = True
+spawn_pager = True
+authors_maxlength = 30
+displayed_headers = 'From,To,Cc,Bcc,Subject'