1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 # config.py - configuration settings and global variables for Arvados clients
7 # Arvados configuration settings are taken from $HOME/.config/arvados.
8 # Environment variables override settings in the config file.
14 if os.environ.get('HOME') is not None:
15 default_config_file = os.environ['HOME'] + '/.config/arvados/settings.conf'
17 default_config_file = ''
19 KEEP_BLOCK_SIZE = 2**26
20 EMPTY_BLOCK_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0'
22 def initialize(config_file=default_config_file):
26 # load the specified config file if available
28 _settings = load(config_file)
32 # override any settings with environment vars
33 for var in os.environ:
34 if var.startswith('ARVADOS_'):
35 _settings[var] = os.environ[var]
37 def load(config_file):
39 with open(config_file, "r") as f:
41 if re.match(r'^\s*(?:#|$)', config_line):
43 var, val = config_line.rstrip().split('=', 2)
47 def flag_is_true(key, d=None):
50 return d.get(key, '').lower() in set(['1', 't', 'true', 'y', 'yes'])
52 def get(key, default_val=None):
53 return settings().get(key, default_val)