Gentoo Archives: gentoo-catalyst

From: "Rick \\\"Zero_Chaos\\\" Farina" <zerochaos@g.o>
To: gentoo-catalyst@l.g.o
Subject: Re: [gentoo-catalyst] [PATCH] main: extend the -c option to accept multiple files
Date: Wed, 28 Oct 2015 01:53:06
Message-Id: 56302A94.4060603@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH] main: extend the -c option to accept multiple files by Mike Frysinger
1 I support this idea, but maybe we could leave the --config option so as
2 not to confuse people who are only passing one config?
3
4 Thanks,
5 Zero
6
7 On 10/27/2015 01:52 AM, Mike Frysinger wrote:
8 > There's no real reason people can't load multiple config files, so extend
9 > the --config option into --configs and let people specify multiple ones.
10 > ---
11 > catalyst/defaults.py | 2 ++
12 > catalyst/main.py | 55 +++++++++++++++++-----------------------------------
13 > 2 files changed, 20 insertions(+), 37 deletions(-)
14 >
15 > diff --git a/catalyst/defaults.py b/catalyst/defaults.py
16 > index 666afca..c5162d6 100644
17 > --- a/catalyst/defaults.py
18 > +++ b/catalyst/defaults.py
19 > @@ -46,6 +46,8 @@ confdefaults={
20 > "storedir": "/var/tmp/catalyst",
21 > }
22 >
23 > +DEFAULT_CONFIG_FILE = '/etc/catalyst/catalyst.conf'
24 > +
25 > PORT_LOGDIR_CLEAN = \
26 > 'find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
27 >
28 > diff --git a/catalyst/main.py b/catalyst/main.py
29 > index 9f563cf..176871d 100644
30 > --- a/catalyst/main.py
31 > +++ b/catalyst/main.py
32 > @@ -21,7 +21,7 @@ from DeComp.contents import ContentsMap
33 >
34 > from catalyst import log
35 > import catalyst.config
36 > -from catalyst.defaults import confdefaults, option_messages
37 > +from catalyst.defaults import confdefaults, option_messages, DEFAULT_CONFIG_FILE
38 > from catalyst.hash_utils import HashMap, HASH_DEFINITIONS
39 > from catalyst.support import CatalystError
40 > from catalyst.version import get_version
41 > @@ -36,40 +36,19 @@ def version():
42 > log.info('Copyright 2008-2012 various authors')
43 > log.info('Distributed under the GNU General Public License version 2.1')
44 >
45 > -def parse_config(myconfig):
46 > +def parse_config(config_files):
47 > # search a couple of different areas for the main config file
48 > myconf={}
49 > - config_file=""
50 > - default_config_file = '/etc/catalyst/catalyst.conf'
51 >
52 > - # first, try the one passed (presumably from the cmdline)
53 > - if myconfig:
54 > - if os.path.exists(myconfig):
55 > - log.notice('Using command line specified Catalyst configuration file: %s',
56 > - myconfig)
57 > - config_file=myconfig
58 > -
59 > - else:
60 > - log.critical('Specified configuration file does not exist: %s', myconfig)
61 > -
62 > - # next, try the default location
63 > - elif os.path.exists(default_config_file):
64 > - log.notice('Using default Catalyst configuration file: %s',
65 > - default_config_file)
66 > - config_file = default_config_file
67 > -
68 > - # can't find a config file (we are screwed), so bail out
69 > - else:
70 > - log.critical('Could not find a suitable configuration file')
71 > -
72 > - # now, try and parse the config file "config_file"
73 > - try:
74 > -# execfile(config_file, myconf, myconf)
75 > - myconfig = catalyst.config.ConfigParser(config_file)
76 > - myconf.update(myconfig.get_values())
77 > -
78 > - except Exception:
79 > - log.critical('Could not find parse configuration file: %s', myconfig)
80 > + # try and parse the config file "config_file"
81 > + for config_file in config_files:
82 > + log.notice('Loading configuration file: %s', config_file)
83 > + try:
84 > + config = catalyst.config.ConfigParser(config_file)
85 > + myconf.update(config.get_values())
86 > + except Exception as e:
87 > + log.critical('Could not find parse configuration file: %s: %s',
88 > + config_file, e)
89 >
90 > # now, load up the values into conf_values so that we can use them
91 > for x in list(confdefaults):
92 > @@ -209,9 +188,9 @@ $ catalyst -f stage1-specfile.spec"""
93 > group.add_argument('-F', '--fetchonly',
94 > default=False, action='store_true',
95 > help='fetch files only')
96 > - group.add_argument('-c', '--config',
97 > - type=FilePath(),
98 > - help='use specified configuration file')
99 > + group.add_argument('-c', '--configs',
100 > + type=FilePath(), action='append',
101 > + help='use specified configuration files')
102 > group.add_argument('-f', '--file',
103 > type=FilePath(),
104 > help='read specfile')
105 > @@ -241,7 +220,9 @@ def main():
106 > color=opts.color)
107 >
108 > # Parse the command line options.
109 > - myconfig = opts.config
110 > + myconfigs = opts.configs
111 > + if not myconfigs:
112 > + myconfigs = [DEFAULT_CONFIG_FILE]
113 > myspecfile = opts.file
114 > mycmdline = opts.cli[:]
115 >
116 > @@ -271,7 +252,7 @@ def main():
117 > # made it this far so start by outputting our version info
118 > version()
119 > # import configuration file and import our main module using those settings
120 > - parse_config(myconfig)
121 > + parse_config(myconfigs)
122 >
123 > conf_values["options"].update(options)
124 > log.debug('conf_values[options] = %s', conf_values['options'])
125 >

Replies