#26 Enable user config
Merged 3 years ago by lrossett. Opened 3 years ago by carlwgeorge.
centos/ carlwgeorge/centpkg user_config  into  develop

file modified
+13 -7
@@ -29,17 +29,22 @@ 

      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 @@ 

      # 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')

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

I think we need to document the configuration file, if it isn't yet, somewhere but this is beyond the scope of the PR.

Pull-Request has been merged by lrossett

3 years ago
Metadata