Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorent <florent@toopy.org>2011-12-21 00:25:58 (GMT)
committer florent <florent@toopy.org>2011-12-21 00:25:58 (GMT)
commit7220b8450e709f500a382921c807d0aa006bc1e4 (patch)
treec433b8c1da15bc0d8e3472e3fc004e67650a7cc7
parent671f944da6e578459373b13c9648433de7f79cd5 (diff)
ensure default config, or local or passed as param for easy install and use
-rw-r--r--datastore_reader/utils/config.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/datastore_reader/utils/config.py b/datastore_reader/utils/config.py
index 76caed6..456343e 100644
--- a/datastore_reader/utils/config.py
+++ b/datastore_reader/utils/config.py
@@ -1,13 +1,35 @@
+# python import
+import os, sys
+
# config obj
from ConfigObject import config_module
+
def _init_config_obj():
+ # init path var
+ config_path = '__no_config___'
+ # config path passed
+ if len(sys.argv) > 1\
+ and os.path.exists(sys.argv[1]):
+ config_path = sys.argv[1]
+ # or in the current dir
+ if not os.path.exists(config_path):
+ config_path = 'config.ini'
+ # or in the package by default
+ if not os.path.exists(config_path):
+ config_path = os.path.join(os.path.dirname(__file__),
+ '..', '..', 'config.ini')
+ # really no config!!
+ if not os.path.exists(config_path):
+ raise Exception('no config found!')
# init config obj
- config_module(__name__, __file__, 'config.ini')
+ config_module(__name__, __file__, config_path)
+
# singleton flag
__initialized__ = False
+
# do init
if __initialized__ is False:
# init config