summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2011-12-15 14:31:52 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2011-12-16 22:14:48 +0000
commit0ef8d5263c7dcd0434f8141ef89f8b9b6a96117f (patch)
tree8c2374c94617f70ba3d5609ee6c993c03bbf9474
parent9afecc45f0ff3e68e751a10f3f6485776b780f4d (diff)
gracefully exit if config parsing fails
issue #152
-rwxr-xr-xalot/init.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/alot/init.py b/alot/init.py
index 362fb49c..b0a84777 100755
--- a/alot/init.py
+++ b/alot/init.py
@@ -5,6 +5,7 @@ import logging
import os
import settings
+import ConfigParser
from account import AccountManager
from db import DBManager
from ui import UI
@@ -50,7 +51,7 @@ def main():
# interpret cml arguments
args = parse_args()
- # locate and read config file
+ # locate alot config files
configfiles = [
os.path.join(os.environ.get('XDG_CONFIG_HOME',
os.path.expanduser('~/.config')),
@@ -63,14 +64,21 @@ def main():
sys.exit('File %s does not exist' % expanded_path)
configfiles.insert(0, expanded_path)
- for configfilename in configfiles:
- if os.path.exists(configfilename):
- settings.config.read(configfilename)
- break # use only the first
-
- # read notmuch config
+ # locate notmuch config
notmuchfile = os.path.expanduser(args.notmuchconfigfile)
- settings.notmuchconfig.read(notmuchfile)
+
+ try:
+ # read the first alot config file we find
+ for configfilename in configfiles:
+ if os.path.exists(configfilename):
+ settings.config.read(configfilename)
+ break # use only the first
+
+ # read notmuch config
+ settings.notmuchconfig.read(notmuchfile)
+
+ except ConfigParser.Error, e: # exit on parse errors
+ sys.exit(e)
# setup logging
numeric_loglevel = getattr(logging, args.debug_level.upper(), None)