From 5b6d1752246693c9b59d7e6f731031eb925b058b Mon Sep 17 00:00:00 2001 From: Carl George Date: Apr 16 2021 03:02:09 +0000 Subject: Enable user config Read both `/etc/rpkg/centpkg.conf` and `~/.config/rpkg/centpkg.conf` config files, merging the results. Also define a `--user-config` flag to override the later config path, similar to `--config`. This approach is borrowed from fedpkg. Fixes #23 --- diff --git a/src/centpkg/__main__.py b/src/centpkg/__main__.py index 549e5b2..c696c69 100644 --- a/src/centpkg/__main__.py +++ b/src/centpkg/__main__.py @@ -29,17 +29,22 @@ def main(): Centpkg main. """ - # Setup an argparser and parse the known commands to get the config file program_name = os.path.basename(sys.argv[0]) - # Modified ArgumentParser provides parameter "allow_abbrev=False" (which affects processing - # of commandline arguments with common prefix). Generaly it is available since python3.6. - - # This enables "allow_abbrev" for older python versions. - parser = pyrpkg.cli.ArgumentParser(add_help=False) + default_user_config_path = os.path.join( + os.path.expanduser('~'), '.config', 'rpkg', '%s.conf' % program_name) + + # Setup an argparser and parse the known commands to get the config file + + # - use the custom ArgumentParser class from pyrpkg.cli and disable + # argument abbreviation to ensure that --user will be not treated as + # --user-config + parser = pyrpkg.cli.ArgumentParser(add_help=False, allow_abbrev=False) parser.add_argument('-C', '--config', help='Specify a config file to use', - default=f'/etc/rpkg/%s.conf' % program_name) + default='/etc/rpkg/%s.conf' % program_name) + parser.add_argument('--user-config', help='Specify a user config file to use', + default=default_user_config_path) (args, other) = parser.parse_known_args() @@ -51,6 +56,7 @@ def main(): # Setup a configuration object and read config file data config = ConfigParser.SafeConfigParser() config.read(args.config) + config.read(args.user_config) client = centpkg.cli.centpkgClient(config, name=program_name) client.do_imports(site='centpkg')