diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2011-09-22 15:03:25 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2011-09-22 15:03:25 +0200 |
commit | e7440c88368de4a9774d43d87e449fbf2709ba80 (patch) | |
tree | 5dff1ac888c0038e54b53a63cdc2e44c456235c9 /alot | |
parent | b65b54384d50b5cd8a26dacf4b81d6fd4922e9bd (diff) |
Adhere to the freedesktop basedir spec to locate the config file
This patch retains the current behavior while also looking for
the config in ~/.config/alot/config. For more details see:
http://www.freedesktop.org/wiki/Specifications/basedir-spec
Diffstat (limited to 'alot')
-rwxr-xr-x | alot/init.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/alot/init.py b/alot/init.py index 8d95fa72..77515b71 100755 --- a/alot/init.py +++ b/alot/init.py @@ -16,6 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ +import sys import argparse import logging import os @@ -30,7 +31,7 @@ from urwid.command_map import command_map def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('-c', dest='configfile', - default='~/.alot.rc', + default=None, help='alot\'s config file') parser.add_argument('-n', dest='notmuchconfigfile', default='~/.notmuch-config', @@ -61,9 +62,27 @@ def main(): # interpret cml arguments args = parse_args() - #read config file - configfilename = os.path.expanduser(args.configfile) - settings.config.read(configfilename) + #locate and read config file + configfiles = [ + os.path.join(os.environ.get('XDG_CONFIG_HOME', + os.path.expanduser('~/.config')), + 'alot', 'config'), + os.path.expanduser('~/.alot.rc'), + ] + if args.configfile: + expanded_path = os.path.expanduser(args.configfile) + if not os.path.exists(expanded_path): + sys.exit('File %s does not exist' % expanded_path) + configfiles.insert(0, expanded_path) + + found_config = False + for configfilename in configfiles: + if os.path.exists(configfilename): + settings.config.read(configfilename) + found_config = True + if not found_config: + sys.exit('No configuration file found (tried %s)' % ', '.join(configfiles)) + notmuchfile = os.path.expanduser(args.notmuchconfigfile) settings.notmuchconfig.read(notmuchfile) settings.hooks.setup(settings.config.get('general', 'hooksfile')) |