Merge branch 'master' into 3699-arv-copy
[arvados.git] / sdk / python / arvados / config.py
index e205e9239a65818f7ce21863ed676d96a46c737c..c3b9b4073dd6b84fd3162d08da6bd0708f75b8ca 100644 (file)
@@ -14,17 +14,33 @@ EMPTY_BLOCK_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0'
 def initialize(config_file=default_config_file):
     global _settings
     _settings = {}
-    if os.path.exists(config_file):
-        with open(config_file, "r") as f:
-            for config_line in f:
-                if re.match('^\s*#', config_line):
-                    continue
-                var, val = config_line.rstrip().split('=', 2)
-                _settings[var] = val
+
+    # load the specified config file if available
+    try:
+        _settings = load(config_file)
+    except IOError:
+        pass
+
+    # override any settings with environment vars
     for var in os.environ:
         if var.startswith('ARVADOS_'):
             _settings[var] = os.environ[var]
 
+def load(config_file):
+    cfg = {}
+    with open(config_file, "r") as f:
+        for config_line in f:
+            if re.match('^\s*$', config_line):
+                continue
+            if re.match('^\s*#', config_line):
+                continue
+            var, val = config_line.rstrip().split('=', 2)
+            cfg[var] = val
+    return cfg
+
+def flag_is_true(key):
+    return get(key, '').lower() in set(['1', 't', 'true', 'y', 'yes'])
+
 def get(key, default_val=None):
     return settings().get(key, default_val)