]> git.phdru.name Git - m_librarian.git/commitdiff
Add configuration file parser and sample
authorOleg Broytman <phd@phdru.name>
Sat, 19 Dec 2015 22:01:02 +0000 (01:01 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 19 Dec 2015 22:01:02 +0000 (01:01 +0300)
m_librarian/config.py [new file with mode: 0755]
sample/m_librarian.conf [new file with mode: 0644]

diff --git a/m_librarian/config.py b/m_librarian/config.py
new file mode 100755 (executable)
index 0000000..f1dfdb7
--- /dev/null
@@ -0,0 +1,28 @@
+#! /usr/bin/env python
+
+__all__ = ['ml_conf']
+
+import os
+from ConfigParser import SafeConfigParser
+
+config_dirs = []
+if 'XDG_CONFIG_HOME' in os.environ:
+    config_dirs.append(os.environ['XDG_CONFIG_HOME'])
+if 'XDG_CONFIG_DIRS' in os.environ:
+    config_dirs.extend(os.environ['XDG_CONFIG_DIRS'].split(':'))
+home_config = os.path.expanduser('~/.config')
+if home_config not in config_dirs:
+    config_dirs.append(home_config)
+
+for d in config_dirs:
+    ml_conf_file = os.path.join(d, 'm_librarian.conf')
+    if os.path.exists(ml_conf_file):
+        ml_conf = SafeConfigParser()
+        ml_conf.read(ml_conf_file)
+        break
+else:
+    ml_conf = ml_conf_file = None
+
+if __name__ == '__main__':
+    print "Config dirs:", config_dirs
+    print "Config file:", ml_conf_file
diff --git a/sample/m_librarian.conf b/sample/m_librarian.conf
new file mode 100644 (file)
index 0000000..17fc310
--- /dev/null
@@ -0,0 +1,10 @@
+[database]
+; DB URI syntax examples:
+
+; URI = mysql://host/database?debug=1
+; URI = mysql://user:password@host/database
+; URI = postgres:///full/path/to/socket/database
+; URI = postgres://host:5432/database
+; URI = postgres://user@host/database?debug=&cache=
+; URI = sqlite:///full/path/to/database
+; URI = sqlite:/C:/full/path/to/database