diff options
author | 2011-02-06 15:34:36 -0800 | |
---|---|---|
committer | 2011-02-06 15:34:36 -0800 | |
commit | 50fc5d0e88f000b775d2e67c24d5d6728833fdbc (patch) | |
tree | 8b185880559eb3af583641d75b5b89d013eded33 | |
parent | add an example testpath for testing the git checkout (diff) | |
download | overlord-50fc5d0e88f000b775d2e67c24d5d6728833fdbc.tar.gz overlord-50fc5d0e88f000b775d2e67c24d5d6728833fdbc.tar.bz2 overlord-50fc5d0e88f000b775d2e67c24d5d6728833fdbc.zip |
add the ability to plugin repository definition xml files without editing the config file
-rw-r--r-- | overlord/config.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/overlord/config.py b/overlord/config.py index 4caf83c..884fc58 100644 --- a/overlord/config.py +++ b/overlord/config.py @@ -28,6 +28,7 @@ __version__ = "$Id: config.py 286 2007-01-09 17:48:23Z wrobel $" #------------------------------------------------------------------------------- import sys, ConfigParser +import os from optparse import OptionParser, OptionGroup from overlord.debug import OUT @@ -44,6 +45,28 @@ _USAGE = """ overlord -f [-o URL] overlord (-l|-L|-S)""" + +def read_config(config=None, defaults=None): + """reads the config file defined in defaults['config'] + and updates the config + + @param config: ConfigParser.ConfigParser(self.defaults) instance + @param defaults: dict + @modifies config['MAIN']['overlays'] + """ + config.read(defaults['config']) + if config.get('MAIN', 'overlay_defs'): + filelist = os.listdir(config.get('MAIN', 'overlay_defs')) + filelist = [f for f in filelist if f.endswith('.xml')] + overlays = set(config.get('MAIN', 'overlays').split('\n')) + for _file in filelist: + path = os.path.join(config.get('MAIN', 'overlay_defs'), _file) + if os.path.isfile(path): + overlays.update(["file://" + path]) + config.set('MAIN', 'overlays', '\n'.join(overlays)) + + + class BareConfig(object): '''Handles the configuration only.''' @@ -68,7 +91,8 @@ class BareConfig(object): 'nocheck' : 'yes', 'proxy' : '', 'umask' : '0022', - 'overlays' : + 'overlays' : '', + 'overlay_defs': '/etc/overlord/overlays' 'http://www.gentoo.org/proj/en/overlays/repositories.xml', 'bzr_command': '/usr/bin/bzr', 'cvs_command': '/usr/bin/cvs', @@ -318,7 +342,7 @@ class ArgsParser(object): #----------------------------------------------------------------- # Debug Options - self.output.cli_opts(self.parser) + #self.output.cli_opts(self.parser) # Parse the command line first since we need to get the config # file option. @@ -333,7 +357,7 @@ class ArgsParser(object): % ', '.join(('"%s"' % e) for e in remain_args[1:])) # handle debugging - self.output.cli_handle(self.options) + #self.output.cli_handle(self.options) # add output to the options self.options.__dict__['output'] = self.output @@ -351,7 +375,7 @@ class ArgsParser(object): if not self.options.__dict__['config'] is None: self.defaults['config'] = self.options.__dict__['config'] - self.output.debug('Got config file at ' + self.defaults['config'], 8) + #self.output.debug('Got config file at ' + self.defaults['config'], 8) # Now parse the config file self.config = ConfigParser.ConfigParser(self.defaults) @@ -366,9 +390,9 @@ class ArgsParser(object): self.output.set_info_level(int(self['quietness'])) self.output.set_warn_level(int(self['quietness'])) - self.output.debug('Reading config file at ' + self.defaults['config'], 8) + #self.output.debug('Reading config file at ' + self.defaults['config'], 8) - self.config.read(self.defaults['config']) + read_config(self.config, self.defaults) def __getitem__(self, key): @@ -407,6 +431,7 @@ class ArgsParser(object): return None + def keys(self): '''Special handler for the configuration keys.''' |