diff options
author | mathieui <mathieui@mathieui.net> | 2015-02-21 23:16:52 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2015-02-21 23:16:52 +0100 |
commit | 1209bd94b60cb85c756d937ad9cada69f2428397 (patch) | |
tree | 6e215b9f53aa8d37e141844f72513daf340d9b22 /src | |
parent | 96e97962bc64fe8a53c02f7f0bd787cee5c3fc5f (diff) | |
download | poezio-1209bd94b60cb85c756d937ad9cada69f2428397.tar.gz poezio-1209bd94b60cb85c756d937ad9cada69f2428397.tar.bz2 poezio-1209bd94b60cb85c756d937ad9cada69f2428397.tar.xz poezio-1209bd94b60cb85c756d937ad9cada69f2428397.zip |
Add a -c/--check-config option to check the config file
It displays the missing options and the ones which are changed
from the default values.
Diffstat (limited to 'src')
-rw-r--r-- | src/args.py | 11 | ||||
-rw-r--r-- | src/config.py | 28 | ||||
-rw-r--r-- | src/poezio.py | 4 |
3 files changed, 39 insertions, 4 deletions
diff --git a/src/args.py b/src/args.py index 637d3158..a67a0142 100644 --- a/src/args.py +++ b/src/args.py @@ -11,14 +11,17 @@ def parse_args(CONFIG_PATH=''): """ Parse the arguments from the command line """ - parser = ArgumentParser() + parser = ArgumentParser('poezio') + parser.add_argument("-c", "--check-config", dest="check_config", + action='store_true', + help=_('Check the config file')) + parser.add_argument("-d", "--debug", dest="debug", + help=_("The file where debug will be written"), + metavar="DEBUG_FILE") parser.add_argument("-f", "--file", dest="filename", default=path.join(CONFIG_PATH, 'poezio.cfg'), help=_("The config file you want to use"), metavar="CONFIG_FILE") - parser.add_argument("-d", "--debug", dest="debug", - help=_("The file where debug will be written"), - metavar="DEBUG_FILE") parser.add_argument("-v", "--version", dest="version", help=SUPPRESS, metavar="VERSION", default="0.9-dev") diff --git a/src/config.py b/src/config.py index ef5168e1..333809d2 100644 --- a/src/config.py +++ b/src/config.py @@ -522,6 +522,34 @@ def check_create_cache_dir(): except OSError: pass +def check_config(): + """ + Check the config file and print results + """ + result = {'missing': [], 'changed': []} + for option in DEFAULT_CONFIG['Poezio']: + value = config.get(option) + if value != DEFAULT_CONFIG['Poezio'][option]: + result['changed'].append((option, value, DEFAULT_CONFIG['Poezio'][option])) + else: + value = config.get(option, default='') + upper = value.upper() + default = str(DEFAULT_CONFIG['Poezio'][option]).upper() + if upper != default: + result['missing'].append(option) + + result['changed'].sort(key=lambda x: x[0]) + result['missing'].sort() + if result['changed']: + print('\033[1mOptions changed from the default configuration:\033[0m\n') + for option, new_value, default in result['changed']: + print(' \033[1m%s\033[0m = \033[33m%s\033[0m (default: \033[32m%s\033[0m)' % (option, new_value, default)) + + if result['missing']: + print('\n\033[1mMissing options:\033[0m (the defaults are used)\n') + for option in result['missing']: + print(' \033[31m%s\033[0m' % option) + def run_cmdline_args(CONFIG_PATH): "Parse the command line arguments" global options diff --git a/src/poezio.py b/src/poezio.py index 1a5a257e..7a83f510 100644 --- a/src/poezio.py +++ b/src/poezio.py @@ -59,6 +59,10 @@ def main(): from config import options + if options.check_config: + config.check_config() + sys.exit(0) + import theming theming.update_themes_dir() |