forked from osl-incubator/scicookie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.py
46 lines (33 loc) · 1.35 KB
/
profile.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
"""Profile handles "profiles" defined in the .yaml files."""
from pathlib import Path
import yaml
from scicookie.logs import SciCookieErrorType, SciCookieLogs
PACKAGE_PATH = Path(__file__).parent
PROFILE_DIR_PATH = PACKAGE_PATH / "profiles"
class Profile:
"""Profile class that handles profiles defined in the .yaml files."""
profile_name: str = ""
config: dict = {}
profiles_available: list = []
def __init__(self, profile_name: str):
self._load_profiles_available()
if profile_name not in self.profiles_available:
SciCookieLogs.raise_error(
"The given profiles is not available.",
SciCookieErrorType.SCICOOKIE_INVALID_PARAMETER,
)
self.profile_name = profile_name
self.config = self.read_config()
def _load_profiles_available(self):
# note: it should catch it from the files' name
self.profiles_available = ["osl"]
def read_config(self):
"""Read the config file."""
config = {}
with open(PROFILE_DIR_PATH / "base.yaml") as f:
config = yaml.safe_load(f)
with open(PROFILE_DIR_PATH / f"{self.profile_name}.yaml") as f:
config_profile = yaml.safe_load(f)
for name, properties in config_profile.items():
config[name].update(properties)
return config