pgtoolkit/configparser.py
changeset 104 d8ff52a0390f
parent 103 24e94a3da209
child 105 10551741f61f
--- a/pgtoolkit/configparser.py	Mon May 26 18:18:21 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-import logging
-
-
-class ConfigParser:
-    def __init__(self):
-        self.args = {}       # config file arguments
-        self.registered_args = {}
-        self.log = logging.getLogger('config')
-
-    def add_argument(self, name, type=str, default=None):
-        self.registered_args[name] = {'type':type, 'default':default}
-        self.args[name] = default
-
-    def load(self, fname):
-        # parse config file
-        with open(fname) as f:
-            exec(f.read(), self.args)
-        # check contents
-        return self.check()
-
-    def check(self):
-        ok = True
-        for key in self.args.keys():
-            if key == '__builtins__':
-                continue
-            if key in self.registered_args:
-                # arg registered, check type
-                type = self.registered_args[key]['type']
-                if not isinstance(self.args[key], type) and not self.args[key] is None:
-                    ok = False
-                    self.log.error("Bad type of config parameter '%s': is %s but should be %s",
-                        key, type(self.args[key]), type)
-            else:
-                # arg not registered
-                ok = False
-                self.log.error("Unknown config parameter '%s'.", key)
-        return ok
-
-    def __getattr__(self, name):
-        if name in self.args:
-            return self.args[name]
-
-        # raise error if not found
-        raise AttributeError()
-