-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathcommon.py
36 lines (27 loc) · 1.13 KB
/
common.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
""" Common functions between CustomPiOS python scripts"""
from typing import Dict, Any, Optional, cast
import yaml
import os
from pathlib import Path
def get_custompios_folder():
custompios_path = os.environ.get("CUSTOM_PI_OS_PATH", None)
if custompios_path is not None:
return Path(custompios_path)
return Path(__file__).parent.parent
IMAGES_CONFIG = os.path.join(get_custompios_folder(), "images.yml")
def read_images() -> Dict[str, Dict[str,str]]:
if not os.path.isfile(IMAGES_CONFIG):
raise Exception(f"Error: Remotes config file not found: {IMAGES_CONFIG}")
with open(IMAGES_CONFIG,'r') as f:
output = yaml.safe_load(f)
return output
def get_image_config() -> Optional[Dict["str", Any]]:
images = read_images()
base_board = os.environ.get("BASE_BOARD", None)
base_image_path = os.environ.get("BASE_IMAGE_PATH", None)
# Default to raspberrypiarmhf board in case of CustomPiOS v1
if base_board is None:
base_board = "raspberrypiarmhf"
if base_board is not None and base_board in images["images"]:
return images["images"][base_board]
return None