From 7bc6c756de57915f80c90b09ad0180ca7b749e48 Mon Sep 17 00:00:00 2001 From: LilithCole Date: Fri, 9 Aug 2024 15:38:05 +0100 Subject: [PATCH 1/3] add upgrade step for CAENV895 --- src/upgrade_step_from_14p0p0.py | 28 ++++++++++++++++++++++++++++ upgrade.py | 4 +++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/upgrade_step_from_14p0p0.py diff --git a/src/upgrade_step_from_14p0p0.py b/src/upgrade_step_from_14p0p0.py new file mode 100644 index 0000000..f7119f9 --- /dev/null +++ b/src/upgrade_step_from_14p0p0.py @@ -0,0 +1,28 @@ +import socket + +from src.common_upgrades.change_macros_in_xml import ChangeMacrosInXML +from src.common_upgrades.utils.macro import Macro +from src.upgrade_step import UpgradeStep + + +class UpgradeFrom14p0p0(UpgradeStep): + """Set CARDS0 macro for all instruments except ARGUS/CHRONUS in which it is configured differently already""" + + def perform(self, file_access, logger): + try: + hostname = socket.gethostname() + # Make sure we do not perform this on ARGUS/CHRONUS where the macro is already present + if hostname not in ["NDXARGUS", "NDXCHRONUS"]: + ioc_name = "CAENV895" + change_macros_in_xml = ChangeMacrosInXML(file_access, logger) + change_macros_in_xml.add_macro( + ioc_name, + Macro("CARDS", "6"), + "^[0-9]+$", + "Number of cards in crate 0, leave blank if this crate does not exist", + "Yes", + ) + return 0 + except Exception as e: + logger.error("Unable to perform upgrade, caught error: {}".format(e)) + return 1 diff --git a/upgrade.py b/upgrade.py index 945adc3..3a82e8b 100644 --- a/upgrade.py +++ b/upgrade.py @@ -20,6 +20,7 @@ from src.upgrade_step_from_12p0p1 import AddOscCollimMovingIndicator from src.upgrade_step_from_12p0p2 import UpgradeFrom12p0p2 from src.upgrade_step_from_12p0p3 import UpgradeFrom12p0p3 +from src.upgrade_step_from_14p0p0 import UpgradeFrom14p0p0 from src.upgrade_step_noop import UpgradeStepNoOp # A list of upgrade step tuples tuple is name of version to apply the upgrade to and upgrade class. @@ -70,7 +71,8 @@ ("12.0.3", UpgradeFrom12p0p3()), ("13.0.0", UpgradeStepNoOp()), ("13.0.1", UpgradeStepNoOp()), - ("14.0.0", None), + ("14.0.0", UpgradeFrom14p0p0()), + ("15.0.0", None) # to add step see https://github.com/ISISComputingGroup/ibex_developers_manual/wiki/Config-Upgrader#adding-an-upgrade-step ] From 17f15e986ca5aed807b189ca4bee75e9d233fa44 Mon Sep 17 00:00:00 2001 From: LilithCole Date: Fri, 9 Aug 2024 15:53:20 +0100 Subject: [PATCH 2/3] fix ruff errors --- src/upgrade_step_from_14p0p0.py | 7 +++++-- upgrade.py | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/upgrade_step_from_14p0p0.py b/src/upgrade_step_from_14p0p0.py index f7119f9..0781990 100644 --- a/src/upgrade_step_from_14p0p0.py +++ b/src/upgrade_step_from_14p0p0.py @@ -2,13 +2,16 @@ from src.common_upgrades.change_macros_in_xml import ChangeMacrosInXML from src.common_upgrades.utils.macro import Macro +from src.file_access import FileAccess +from src.local_logger import LocalLogger from src.upgrade_step import UpgradeStep class UpgradeFrom14p0p0(UpgradeStep): - """Set CARDS0 macro for all instruments except ARGUS/CHRONUS in which it is configured differently already""" + """Set CARDS0 macro for all instruments, + except ARGUS/CHRONUS in which it is configured differently already""" - def perform(self, file_access, logger): + def perform(self, file_access: FileAccess, logger: LocalLogger) -> int: try: hostname = socket.gethostname() # Make sure we do not perform this on ARGUS/CHRONUS where the macro is already present diff --git a/upgrade.py b/upgrade.py index 3a82e8b..5813dee 100644 --- a/upgrade.py +++ b/upgrade.py @@ -73,7 +73,8 @@ ("13.0.1", UpgradeStepNoOp()), ("14.0.0", UpgradeFrom14p0p0()), ("15.0.0", None) - # to add step see https://github.com/ISISComputingGroup/ibex_developers_manual/wiki/Config-Upgrader#adding-an-upgrade-step + # to add step see + # https://github.com/ISISComputingGroup/ibex_developers_manual/wiki/Config-Upgrader#adding-an-upgrade-step ] if __name__ == "__main__": From 1d45e1a54eeec05bcf79e19195a9495d9ceb1f61 Mon Sep 17 00:00:00 2001 From: LilithCole Date: Fri, 9 Aug 2024 16:00:34 +0100 Subject: [PATCH 3/3] ruff reformat --- src/upgrade_step_from_14p0p0.py | 2 +- upgrade.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/upgrade_step_from_14p0p0.py b/src/upgrade_step_from_14p0p0.py index 0781990..b2b76dd 100644 --- a/src/upgrade_step_from_14p0p0.py +++ b/src/upgrade_step_from_14p0p0.py @@ -9,7 +9,7 @@ class UpgradeFrom14p0p0(UpgradeStep): """Set CARDS0 macro for all instruments, - except ARGUS/CHRONUS in which it is configured differently already""" + except ARGUS/CHRONUS in which it is configured differently already""" def perform(self, file_access: FileAccess, logger: LocalLogger) -> int: try: diff --git a/upgrade.py b/upgrade.py index 5813dee..4837eab 100644 --- a/upgrade.py +++ b/upgrade.py @@ -72,7 +72,7 @@ ("13.0.0", UpgradeStepNoOp()), ("13.0.1", UpgradeStepNoOp()), ("14.0.0", UpgradeFrom14p0p0()), - ("15.0.0", None) + ("15.0.0", None), # to add step see # https://github.com/ISISComputingGroup/ibex_developers_manual/wiki/Config-Upgrader#adding-an-upgrade-step ]