-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_loader.py
50 lines (41 loc) · 1.54 KB
/
config_loader.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
import sys
import yaml
import pathlib
from pydantic import BaseModel, DirectoryPath
from typing import List, Optional
import log_utils as wp
Config = None
chia_const = None
class WrapperConfig(BaseModel):
mode: str
farmer_key: str
contract_key: str
compression_level: int
plotter_enabled: bool
directories_to_plot: List[str]
plot_with_128GO_ram_only: bool
tmp_plot_directory_for_128go_ram_support: Optional[str] = None
use_staging_directories: bool
staging_directories: Optional[List[str]] = None
manager_bdd_path: Optional[str] = None
staging_use_process_number: bool
staging_copy_concurrent_process: Optional[int] = None
def load_config(path: str):
load_chia_const()
config_path = pathlib.Path(path)
try:
with open(config_path, 'r') as yaml_file:
try:
global Config
Config = WrapperConfig(**yaml.safe_load(yaml_file))
wp.Logger.bladebit_wrapper_logger.log(wp.Logger.SUCCESS, 'Configuration is valid')
except ValueError as e:
wp.Logger.bladebit_wrapper_logger.log(wp.Logger.FAILED, 'Configuration is invalid: {}'.format(e))
sys.exit(1)
except yaml.YAMLError as e:
wp.Logger.bladebit_wrapper_logger.log(wp.Logger.FAILED, 'Unable to load YAML {} caused by: {}'.format(path, e))
def load_chia_const():
chia_const_path = pathlib.Path('config/chia.yml')
with open(chia_const_path, 'r') as yaml_file:
global chia_const
chia_const = yaml.safe_load(yaml_file)