|
13 | 13 | # If not, see <https://www.gnu.org/licenses/>.""" |
14 | 14 | # Author: Tobias Sterbak |
15 | 15 |
|
16 | | -from typing import List |
| 16 | +from typing import List, Optional |
| 17 | +from pathlib import Path |
| 18 | +from loguru import logger |
17 | 19 |
|
18 | 20 | import yaml |
19 | 21 |
|
@@ -50,7 +52,33 @@ def from_file(cls, path): |
50 | 52 | raw_steps = config["steps"] |
51 | 53 | metadata = config["metadata"] |
52 | 54 | except yaml.YAMLError as exc: |
53 | | - print(exc) |
| 55 | + logger.info(exc) |
54 | 56 |
|
55 | 57 | steps = [Step(**raw_step) for raw_step in raw_steps] |
56 | 58 | return cls(steps, metadata) |
| 59 | + |
| 60 | + |
| 61 | +def _load_config(device_code: str, config_path: Path) -> Optional[InstallerConfig]: |
| 62 | + """ |
| 63 | + Function to load a function from given path and directory path. |
| 64 | + |
| 65 | + Try to load local file in the same directory as the executable first, then load from assets. |
| 66 | + """ |
| 67 | + # try loading a custom local file first |
| 68 | + custom_path = Path.cwd().joinpath(Path(f"{device_code}.yaml")) |
| 69 | + try: |
| 70 | + config = InstallerConfig.from_file(custom_path) |
| 71 | + logger.info(f"Loaded custom device config from {custom_path}.") |
| 72 | + logger.info(f"Config metadata: {config.metadata}.") |
| 73 | + return config |
| 74 | + except FileNotFoundError: |
| 75 | + # if no localfile, then try to load a config file from assets |
| 76 | + path = config_path.joinpath(Path(f"{device_code}.yaml")) |
| 77 | + try: |
| 78 | + config = InstallerConfig.from_file(path) |
| 79 | + logger.info(f"Loaded device config from {path}.") |
| 80 | + logger.info(f"Config metadata: {config.metadata}.") |
| 81 | + return config |
| 82 | + except FileNotFoundError: |
| 83 | + logger.info(f"No device config found for {path}.") |
| 84 | + return None |
0 commit comments