Skip to content
Snippets Groups Projects

feat(spack_operation): implement setup_spack_env functionality

1 unresolved thread
Compare and
38 files
+ 2871
48
Compare changes
  • Side-by-side
  • Inline
Files
38
import glob
import os
import time
from os.path import join
from pathlib import Path
import oras.client
from pathlib import Path
from dedal.build_cache.BuildCacheManagerInterface import BuildCacheManagerInterface
from dedal.logger.logger_builder import get_logger
from dedal.utils.utils import clean_up
class BuildCacheManager(BuildCacheManagerInterface):
@@ -113,7 +113,49 @@ class BuildCacheManager(BuildCacheManagerInterface):
if tags is not None:
try:
self._client.delete_tags(self._oci_registry_path, tags)
self._logger.info(f"Successfully deleted all artifacts form OCI registry.")
self._logger.info("Successfully deleted all artifacts form OCI registry.")
except RuntimeError as e:
self._logger.error(
f"Failed to delete artifacts: {e}")
def __log_warning_if_needed(self, warn_message: str, items: list[str]) -> None:
"""Logs a warning message if the number of items is greater than 1. (Private function)
This method logs a warning message using the provided message and items if the list of items has more than one element.
Args:
warn_message (str): The warning message to log.
items (list[str]): The list of items to include in the log message.
"""
if len(items) > 1:
self._logger.warning(warn_message, items, items[0])
def get_public_key_from_cache(self, build_cache_dir: str | None) -> str | None:
"""Retrieves the public key from the build cache.
This method searches for the public key within the specified build cache directory.
Args:
build_cache_dir (str | None): The path to the build cache directory.
Returns:
str | None: The path to the public key file if found, otherwise None.
"""
if not build_cache_dir or not os.path.exists(build_cache_dir):
self._logger.warning("Build cache directory does not exist!")
return None
pgp_folders = glob.glob(f"{build_cache_dir}/**/_pgp", recursive=True)
if not pgp_folders:
self._logger.warning("No _pgp folder found in the build cache!")
return None
self.__log_warning_if_needed(
"More than one PGP folders found in the build cache: %s, using the first one in the list: %s", pgp_folders)
pgp_folder = pgp_folders[0]
key_files = glob.glob(join(pgp_folder, "**"))
if not key_files:
self._logger.warning("No PGP key files found in the build cache!")
return None
self.__log_warning_if_needed(
"More than one PGP key files found in the build cache: %s, using the first one in the list: %s", key_files)
return key_files[0]