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 10import os 11import re 12 13from typing import ( 14 Callable, 15 Iterable, 16 Union, 17) 18 19from . import util 20from ._internal import basedirs 21 22_settings = None 23default_config_file = '' 24""" 25.. WARNING:: Deprecated 26 Default configuration initialization now searches for the "default" 27 configuration in several places. This value no longer has any effect. 28""" 29 30KEEP_BLOCK_SIZE = 2**26 31EMPTY_BLOCK_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0' 32 33def initialize( 34 config_file: Union[ 35 str, 36 os.PathLike, 37 Callable[[str], Iterable[os.PathLike]], 38 ]=basedirs.BaseDirectories('CONFIG').search, 39) -> None: 40 global _settings 41 _settings = {} 42 43 if callable(config_file): 44 search_paths = iter(config_file('settings.conf')) 45 config_file = next(search_paths, '') 46 47 # load the specified config file if available 48 try: 49 _settings = load(config_file) 50 except IOError: 51 pass 52 53 # override any settings with environment vars 54 for var in os.environ: 55 if var.startswith('ARVADOS_'): 56 _settings[var] = os.environ[var] 57 58def load(config_file): 59 cfg = {} 60 with open(config_file, "r") as f: 61 for config_line in f: 62 if re.match(r'^\s*(?:#|$)', config_line): 63 continue 64 var, val = config_line.rstrip().split('=', 2) 65 cfg[var] = val 66 return cfg 67 68def flag_is_true(key, d=None): 69 if d is None: 70 d = settings() 71 return d.get(key, '').lower() in set(['1', 't', 'true', 'y', 'yes']) 72 73def get(key, default_val=None): 74 return settings().get(key, default_val) 75 76def settings(): 77 if _settings is None: 78 initialize() 79 return _settings
default_config_file =
''
KEEP_BLOCK_SIZE =
67108864
EMPTY_BLOCK_LOCATOR =
'd41d8cd98f00b204e9800998ecf8427e+0'
def
initialize( config_file: Union[str, os.PathLike, Callable[[str], Iterable[os.PathLike]]] = <bound method BaseDirectories.search of <arvados._internal.basedirs.BaseDirectories object>>) -> None:
34def initialize( 35 config_file: Union[ 36 str, 37 os.PathLike, 38 Callable[[str], Iterable[os.PathLike]], 39 ]=basedirs.BaseDirectories('CONFIG').search, 40) -> None: 41 global _settings 42 _settings = {} 43 44 if callable(config_file): 45 search_paths = iter(config_file('settings.conf')) 46 config_file = next(search_paths, '') 47 48 # load the specified config file if available 49 try: 50 _settings = load(config_file) 51 except IOError: 52 pass 53 54 # override any settings with environment vars 55 for var in os.environ: 56 if var.startswith('ARVADOS_'): 57 _settings[var] = os.environ[var]
def
load(config_file):
def
flag_is_true(key, d=None):
def
get(key, default_val=None):
def
settings():