app_deploy: refactor configuration handling
Move specific configuration out of __init__ into several methods that may be called by subclasses. This allows child implementations to define and share specific sets of configuration that they require without forcing all implementations to do so. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
@@ -8,10 +8,12 @@ from __future__ import annotations
|
||||
import os
|
||||
import sys
|
||||
import copy
|
||||
import pathlib
|
||||
from ...utils import source_info
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Dict
|
||||
Dict,
|
||||
Optional
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -26,9 +28,9 @@ BASE_CONFIG: Dict[str, Dict[str, str]] = {
|
||||
"origin": "https://github.com/arksine/moonraker.git",
|
||||
"requirements": "scripts/moonraker-requirements.txt",
|
||||
"venv_args": "-p python3",
|
||||
"install_script": "scripts/install-moonraker.sh",
|
||||
"system_dependencies": "scripts/system-dependencies.json",
|
||||
"host_repo": "arksine/moonraker",
|
||||
"env": sys.executable,
|
||||
"virtualenv": sys.exec_prefix,
|
||||
"path": str(source_info.source_path()),
|
||||
"managed_services": "moonraker"
|
||||
},
|
||||
@@ -43,14 +45,19 @@ BASE_CONFIG: Dict[str, Dict[str, str]] = {
|
||||
}
|
||||
}
|
||||
|
||||
def get_app_type(app_path: Optional[pathlib.Path] = None) -> str:
|
||||
# None type will perform checks on Moonraker
|
||||
if source_info.is_git_repo(app_path):
|
||||
return "git_repo"
|
||||
else:
|
||||
return "zip"
|
||||
|
||||
def get_base_configuration(config: ConfigHelper, channel: str) -> ConfigHelper:
|
||||
server = config.get_server()
|
||||
base_cfg = copy.deepcopy(BASE_CONFIG)
|
||||
app_type = "zip" if channel == "stable" else "git_repo"
|
||||
base_cfg["moonraker"]["channel"] = channel
|
||||
base_cfg["moonraker"]["type"] = app_type
|
||||
base_cfg["klipper"]["channel"] = channel
|
||||
base_cfg["klipper"]["type"] = app_type
|
||||
base_cfg["moonraker"]["type"] = get_app_type()
|
||||
base_cfg["klipper"]["channel"] = "beta" if channel == "stable" else channel
|
||||
db: MoonrakerDatabase = server.lookup_component('database')
|
||||
base_cfg["klipper"]["path"] = db.get_item(
|
||||
"moonraker", "update_manager.klipper_path", KLIPPER_DEFAULT_PATH
|
||||
@@ -58,4 +65,6 @@ def get_base_configuration(config: ConfigHelper, channel: str) -> ConfigHelper:
|
||||
base_cfg["klipper"]["env"] = db.get_item(
|
||||
"moonraker", "update_manager.klipper_exec", KLIPPER_DEFAULT_EXEC
|
||||
).result()
|
||||
klipper_path = pathlib.Path(base_cfg["klipper"]["path"])
|
||||
base_cfg["klipper"]["type"] = get_app_type(klipper_path)
|
||||
return config.read_supplemental_dict(base_cfg)
|
||||
|
Reference in New Issue
Block a user