refactor: add paths, services ctx, and extract models to own files
This commit is contained in:
+19
-12
@@ -1,14 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import DirectoryPath, FilePath
|
||||
from pydantic_settings import BaseSettings
|
||||
from pydantic import BaseModel, DirectoryPath, FilePath
|
||||
|
||||
from core.utils import get_git_root
|
||||
|
||||
REPO_ROOT = get_git_root(__file__)
|
||||
|
||||
|
||||
class Paths(BaseSettings):
|
||||
class Paths(BaseModel):
|
||||
# fmt: off
|
||||
repo_root: DirectoryPath = REPO_ROOT
|
||||
|
||||
@@ -19,17 +18,25 @@ class Paths(BaseSettings):
|
||||
service_manager_ui_file: FilePath = repo_root / "qt" / "A_BD_ServiceManager.ui"
|
||||
# fmt: on
|
||||
|
||||
def get_files_to_stage(self, service_dir_name: str) -> list[str]:
|
||||
"""
|
||||
Returns all required relative file paths for git staging.
|
||||
"""
|
||||
service_current = self.repo_root / "services" / service_dir_name / "current"
|
||||
|
||||
staged_paths = [
|
||||
service_current,
|
||||
self.service_registry_file,
|
||||
self.master_hla_names_file,
|
||||
self.master_ioc_subs_file,
|
||||
self.iocs_overview_filename,
|
||||
self.service_manager_ui_file,
|
||||
]
|
||||
|
||||
return [self.relative(p) for p in staged_paths]
|
||||
|
||||
def relative(self, path: Path) -> str:
|
||||
"""
|
||||
Convert any absolute path into a string path relative to repo_root.
|
||||
"""
|
||||
return str(path.relative_to(self.repo_root))
|
||||
|
||||
def get_service_dir(self, service_dir_name: str) -> Path:
|
||||
"""
|
||||
Helper to get a service path dynamically.
|
||||
"""
|
||||
return self.repo_root / "services" / service_dir_name / "current"
|
||||
|
||||
|
||||
paths = Paths()
|
||||
|
||||
Reference in New Issue
Block a user