Package arvados :: Module config
[hide private]
[frames] | no frames]

Source Code for Module arvados.config

 1  # Copyright (C) The Arvados Authors. All rights reserved. 
 2  # 
 3  # SPDX-License-Identifier: Apache-2.0 
 4   
 5  # config.py - configuration settings and global variables for Arvados clients 
 6  # 
 7  # Arvados configuration settings are taken from $HOME/.config/arvados. 
 8  # Environment variables override settings in the config file. 
 9   
10  import os 
11  import re 
12   
13  _settings = None 
14  if os.environ.get('HOME') is not None: 
15      default_config_file = os.environ['HOME'] + '/.config/arvados/settings.conf' 
16  else: 
17      default_config_file = '' 
18   
19  KEEP_BLOCK_SIZE = 2**26 
20  EMPTY_BLOCK_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0' 
21   
22 -def initialize(config_file=default_config_file):
23 global _settings 24 _settings = {} 25 26 # load the specified config file if available 27 try: 28 _settings = load(config_file) 29 except IOError: 30 pass 31 32 # override any settings with environment vars 33 for var in os.environ: 34 if var.startswith('ARVADOS_'): 35 _settings[var] = os.environ[var]
36
37 -def load(config_file):
38 cfg = {} 39 with open(config_file, "r") as f: 40 for config_line in f: 41 if re.match('^\s*$', config_line): 42 continue 43 if re.match('^\s*#', config_line): 44 continue 45 var, val = config_line.rstrip().split('=', 2) 46 cfg[var] = val 47 return cfg
48
49 -def flag_is_true(key, d=None):
50 if d is None: 51 d = settings() 52 return d.get(key, '').lower() in set(['1', 't', 'true', 'y', 'yes'])
53
54 -def get(key, default_val=None):
55 return settings().get(key, default_val)
56
57 -def settings():
58 if _settings is None: 59 initialize() 60 return _settings
61