Skip to content

Commit 197f29f

Browse files
committed
use Version and catch InvalidVersion if cant parse version
1 parent 1331b33 commit 197f29f

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

utils/hotfix_utils/RepoChecker.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55

66
import requests
7-
from packaging.version import Version
7+
from packaging.version import Version, InvalidVersion
88

99
from utils.hotfix_utils.InstrumentChecker import InstrumentChecker
1010

@@ -40,39 +40,41 @@ def get_insts_on_latest_ibex_via_inst_config(self) -> list:
4040
result_list = []
4141
for instrument in instrument_list:
4242
if not instrument["seci"]:
43-
version = requests.get(
43+
version_string = requests.get(
4444
"https://control-svcs.isis.cclrc.ac.uk/git/?p=instconfigs/inst.git;a=blob_plain;f=configurations/config_version.txt;hb=refs/heads/"
4545
+ instrument["hostName"]
4646
).text
47-
version_first_number = int(version.strip().split(".")[0])
48-
if self.debug_mode:
49-
print(
50-
f"DEBUG: Found instrument {instrument['name']} on IBEX version {version_first_number}"
51-
)
52-
if (
53-
version_first_number is not None
54-
and version_first_number != "None"
55-
and version_first_number != ""
56-
):
47+
try:
48+
version = Version(version_string)
49+
50+
if self.debug_mode:
51+
print(
52+
f"DEBUG: Found instrument {instrument['name']} on IBEX version {version}"
53+
)
5754
result_list.append(
5855
{
5956
"hostname": instrument["hostName"],
60-
"version": version_first_number,
57+
"version": version,
6158
}
6259
)
60+
except InvalidVersion as e:
61+
print(
62+
f"Could not parse {instrument['name']}'s Version({version_string}): {str(e)}"
63+
)
6364

6465
# Get the latest versions of IBEX
65-
versions = sorted(set([inst["version"] for inst in result_list]), key=Version)
66-
latest_version = versions[-1]
67-
second_latest_version = versions[-2]
66+
versions = sorted(set([inst["version"] for inst in result_list]))
67+
68+
latest_major_version = versions[-1].major
69+
second_latest_major_version = latest_major_version - 1
70+
print(f"INFO: checking versions {latest_major_version}.x.x and {second_latest_major_version}.x.x")
6871

6972
# filter out the instruments that are not on the latest version
7073
insts_on_latest_ibex = [
7174
inst["hostname"]
7275
for inst in result_list
7376
if (
74-
inst["version"] == latest_version
75-
or inst["version"] == second_latest_version
77+
inst["version"].major in [latest_major_version, second_latest_major_version]
7678
)
7779
]
7880

0 commit comments

Comments
 (0)