chore: update ui service manager of new service
This commit is contained in:
@@ -20,6 +20,9 @@ IOCS_OVERVIEW_FILENAME = REPO_ROOT / "docs" / "ioc" / "ioc_overview.md"
|
||||
|
||||
SERVICE_MANAGER_UI_FILENAME = REPO_ROOT / "qt" / "A_BD_ServiceManager.ui"
|
||||
|
||||
MASTER_SERVICE_DIR = REPO_ROOT / "services" / "master" / "current"
|
||||
MASTER_IOC_SUBS_FILE = MASTER_SERVICE_DIR / "ioc" / "AGEBD-CPCL-MASTER_main.subs"
|
||||
|
||||
|
||||
class Service(BaseModel):
|
||||
name: str
|
||||
@@ -132,6 +135,49 @@ class IocsOverview(BaseModel):
|
||||
f.write(self.content)
|
||||
|
||||
|
||||
class MasterIocSubs(BaseModel):
|
||||
config_path: ClassVar[str] = str(MASTER_IOC_SUBS_FILE)
|
||||
|
||||
content: str
|
||||
|
||||
@classmethod
|
||||
def read_from_file(cls) -> "MasterIocSubs":
|
||||
with open(cls.config_path) as f:
|
||||
file_content = f.read()
|
||||
|
||||
return MasterIocSubs(content=file_content)
|
||||
|
||||
def update_content(
|
||||
self,
|
||||
service_name: str,
|
||||
starton: str = "0", # TODO: ok defaults?
|
||||
autooff: str = "0", # TODO: ok defaults?
|
||||
):
|
||||
"""
|
||||
Parses the configuration text and appends a new row before the closing bracket.
|
||||
"""
|
||||
quoted_service = f'"{service_name}"'
|
||||
new_row = f' {{ "{{{{ agebd_env }}}}", {quoted_service:<22} , "{starton}", "{autooff}" }}'
|
||||
|
||||
# Use regex to find the last closing curly brace of the configuration block
|
||||
# This targets the line that contains only a lone closing brace, optional spaces, and maybe a comma/semicolon.
|
||||
pattern = r"(\s*\n\s*\}(?:;|,)?\s*$)"
|
||||
|
||||
if re.search(pattern, self.content, re.MULTILINE):
|
||||
# Insert our new row right before that closing brace line
|
||||
self.content = re.sub(
|
||||
pattern, f"\n{new_row}\\1", self.content, count=1, flags=re.MULTILINE
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
"Could not locate the closing structure format '}' inside the configuration."
|
||||
)
|
||||
|
||||
def write_to_file(self) -> None:
|
||||
with open(self.config_path, "w") as f:
|
||||
f.write(self.content)
|
||||
|
||||
|
||||
# TODO: maybe separate models into their own files
|
||||
class ServiceManagerUI(BaseModel):
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
|
||||
@@ -14,7 +14,14 @@ from core.git import (
|
||||
git_push_changes,
|
||||
switch_branch,
|
||||
)
|
||||
from core.models import IocsOverview, MasterHLANames, Service, ServiceManagerUI, ServiceRegistry
|
||||
from core.models import (
|
||||
IocsOverview,
|
||||
MasterHLANames,
|
||||
MasterIocSubs,
|
||||
Service,
|
||||
ServiceManagerUI,
|
||||
ServiceRegistry,
|
||||
)
|
||||
from core.utils import get_git_root
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -23,8 +30,6 @@ REPO_ROOT = get_git_root(__file__)
|
||||
SERVICE_TEMPLATES_DIR = REPO_ROOT / "templates" / "service"
|
||||
SERVICE_DEST_DIR = REPO_ROOT / "services"
|
||||
|
||||
MASTER_SERVICE_DIR = REPO_ROOT / "services" / "master" / "current"
|
||||
MASTER_IOC_SUBS_FILE = MASTER_SERVICE_DIR / "ioc" / "AGEBD-CPCL-MASTER_main.subs"
|
||||
|
||||
# TODO: lots of hardcoded paths. Create config object?
|
||||
|
||||
@@ -51,6 +56,9 @@ class ServiceCreator:
|
||||
iocs_overview_old = IocsOverview.read_from_file()
|
||||
iocs_overview = IocsOverview.read_from_file()
|
||||
iocs_overview.add_ioc(service, description=self.ioc_description)
|
||||
master_ioc_subs_old = MasterIocSubs.read_from_file()
|
||||
master_ioc_subs = MasterIocSubs.read_from_file()
|
||||
master_ioc_subs.update_content(service_name=service.name_upper)
|
||||
service_manager_old = ServiceManagerUI.read_from_file()
|
||||
service_manager = ServiceManagerUI.read_from_file()
|
||||
service_manager.update_xml(service=service, ui_name=self.ui_name, panelcmd=self.panelcmd)
|
||||
@@ -68,14 +76,9 @@ class ServiceCreator:
|
||||
registry.write_to_config()
|
||||
hla_names.write_to_config()
|
||||
iocs_overview.write_to_file()
|
||||
master_ioc_subs.write_to_file()
|
||||
service_manager.write_to_file()
|
||||
|
||||
self._append_to_master_ioc_subs(
|
||||
service_name=service.name_upper,
|
||||
starton="0", # TODO: ok?
|
||||
autooff="0", # TODO: ok?
|
||||
)
|
||||
|
||||
# TODO: can't push if branch already exists in remote
|
||||
raise
|
||||
git_push_changes(
|
||||
@@ -95,6 +98,7 @@ class ServiceCreator:
|
||||
registry_old.write_to_config()
|
||||
hla_names_old.write_to_config()
|
||||
iocs_overview_old.write_to_file()
|
||||
master_ioc_subs_old.write_to_file()
|
||||
service_manager_old.write_to_file()
|
||||
switch_branch(repo, original_branch)
|
||||
raise e
|
||||
@@ -145,34 +149,3 @@ class ServiceCreator:
|
||||
logger.error(f"Exit Code: {e.returncode}")
|
||||
logger.error(f"Details:\n{e.stderr}")
|
||||
raise UVError(e.stderr) from e
|
||||
|
||||
def _append_to_master_ioc_subs(
|
||||
self,
|
||||
service_name: str,
|
||||
starton: str,
|
||||
autooff: str,
|
||||
) -> None:
|
||||
"""
|
||||
Parses the configuration text and appends a new row before the closing bracket.
|
||||
"""
|
||||
with open(MASTER_IOC_SUBS_FILE) as f:
|
||||
file_content = f.read()
|
||||
|
||||
quoted_service = f'"{service_name}"'
|
||||
new_row = f' {{ "{{{{ agebd_env }}}}", {quoted_service:<22} , "{starton}", "{autooff}" }}'
|
||||
|
||||
# Use regex to find the last closing curly brace of the configuration block
|
||||
# This targets the line that contains only a lone closing brace, optional spaces, and maybe a comma/semicolon.
|
||||
pattern = r"(\s*\n\s*\}(?:;|,)?\s*$)"
|
||||
|
||||
if re.search(pattern, file_content, re.MULTILINE):
|
||||
# Insert our new row right before that closing brace line
|
||||
updated_content = re.sub(
|
||||
pattern, f"\n{new_row}\\1", file_content, count=1, flags=re.MULTILINE
|
||||
)
|
||||
with open(MASTER_IOC_SUBS_FILE, "w") as f:
|
||||
f.write(updated_content)
|
||||
else:
|
||||
raise ValueError(
|
||||
"Could not locate the closing structure format '}' inside the configuration."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user