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