diff --git a/afew/Settings.py b/afew/Settings.py index 44d6f3c..89a52b5 100644 --- a/afew/Settings.py +++ b/afew/Settings.py @@ -9,17 +9,14 @@ from afew.configparser import ConfigParser from afew.FilterRegistry import all_filters -user_config_dir = os.path.join(os.environ.get('XDG_CONFIG_HOME', - os.path.expanduser('~/.config')), - 'afew') -user_config_dir = os.path.expandvars(user_config_dir) +user_config_dir = None +settings = None -settings = ConfigParser() -# preserve the capitalization of the keys. -settings.optionxform = str -settings.readfp(open(os.path.join(os.path.dirname(__file__), 'defaults', 'afew.config'))) -settings.read(os.path.join(user_config_dir, 'config')) +default_user_config_dir = os.path.join(os.environ.get('XDG_CONFIG_HOME', + os.path.expanduser('~/.config')), + 'afew') +default_user_config_dir = os.path.expandvars(default_user_config_dir) # All the values for keys listed here are interpreted as ;-delimited lists value_is_a_list = ['tags', 'tags_blacklist'] @@ -28,6 +25,21 @@ section_re = re.compile(r'^(?P[a-z_][a-z0-9_]*)(\((?P[a-z_][a-z0-9_]*)\)|\.(?P\d+))?$', re.I) +def parse_settings(argument_user_config_dir = None): + global user_config_dir, settings + + if not argument_user_config_dir: + argument_user_config_dir = default_user_config_dir + user_config_dir = argument_user_config_dir + + settings = ConfigParser() + # preserve the capitalization of the keys. + settings.optionxform = str + + settings.readfp(open(os.path.join(os.path.dirname(__file__), 'defaults', 'afew.config'))) + settings.read(os.path.join(user_config_dir, 'config')) + + def get_filter_chain(database): filter_chain = [] diff --git a/afew/commands.py b/afew/commands.py index 6048592..12caf23 100644 --- a/afew/commands.py +++ b/afew/commands.py @@ -9,8 +9,9 @@ from afew.Database import Database from afew.main import main as inner_main from afew.FilterRegistry import all_filters -from afew.Settings import user_config_dir, get_filter_chain, \ - get_mail_move_rules, get_mail_move_age, get_mail_move_rename +from afew.Settings import default_user_config_dir, user_config_dir, \ + parse_settings, get_filter_chain, get_mail_move_rules, \ + get_mail_move_age, get_mail_move_rename from afew.NotmuchSettings import read_notmuch_settings, get_notmuch_new_query from afew.version import version @@ -54,6 +55,10 @@ # general options options_group = parser.add_argument_group('General options') +options_group.add_argument( + '-c', '--config', default=default_user_config_dir, + help="path to directory containing afew's config [default: %(default)s]" +) # TODO: get config via notmuch api options_group.add_argument( '-C', '--notmuch-config', default=None, @@ -114,6 +119,7 @@ def main(): elif no_query_modifiers > 1: sys.exit('Please specify either --all, --new or a query string') + parse_settings(args.config) read_notmuch_settings(args.notmuch_config) if args.new: