diff --git a/cli/src/core/models.py b/cli/src/core/models.py index 808c0a0..19d2377 100644 --- a/cli/src/core/models.py +++ b/cli/src/core/models.py @@ -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) diff --git a/cli/src/core/service_creator.py b/cli/src/core/service_creator.py index ba8ea67..1d45bf4 100644 --- a/cli/src/core/service_creator.py +++ b/cli/src/core/service_creator.py @@ -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." - ) diff --git a/config/services_registry.yml b/config/services_registry.yml index 48cbad7..21b4297 100644 --- a/config/services_registry.yml +++ b/config/services_registry.yml @@ -1,5 +1,5 @@ next_available_ioc_port: 50001 services: - - name: master - ioc_port: 50000 - status: active +- name: master + ioc_port: 50000 + status: active diff --git a/qt/A_BD_ServiceManager.ui b/qt/A_BD_ServiceManager.ui index 9d8b5ec..329f51a 100644 --- a/qt/A_BD_ServiceManager.ui +++ b/qt/A_BD_ServiceManager.ui @@ -1,4 +1,4 @@ - + MainWindow @@ -29,7 +29,7 @@ QMainWindow#MainWindow[transparent=true], QWidget#Form[transparent=true], QDialo /* Title */ /*-----------------------------------------------*/ /* Operation panels */ -caLabel[statusTip="Operation"]{ +caLabel[statusTip="Operation"]{ color: rgba(0, 0, 0, 255); font: bold 18pt; font-family: Sans Serif; @@ -543,7 +543,7 @@ caLabel[statusTip="Operation"]{ A_BD_Master.ui - + @@ -933,7 +933,7 @@ caLabel[statusTip="Operation"]{ A - + 1.000000000000000 @@ -955,7 +955,7 @@ caLabel[statusTip="Operation"]{ caFrame::IfZero - + Expert-Mode @@ -1015,7 +1015,7 @@ caLabel[statusTip="Operation"]{ false - terminator -e "ssh svcusr-sls2hla@sls-vserv-bd-hla01" + terminator -e "ssh svcusr-sls2hla@sls-vserv-bd-hla01" @@ -1056,7 +1056,7 @@ caLabel[statusTip="Operation"]{ CONTROL-ONOFF - + 1 @@ -1126,10 +1126,10 @@ caLabel[statusTip="Operation"]{ - + - + 1 @@ -1185,10 +1185,10 @@ caLabel[statusTip="Operation"]{ - + - + 1 @@ -1303,7 +1303,7 @@ caLabel[statusTip="Operation"]{
caScriptButton
- + cacalc_2 @@ -1322,4 +1322,4 @@ caLabel[statusTip="Operation"]{ -
+ \ No newline at end of file