diff --git a/shared/workspaces/workspaces/system/services/casa_matrix_service.py b/shared/workspaces/workspaces/system/services/casa_matrix_service.py index 3c4fb0eb2876159af78378aeb9e61da4f7291304..de5fa6c9c10cdfd8eaf064a1de2cabf7d39661b8 100644 --- a/shared/workspaces/workspaces/system/services/casa_matrix_service.py +++ b/shared/workspaces/workspaces/system/services/casa_matrix_service.py @@ -44,6 +44,7 @@ DEV_CASA_REGEX = r"^casa-[0-9\.\-]*(pipeline-)?[^tp]" CASA_VERSION_REGEX = r"[a-zA-Z\-]+([\d]+(\.[\d]+){2}(-[\d]+){0,1}).*" PIPELINE_VERSION_REGEX = r".*([\d]{4}(\.[\d]+){3}).*" EL_SUFFIX_REGEX = r"[\.\-]el[0-9]+$" +IGNORE_REGEX = r"\.|\-" def casa_version_from_path(path: str) -> str: @@ -70,8 +71,7 @@ def casa_version_from_path(path: str) -> str: pv_search = re.search(PIPELINE_VERSION_REGEX, path) if cv_search: - # Replace last '-' in the directory name with '.' to match versions stored in the database - casa_version = ".".join(cv_search.group(1).rsplit("-", 1)) + casa_version = cv_search.group(1) if pv_search: # Strip el* from the release name (used to be a thing) pipeline_version = re.sub(EL_SUFFIX_REGEX, "", pv_search.group(1)) @@ -94,22 +94,23 @@ def natural_sort(in_list: list, reverse: bool = False) -> list: return sorted(in_list, key=alphanum_key, reverse=reverse) -def versions_match(db_ver: str, dir_ver: str) -> bool: +def versions_match(req_v: str, dir_v: str) -> bool: """ - Compares CASA+pipeline version formats stored in the database vs. those installed. + Compares CASA+pipeline version formats stored in the request vs installed. - :param db_ver: Version coming from the database - :param dir_ver: Version coming from a directory path + :param req_v: Version coming from the request + :param dir_v: Version coming from a directory path :return: True if the CASA+pipeline versions match """ - if db_ver == dir_ver: - return True + req_cv, req_pv = req_v.split("|") + dir_cv, dir_pv = dir_v.split("|") - # Ignore comparing pipeline versions if they don't exist in the installed version's name - if dir_ver.split("|")[1] == "default": - return db_ver.split("|")[0] == dir_ver.split("|")[0] + # Ignore comparing '.' and '-' characters because they like to be used interchangeably + req_cv = re.sub(IGNORE_REGEX, "", req_cv) + dir_cv = re.sub(IGNORE_REGEX, "", dir_cv) - return False + # Ignore comparing pipeline versions if they don't exist in the installed version's name + return req_cv == dir_cv and (dir_pv == "default" or req_pv == dir_pv) class CasaMatrixService(CasaMatrixServiceIF): @@ -270,14 +271,14 @@ class CasaMatrixService(CasaMatrixServiceIF): versions.append(installed_version) # Put the requested version as first in the list if it's valid - for v in versions: - # TODO: This needs to be converted if the pipeline number is missing from the directory name like 5.1.1-5 - if versions_match(version, v["version"]): - versions.insert(0, versions.pop(versions.index(v))) + if version: + for v in versions: + if versions_match(version, v["version"]): + versions.insert(0, versions.pop(versions.index(v))) # If the requested version is invalid, put the default as first in the list # If the default is invalid, the newest version will be first in the list - if versions and versions_match(version, versions[0]["version"]): + if versions and (not version or not versions_match(version, versions[0]["version"])): default = self.get_default_version(capability, telescope) if default: for v in versions: