-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
66 lines (51 loc) · 1.67 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# from btdashboard.defaults import default_settings
from btdashboard.logger import Logger
import os
from btconfig import Config
logger = Logger().init_logger(__name__)
class AppConfig():
def __init__(self, **kwargs):
pass
def initialize(self, **kwargs):
logger.info("Initializing config")
args = kwargs.get('args', {})
verify_tls = kwargs.get('verify_tls')
# Initialize App Config
initial_data = {
'environment': os.environ
}
config_file_uri = kwargs.get('config_file') or \
args.get('config_file')
if config_file_uri:
logger.info(f"Config file URI is {config_file_uri}")
# Initialize App Config
config = Config(
config_file_uri=config_file_uri,
initial_data=initial_data,
args=args,
verify_tls=verify_tls
)
settings = config.read()
return settings
else:
return {}
@staticmethod
def get_config_path(search_paths, config_file_name):
config_found = False
config_file_paths = [
os.path.expanduser(os.path.join(p, 'etc', config_file_name))
for p in search_paths
]
config_file_paths_adjacent = [
os.path.expanduser(os.path.join(p, config_file_name))
for p in search_paths
]
config_file_paths.extend(config_file_paths_adjacent)
for config_file_path in config_file_paths:
logger.debug(f'Checking {config_file_path}')
if os.path.exists(config_file_path):
logger.info(f'Found {config_file_path}')
return config_file_path
if not config_found:
logger.error(f'Could not find {config_file_name} config file in any of the expected locations')
return None