3699: add arv-copy
[arvados.git] / sdk / python / arvados / config.py
index 2b8374afb5c493cbf0eaeecc4d95da5325433865..211e6f5563b0d9a0a3727e31df32b5b7ef790ac9 100644 (file)
@@ -14,17 +14,28 @@ 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
+            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'])