3427: Restore arv-put's resume functionality.
[arvados.git] / sdk / python / arvados / config.py
1 # config.py - configuration settings and global variables for Arvados clients
2 #
3 # Arvados configuration settings are taken from $HOME/.config/arvados.
4 # Environment variables override settings in the config file.
5
6 import os
7 import re
8
9 _settings = None
10 default_config_file = os.environ['HOME'] + '/.config/arvados/settings.conf'
11
12 EMPTY_BLOCK_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0'
13
14 def initialize(config_file=default_config_file):
15     global _settings
16     _settings = {}
17     if os.path.exists(config_file):
18         with open(config_file, "r") as f:
19             for config_line in f:
20                 if re.match('^\s*#', config_line):
21                     continue
22                 var, val = config_line.rstrip().split('=', 2)
23                 _settings[var] = val
24     for var in os.environ:
25         if var.startswith('ARVADOS_'):
26             _settings[var] = os.environ[var]
27
28 def get(key, default_val=None):
29     return settings().get(key, default_val)
30
31 def settings():
32     if _settings is None:
33         initialize()
34     return _settings