changeset 41:2c228e3cd6d8

split reading and interpreting the .ini into different functions
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 08 Jun 2011 17:50:05 -0700
parents 0b2019d0af98
children 0eebe05f8984
files pyloader/factory.py
diffstat 1 files changed, 26 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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"""