diff --git a/shared/workspaces/workspaces/system/services/casa_matrix_service.py b/shared/workspaces/workspaces/system/services/casa_matrix_service.py index 75f146ad11edbdeb7300b0396eaeb89f4a40a4b4..f4c6468c206ec2ea471b388e1fdbfee9e03d9f40 100644 --- a/shared/workspaces/workspaces/system/services/casa_matrix_service.py +++ b/shared/workspaces/workspaces/system/services/casa_matrix_service.py @@ -91,15 +91,8 @@ class CasaMatrixService(CasaMatrixServiceIF): def __init__(self, session: Session): self.session = session - # Used for linking and looking up default CASA versions - self.casa_delivery_dir = CapoConfig().get("edu.nrao.archive.workflow.config.CasaVersions") - self.casa_settings = CapoConfig().settings("edu.nrao.archive.workflow.config.CasaVersions") - # Used for linking and looking up linked CASA versions self.env_dir = str(CapoConfig().profile).replace('dsoc-', '') - self.archive_settings = CapoConfig().settings("edu.nrao.archive.archiveIface") - self.casa_root = self.archive_settings["casa_root"] - self.allow_dev_casa = True if self.archive_settings["allowDevCasaVersions"].lower() == "true" else False # A valid version will cross-check installed versions in the casa_root against allowed versions in the database self.installed_versions = [] @@ -116,12 +109,13 @@ class CasaMatrixService(CasaMatrixServiceIF): flat_versions = [] # casa_root is the directory that contains all installed versions of CASA for all OSes + casa_root = CapoConfig().get("edu.nrao.archive.archiveIface.casa_root") try: - os.listdir(self.casa_root) + os.listdir(casa_root) except FileNotFoundError: raise Exception("Failed to locate CASA root") - if self.allow_dev_casa: + if CapoConfig().get("edu.nrao.archive.archiveIface.allowDevCasaVersions").lower() == "true": prefix_match = RELEASE_CASA_REGEX else: prefix_match = DEV_CASA_REGEX @@ -129,12 +123,12 @@ class CasaMatrixService(CasaMatrixServiceIF): # Start by building a list of version/path dictionaries, extracting the version name from the directory # names in our CASA root. The assumption here is that all these CASA installs are also pipeline installs. # The sorting here will place the newest OS version at the front. - os_dirs = natural_sort(os.listdir(self.casa_root), reverse=True) + os_dirs = natural_sort(os.listdir(casa_root), reverse=True) all_versions = {} for os_dir in os_dirs: # casa_root / RHEL* - os_dir = os.path.join(self.casa_root, os_dir) + os_dir = os.path.join(casa_root, os_dir) if os.path.isdir(os_dir): # casa_root / RHEL* / env os_env_dir = os.path.join(os_dir, self.env_dir) @@ -159,7 +153,7 @@ class CasaMatrixService(CasaMatrixServiceIF): flat_versions.append(v) if not flat_versions: - logger.critical(f"Did not find any links to installed CASA versions in {self.casa_root}") + logger.critical(f"Did not find any links to installed CASA versions in {casa_root}") # Return the version list sorted with newer versions first return sorted(flat_versions, key=lambda v: v["version"], reverse=True) @@ -259,7 +253,7 @@ class CasaMatrixService(CasaMatrixServiceIF): # 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[0]["version"] != version: + if versions and versions[0]["version"] != version: default = self.get_default_version(capability, telescope) if default: for v in versions: @@ -294,7 +288,8 @@ class CasaMatrixService(CasaMatrixServiceIF): key = keys[0] # The CAPO setting is a full path to a CASA installation (this assumes it is installed) - path = self.casa_settings[key] + casa_settings = CapoConfig().settings("edu.nrao.archive.workflow.config.CasaVersions") + path = casa_settings[key] return casa_version_from_path(path) @@ -403,21 +398,26 @@ class CasaMatrixService(CasaMatrixServiceIF): # For logging found_versions = {} + # The directory that contains all installed versions of CASA for all OSes + casa_root = CapoConfig().get("edu.nrao.archive.archiveIface.casa_root") + # The directory where we're generating links to casa_root + casa_delivery_dir = CapoConfig().get("edu.nrao.archive.workflow.config.CasaVersions") + # We're going to add symlinks to a new dir and then replace the old one (in case something goes awry) temp_dir_name = self.env_dir + "-new" # Start with the RHEL* directories in the CASA delivery area - src_os_dirs = sorted([x for x in os.listdir(self.casa_delivery_dir) if "RHEL" in x], reverse=True) + src_os_dirs = sorted([x for x in os.listdir(casa_delivery_dir) if "RHEL" in x], reverse=True) for src_os_dir in src_os_dirs: found_versions[src_os_dir] = [] # casa_root / RHEL* / env - dest_os_dir = os.path.join(self.casa_root, src_os_dir, temp_dir_name) + dest_os_dir = os.path.join(casa_root, src_os_dir, temp_dir_name) if not dry_run and not os.path.exists(dest_os_dir): os.mkdir(dest_os_dir) # casa_delivery_dir / RHEL* / release - src_release_dir = os.path.join(self.casa_delivery_dir, src_os_dir, "release") + src_release_dir = os.path.join(casa_delivery_dir, src_os_dir, "release") if os.path.isdir(src_release_dir): for src_casa_dir in os.listdir(src_release_dir): @@ -434,7 +434,7 @@ class CasaMatrixService(CasaMatrixServiceIF): if not dry_run: # Move all new symlinks into the old directory, overwriting any that existed by the same name # This does not delete any pre-existing links in order to preserve the 'default' link - final_dest = os.path.join(self.casa_root, src_os_dir, self.env_dir) + final_dest = os.path.join(casa_root, src_os_dir, self.env_dir) logger.info(f"Replacing CASA versions in {final_dest}") if not os.path.exists(final_dest): os.makedirs(final_dest)