# HG changeset patch # User Jeff Hammel # Date 1307580605 25200 # Node ID 2c228e3cd6d8fe3550fc784e2ce9a35554ba2207 # Parent 0b2019d0af98d354e5294f77d10be891bd735c7d split reading and interpreting the .ini into different functions diff -r 0b2019d0af98 -r 2c228e3cd6d8 pyloader/factory.py --- a/pyloader/factory.py Wed Jun 08 08:36:32 2011 -0700 +++ b/pyloader/factory.py Wed Jun 08 17:50:05 2011 -0700 @@ -98,6 +98,29 @@ self.inifile = inifile config = self.read(inifile) PyFactory.__init__(self, config, main) + + @classmethod + def configuration(cls, iniconfig, **defaults): + """interpret configuration from raw .ini syntax""" + config = {} + for section, options in iniconfig.items(): + + # sanity check + assert ':' in section, "No : in section: %s" % section + + # make a dict for the section + name, path = section.split(':', 1) + path = path % defaults + sect = config[name] = dict(path=path) + + for option, value in options.items(): + + if option == '.': # positional arguments + sect['args'] = cast.str2list(value) + else: + sect.setdefault('kwargs', {})[option] = value + + return config @classmethod def read(cls, inifile): @@ -112,19 +135,11 @@ parser.optionxform = str # use whole case parser.read(inifile) - decorators = {} - # parse configuration config = {} for section in parser.sections(): - # sanity check - assert ':' in section, "No : in section: %s" % section - - # make a dict for the section - name, path = section.split(':', 1) - path = path % parser.defaults() - sect = config[name] = dict(path=path) + config[section] = {} # read the options for option in parser.options(section): @@ -140,12 +155,9 @@ except (InterpolationMissingOptionError, InterpolationSyntaxError, InterpolationDepthError): value = parser.get(section, option, raw=True) - if option == '.': # positional arguments - sect['args'] = cast.str2list(value) - else: - sect.setdefault('kwargs', {})[option] = value + config[section][option] = value - return config + return cls.configuration(config, **parser.defaults()) def main(args=sys.argv[1:]): """command line entry point"""