From: Oleg Broytman Date: Sat, 19 Dec 2015 22:01:02 +0000 (+0300) Subject: Add configuration file parser and sample X-Git-Tag: 0.0.1~3 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=071f22093f133ede991d6125905e07a25f4c7ec6;p=m_librarian.git Add configuration file parser and sample --- diff --git a/m_librarian/config.py b/m_librarian/config.py new file mode 100755 index 0000000..f1dfdb7 --- /dev/null +++ b/m_librarian/config.py @@ -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 index 0000000..17fc310 --- /dev/null +++ b/sample/m_librarian.conf @@ -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