From a65d8d82f598a5a281f1b0ea8a89f3ad01a78642 Mon Sep 17 00:00:00 2001 From: Jack Harper Date: Fri, 6 Dec 2024 15:03:09 +0000 Subject: [PATCH 1/4] optionally exclude macro values from IOCs for the web dashboard --- BlockServer/config/ioc.py | 4 ++-- BlockServer/core/config_holder.py | 10 +++++----- block_server.py | 12 +++++++++++- server_common/pv_names.py | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/BlockServer/config/ioc.py b/BlockServer/config/ioc.py index 8ca9675b..b296d2be 100644 --- a/BlockServer/config/ioc.py +++ b/BlockServer/config/ioc.py @@ -107,7 +107,7 @@ def _dict_to_list(in_dict: Dict[str, Any]) -> List[Any]: def __str__(self) -> str: return f"{self.__class__.__name__}(name={self.name}, component={self.component})" - def to_dict(self) -> Dict[str, Union[str, bool, List[Any]]]: + def to_dict(self, exclude_macros: bool = False) -> Dict[str, Union[str, bool, List[Any]]]: """Puts the IOC's details into a dictionary. Returns: @@ -120,7 +120,7 @@ def to_dict(self) -> Dict[str, Union[str, bool, List[Any]]]: "simlevel": self.simlevel, "pvs": self._dict_to_list(self.pvs), "pvsets": self._dict_to_list(self.pvsets), - "macros": self._dict_to_list(self.macros), + "macros": self._dict_to_list(self.macros) if not exclude_macros else [], "component": self.component, "remotePvPrefix": self.remotePvPrefix, } diff --git a/BlockServer/core/config_holder.py b/BlockServer/core/config_holder.py index 417ac5b6..09bcb76a 100644 --- a/BlockServer/core/config_holder.py +++ b/BlockServer/core/config_holder.py @@ -323,7 +323,7 @@ def _add_ioc( f"Can't add IOC '{name}' to component '{component}': component does not exist" ) - def get_config_details(self) -> Dict[str, Any]: + def get_config_details(self, exclude_macros: bool = False) -> Dict[str, Any]: """Get the details of the configuration. Returns: @@ -333,8 +333,8 @@ def get_config_details(self) -> Dict[str, Any]: "blocks": self._blocks_to_list(True), "groups": self._groups_to_list(), "iocs": self._iocs_to_list(), - "component_iocs": self._iocs_to_list_with_components(), - "components": self._comps_to_list(), # Just return the names of the components + "component_iocs": self._iocs_to_list_with_components(exclude_macros), + "components": self._comps_to_list(exclude_macros), # Just return the names of the components "name": self._config.get_name(), "description": self._config.meta.description, "synoptic": self._config.meta.synoptic, @@ -402,10 +402,10 @@ def _groups_to_list(self): grps.append(groups[GRP_NONE.lower()].to_dict()) return grps - def _iocs_to_list(self): + def _iocs_to_list(self, exclude_macros: bool = False): return [ioc.to_dict() for ioc in self._config.iocs.values()] - def _iocs_to_list_with_components(self): + def _iocs_to_list_with_components(self, exclude_macros: bool = False): ioc_list = self._iocs_to_list() for component in self._components.values(): diff --git a/block_server.py b/block_server.py index f9a883d0..eb2cf332 100644 --- a/block_server.py +++ b/block_server.py @@ -84,7 +84,7 @@ initial_dbs = { BlockserverPVNames.BLOCKNAMES: char_waveform(16000), BlockserverPVNames.HEARTBEAT: {"type": "int", "count": 1, "value": [0]}, - BlockserverPVNames.BLOCK_DETAILS: char_waveform(16000), + BlockserverPVNames.WD_CONF_DETAILS: char_waveform(16000), BlockserverPVNames.GROUPS: char_waveform(16000), BlockserverPVNames.COMPS: char_waveform(16000), BlockserverPVNames.LOAD_CONFIG: char_waveform(1000), @@ -465,6 +465,7 @@ def _initialise_config(self, full_init=False): self.update_blocks_monitors() self.update_get_details_monitors() + self.update_wd_details_monitors() self.update_curr_config_name_monitors() self._active_configserver.update_archiver(full_init) for handler in self.on_the_fly_handlers: @@ -656,6 +657,15 @@ def update_get_details_monitors(self): ) self.updatePVs() + def update_wd_details_monitors(self): + """Updates the monitor for the active configuration, so the clients can see any changes.""" + with self.monitor_lock: + config_details_json = convert_to_json(self._active_configserver.get_config_details(exclude_macros=True)) + self.setParam( + BlockserverPVNames.WD_CONF_DETAILS, compress_and_hex(config_details_json) + ) + self.updatePVs() + def update_curr_config_name_monitors(self): """Updates the monitor for the active configuration name, so the clients can see any changes.""" with self.monitor_lock: diff --git a/server_common/pv_names.py b/server_common/pv_names.py index 4e82fdce..cea8b350 100644 --- a/server_common/pv_names.py +++ b/server_common/pv_names.py @@ -46,7 +46,7 @@ class BlockserverPVNames: """Holds and manages blockserver PV names""" BLOCKNAMES = prepend_blockserver("BLOCKNAMES") - BLOCK_DETAILS = prepend_blockserver("BLOCK_DETAILS") + WD_CONF_DETAILS = prepend_blockserver("WD_CONF_DETAILS") BLOCK_RULES = prepend_blockserver("BLOCK_RULES") GROUPS = prepend_blockserver("GROUPS") GROUP_RULES = prepend_blockserver("GROUP_RULES") From 79a8c9a1546383f042f78ae59196d2d2d9f00b7e Mon Sep 17 00:00:00 2001 From: Jack Harper Date: Fri, 6 Dec 2024 15:30:02 +0000 Subject: [PATCH 2/4] even simpler method of doing this --- BlockServer/config/ioc.py | 4 ++-- BlockServer/core/config_holder.py | 10 +++++----- block_server.py | 6 +++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/BlockServer/config/ioc.py b/BlockServer/config/ioc.py index b296d2be..8ca9675b 100644 --- a/BlockServer/config/ioc.py +++ b/BlockServer/config/ioc.py @@ -107,7 +107,7 @@ def _dict_to_list(in_dict: Dict[str, Any]) -> List[Any]: def __str__(self) -> str: return f"{self.__class__.__name__}(name={self.name}, component={self.component})" - def to_dict(self, exclude_macros: bool = False) -> Dict[str, Union[str, bool, List[Any]]]: + def to_dict(self) -> Dict[str, Union[str, bool, List[Any]]]: """Puts the IOC's details into a dictionary. Returns: @@ -120,7 +120,7 @@ def to_dict(self, exclude_macros: bool = False) -> Dict[str, Union[str, bool, Li "simlevel": self.simlevel, "pvs": self._dict_to_list(self.pvs), "pvsets": self._dict_to_list(self.pvsets), - "macros": self._dict_to_list(self.macros) if not exclude_macros else [], + "macros": self._dict_to_list(self.macros), "component": self.component, "remotePvPrefix": self.remotePvPrefix, } diff --git a/BlockServer/core/config_holder.py b/BlockServer/core/config_holder.py index 09bcb76a..417ac5b6 100644 --- a/BlockServer/core/config_holder.py +++ b/BlockServer/core/config_holder.py @@ -323,7 +323,7 @@ def _add_ioc( f"Can't add IOC '{name}' to component '{component}': component does not exist" ) - def get_config_details(self, exclude_macros: bool = False) -> Dict[str, Any]: + def get_config_details(self) -> Dict[str, Any]: """Get the details of the configuration. Returns: @@ -333,8 +333,8 @@ def get_config_details(self, exclude_macros: bool = False) -> Dict[str, Any]: "blocks": self._blocks_to_list(True), "groups": self._groups_to_list(), "iocs": self._iocs_to_list(), - "component_iocs": self._iocs_to_list_with_components(exclude_macros), - "components": self._comps_to_list(exclude_macros), # Just return the names of the components + "component_iocs": self._iocs_to_list_with_components(), + "components": self._comps_to_list(), # Just return the names of the components "name": self._config.get_name(), "description": self._config.meta.description, "synoptic": self._config.meta.synoptic, @@ -402,10 +402,10 @@ def _groups_to_list(self): grps.append(groups[GRP_NONE.lower()].to_dict()) return grps - def _iocs_to_list(self, exclude_macros: bool = False): + def _iocs_to_list(self): return [ioc.to_dict() for ioc in self._config.iocs.values()] - def _iocs_to_list_with_components(self, exclude_macros: bool = False): + def _iocs_to_list_with_components(self): ioc_list = self._iocs_to_list() for component in self._components.values(): diff --git a/block_server.py b/block_server.py index eb2cf332..ceb2b1f8 100644 --- a/block_server.py +++ b/block_server.py @@ -19,6 +19,7 @@ import os import sys import traceback +from distutils.command.config import config from server_common.channel_access import ManagerModeRequiredException, verify_manager_mode @@ -660,7 +661,10 @@ def update_get_details_monitors(self): def update_wd_details_monitors(self): """Updates the monitor for the active configuration, so the clients can see any changes.""" with self.monitor_lock: - config_details_json = convert_to_json(self._active_configserver.get_config_details(exclude_macros=True)) + config_details = self._active_configserver.get_config_details(exclude_macros=True) + config_details = config_details.pop("component_iocs") + config_details = config_details.pop("iocs") + config_details_json = convert_to_json(config_details) self.setParam( BlockserverPVNames.WD_CONF_DETAILS, compress_and_hex(config_details_json) ) From 6e2ebb26eba09d42365ee3fd209f0677b222f24e Mon Sep 17 00:00:00 2001 From: Jack Harper Date: Fri, 6 Dec 2024 15:50:38 +0000 Subject: [PATCH 3/4] removed mistakenly added import --- block_server.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block_server.py b/block_server.py index ceb2b1f8..7482dc6d 100644 --- a/block_server.py +++ b/block_server.py @@ -19,7 +19,6 @@ import os import sys import traceback -from distutils.command.config import config from server_common.channel_access import ManagerModeRequiredException, verify_manager_mode @@ -659,11 +658,12 @@ def update_get_details_monitors(self): self.updatePVs() def update_wd_details_monitors(self): - """Updates the monitor for the active configuration, so the clients can see any changes.""" + """Updates the monitor for the active configuration, so the web dashboard can see any changes.""" with self.monitor_lock: config_details = self._active_configserver.get_config_details(exclude_macros=True) - config_details = config_details.pop("component_iocs") - config_details = config_details.pop("iocs") + keys_to_exclude = ["component_iocs", "iocs"] + for k in keys_to_exclude: + config_details.pop(k) config_details_json = convert_to_json(config_details) self.setParam( BlockserverPVNames.WD_CONF_DETAILS, compress_and_hex(config_details_json) From d6c4e5f01d82bf8f448ec94772689f4166115df1 Mon Sep 17 00:00:00 2001 From: Jack Harper Date: Fri, 6 Dec 2024 15:58:31 +0000 Subject: [PATCH 4/4] use dict comprehension instead --- block_server.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/block_server.py b/block_server.py index 7482dc6d..adf96984 100644 --- a/block_server.py +++ b/block_server.py @@ -660,11 +660,7 @@ def update_get_details_monitors(self): def update_wd_details_monitors(self): """Updates the monitor for the active configuration, so the web dashboard can see any changes.""" with self.monitor_lock: - config_details = self._active_configserver.get_config_details(exclude_macros=True) - keys_to_exclude = ["component_iocs", "iocs"] - for k in keys_to_exclude: - config_details.pop(k) - config_details_json = convert_to_json(config_details) + config_details_json = convert_to_json({k: v for k, v in self._active_configserver.get_config_details(exclude_macros=True).items() if k not in ["component_iocs", "iocs"]}) self.setParam( BlockserverPVNames.WD_CONF_DETAILS, compress_and_hex(config_details_json) )