changeset 21:4f7c05630f36

tie up some factory loose ends and sweeten the API with syntactic sugar
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 06 Jun 2011 07:39:18 -0700
parents 057ccfe310b2
children b16d6a204ac1
files pyloader/factory.py
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pyloader/factory.py	Mon Jun 06 07:33:37 2011 -0700
+++ b/pyloader/factory.py	Mon Jun 06 07:39:18 2011 -0700
@@ -89,18 +89,22 @@
 
     def __init__(self, inifile, main=''):
         assert os.path.exists(inifile), "File not found: %s" % inifile
-
-    def read(self):
+        self.inifile = inifile
+        config = self.read(inifile)
+        PyFactory.__init__(self, config, main)
+        
+    @classmethod
+    def read(cls, inifile):
         """reads configuration from an .ini file"""
 
-        here = os.path.dirname(os.path.abspath(self.inifile))
+        here = os.path.dirname(os.path.abspath(inifile))
         
         # read configuration
         defaults={'here': here,
-                  'this': os.path.abspath(self.inifile)}
+                  'this': os.path.abspath(inifile)}
         parser = ConfigParser(defaults=defaults)
         parser.optionxform = str # use whole case
-        parser.read(self.inifile)
+        parser.read(inifile)
 
         # parse configuration
         config = {}
@@ -131,4 +135,8 @@
                     sect['args'] = cast.str2list(value)
                 else:
                     sect.setdefault('kwargs', {})[option] = value
-                    
+
+        return config
+
+if __name__ == '__main__':
+    pass