Skip to content
Snippets Groups Projects
Commit 694194c6 authored by Daniel Nemergut's avatar Daniel Nemergut
Browse files

Corrected moving the recommended version to the front of the list and properly...

Corrected moving the recommended version to the front of the list and properly sorted the flattened installed versions list by the version names to put the most recent at the top
parent 99485b78
No related branches found
No related tags found
2 merge requests!1706merge 2.8.4 to main,!1670WS-1405 CASA matrix service
Pipeline #16027 passed
......@@ -103,11 +103,11 @@ class CasaMatrixService(CasaMatrixServiceIF):
"""
Makes a list of all CASA versions found within the casa_root for the current profile.
Each 'version' will be a dict containing the version (casa_version | pipeline_version) and path.
The list is first organized by OS versions and then flattened to only use old OSes as fall
The list is first organized by OS versions and then flattened to only use old OSes as fallbacks.
:return: A flattened list of the installed CASA versions + paths
"""
versions = []
flat_versions = []
# casa_root is the directory that contains all installed versions of CASA for all OSes
try:
......@@ -142,18 +142,20 @@ class CasaMatrixService(CasaMatrixServiceIF):
# Flatten the versions such that versions for the most recent OS will be preferred but will fall back to other
# OSes if necessary
for version_list in all_versions.values():
if len(versions) == 0:
versions = version_list
for os_versions in all_versions.values():
if len(flat_versions) == 0:
flat_versions = os_versions
else:
for v in version_list:
if v not in versions:
versions.append(v)
for v in os_versions:
# Check if this version has already been added for a more recent OS
if v not in flat_versions and not any(v["version"] in fv["version"] for fv in flat_versions):
flat_versions.append(v)
if not versions:
if not flat_versions:
logger.critical(f"Did not find any links to installed CASA versions in {self.casa_root}")
return versions
# Return the version list sorted with newer versions first
return list(sorted(flat_versions, key=lambda v: v['version'], reverse=True))
def fetch_allowed_versions(self, capability: str) -> list[str]:
"""
......@@ -189,21 +191,6 @@ class CasaMatrixService(CasaMatrixServiceIF):
return ret
def get_installed_version_by_basename(self, basename: str) -> dict[str, str]:
"""
Gets the installed version string + path for a given basename string.
:param basename: CASA + pipeline basename as a string
:return: Dict containing the version string and installation path
"""
ret = {}
for v in self.installed_versions:
if os.path.basename(v["path"]) == basename:
ret = v
return ret
def is_allowed(self, version: str, capability: str) -> bool:
"""
Checks if the version is valid for the given capability.
......@@ -252,21 +239,21 @@ class CasaMatrixService(CasaMatrixServiceIF):
rec_version = version if version else self.get_default_version(capability, telescope)
# Installed versions are a flat list of dicts containing version names and paths
# Installed versions are a sorted, flattened list of dicts containing version names and paths
self.installed_versions = self.find_installed_versions()
# Allowed versions are a dict of capabilities mapping to lists of version names
self.allowed_versions = self.fetch_allowed_versions(capability)
# Add any versions that are both allowed and installed to the list
for allowed_version in self.allowed_versions:
installed_version = self.get_installed_version_by_basename(allowed_version)
if installed_version:
# Put the recommended version as first in the list
if installed_version["version"] == rec_version:
versions.insert(0, installed_version)
else:
versions.append(installed_version)
# Add any versions that are both allowed and installed to the list, keeping it sorted by version names
for installed_version in self.installed_versions:
if os.path.basename(installed_version["path"]) in self.allowed_versions:
versions.append(installed_version)
# Put the recommended version as first in the list
for v in versions:
if v["version"] == rec_version:
versions.insert(0, versions.pop(versions.index(v)))
logger.debug(f"Found CASA versions for {capability}: {versions}")
......@@ -274,7 +261,7 @@ class CasaMatrixService(CasaMatrixServiceIF):
def get_default_version(
self, capability: str = DEFAULT_CAPABILITY, telescope: str | None = DEFAULT_TELESCOPE
) -> dict[str, str]:
) -> str:
"""
Gets the default CASA version from CAPO for the given capability (the std_calibration capability is default).
......@@ -294,7 +281,7 @@ class CasaMatrixService(CasaMatrixServiceIF):
# The CAPO setting is a full path to a CASA installation (this assumes it is installed)
path = self.casa_settings[key]
return dict(version=casa_version_from_path(path), path=path)
return casa_version_from_path(path)
def get_recipe(self, capability: str) -> str | None:
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment