goa/overrides/toolsutils.py
changeset 0 b97547f5f1fa
child 1977 606923dff11b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/goa/overrides/toolsutils.py	Wed Nov 05 15:52:50 2008 +0100
@@ -0,0 +1,50 @@
+import sys
+from cubicweb import warning
+
+def lines(path, comments=None):
+    result = []
+    for line in open(path, 'U'):
+        line = line.strip()
+        if line and (comments is None or not line.startswith(comments)):
+            result.append(line)
+    return result
+
+def read_config(config_file):
+    """read the application configuration from a file and return it as a
+    dictionnary
+
+    :type config_file: str
+    :param config_file: path to the configuration file
+
+    :rtype: dict
+    :return: a dictionary with specified values associated to option names 
+    """
+    config = current = {}
+    try:
+        for line in lines(config_file, comments='#'):
+            try:
+                option, value = line.split('=', 1)
+            except ValueError:
+                option = line.strip().lower()
+                if option[0] == '[':
+                    # start a section
+                    section = option[1:-1]
+                    assert not config.has_key(section), \
+                           'Section %s is defined more than once' % section
+                    config[section] = current = {}
+                    continue
+                print >> sys.stderr, 'ignoring malformed line\n%r' % line
+                continue
+            option = option.strip().replace(' ', '_')
+            value = value.strip()
+            current[option] = value or None
+    except IOError, ex:
+        warning('missing or non readable configuration file %s (%s)',
+                config_file, ex)
+    return config
+
+def env_path(env_var, default, name):
+    return default
+
+def create_dir(*args):
+    raise RuntimeError()