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