forked from CBIIT/icdc-dataloader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_base.py
48 lines (37 loc) · 1.34 KB
/
config_base.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
import os
import yaml
from bento.common.utils import get_logger
class BentoConfig:
def __init__(self, config_file, args, config_file_arg='config_file'):
self.log = get_logger('Bento Config')
if not config_file:
raise ValueError(f'Empty config file name')
if not os.path.isfile(config_file):
raise ValueError(f'"{config_file}" is not a file!')
self.config_file_arg = config_file_arg
with open(config_file) as c_file:
self.data = yaml.safe_load(c_file)['Config']
if self.data is None:
self.data = {}
self._override(args)
def _override(self, args):
for key, value in vars(args).items():
# Ignore config file argument
if key == self.config_file_arg:
continue
if isinstance(value, bool):
if value:
self.data[key] = value
elif value is not None:
self.data[key] = value
def create_folder(self, folder):
"""
Create given folder if not already exists
:param folder: folder path
:return:
"""
os.makedirs(folder, exist_ok=True)
if not os.path.isdir(folder):
msg = f'{folder} is not a folder!'
self.log.error(msg)
raise Exception(msg)