Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make config directory configurable as argument #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions afew/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -28,6 +25,21 @@
section_re = re.compile(r'^(?P<name>[a-z_][a-z0-9_]*)(\((?P<parent_class>[a-z_][a-z0-9_]*)\)|\.(?P<index>\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 = []

Expand Down
10 changes: 8 additions & 2 deletions afew/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down