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."
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
next_available_ioc_port: 50001
|
||||
services:
|
||||
- name: master
|
||||
ioc_port: 50000
|
||||
status: active
|
||||
- name: master
|
||||
ioc_port: 50000
|
||||
status: active
|
||||
|
||||
+13
-13
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="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"]{
|
||||
<string>A_BD_Master.ui</string>
|
||||
</property>
|
||||
<property name="args">
|
||||
<string/>
|
||||
<string />
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="caLed" name="caled_47">
|
||||
@@ -933,7 +933,7 @@ caLabel[statusTip="Operation"]{
|
||||
<string notr="true">A</string>
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<string notr="true"/>
|
||||
<string notr="true" />
|
||||
</property>
|
||||
<property name="initialValue">
|
||||
<double>1.000000000000000</double>
|
||||
@@ -955,7 +955,7 @@ caLabel[statusTip="Operation"]{
|
||||
<enum>caFrame::IfZero</enum>
|
||||
</property>
|
||||
<property name="visibilityCalc">
|
||||
<string notr="true"/>
|
||||
<string notr="true" />
|
||||
</property>
|
||||
<property name="channel" stdset="0">
|
||||
<string notr="true">Expert-Mode</string>
|
||||
@@ -1015,7 +1015,7 @@ caLabel[statusTip="Operation"]{
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="scriptCommand">
|
||||
<string notr="true">terminator -e "ssh svcusr-sls2hla@sls-vserv-bd-hla01"</string>
|
||||
<string notr="true">terminator -e "ssh svcusr-sls2hla@sls-vserv-bd-hla01"</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
@@ -1056,7 +1056,7 @@ caLabel[statusTip="Operation"]{
|
||||
<string>CONTROL-ONOFF</string>
|
||||
</property>
|
||||
<property name="releaseMessage">
|
||||
<string notr="true"/>
|
||||
<string notr="true" />
|
||||
</property>
|
||||
<property name="pressMessage">
|
||||
<string notr="true">1</string>
|
||||
@@ -1126,10 +1126,10 @@ caLabel[statusTip="Operation"]{
|
||||
</color>
|
||||
</property>
|
||||
<property name="disableChannel" stdset="0">
|
||||
<string/>
|
||||
<string />
|
||||
</property>
|
||||
<property name="releaseMessage">
|
||||
<string notr="true"/>
|
||||
<string notr="true" />
|
||||
</property>
|
||||
<property name="pressMessage">
|
||||
<string notr="true">1</string>
|
||||
@@ -1185,10 +1185,10 @@ caLabel[statusTip="Operation"]{
|
||||
</color>
|
||||
</property>
|
||||
<property name="disableChannel" stdset="0">
|
||||
<string/>
|
||||
<string />
|
||||
</property>
|
||||
<property name="releaseMessage">
|
||||
<string notr="true"/>
|
||||
<string notr="true" />
|
||||
</property>
|
||||
<property name="pressMessage">
|
||||
<string notr="true">1</string>
|
||||
@@ -1303,7 +1303,7 @@ caLabel[statusTip="Operation"]{
|
||||
<header>caScriptButton</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<resources />
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>cacalc_2</sender>
|
||||
@@ -1322,4 +1322,4 @@ caLabel[statusTip="Operation"]{
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user