From bdb9ed9df2bf4cf77cc312b1fa53455930f196bc Mon Sep 17 00:00:00 2001 From: Webb Scales Date: Mon, 24 Jul 2023 17:47:20 -0400 Subject: [PATCH] Pick lint --- lib/pbench/server/cache_manager.py | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/pbench/server/cache_manager.py b/lib/pbench/server/cache_manager.py index 1b80d35cec..7ec409efe9 100644 --- a/lib/pbench/server/cache_manager.py +++ b/lib/pbench/server/cache_manager.py @@ -192,7 +192,7 @@ class Inventory: done. This eliminates interference with later operations. """ - def __init__(self, stream: IO[bytes], tarfile: Optional[tarfile.TarFile] = None): + def __init__(self, stream: IO[bytes], tar_ref: Optional[tarfile.TarFile] = None): """Construct an instance to track extracted inventory This encapsulates many byte stream operations so that it can be used @@ -200,9 +200,9 @@ def __init__(self, stream: IO[bytes], tarfile: Optional[tarfile.TarFile] = None) Args: stream: the data stream of a specific tarball member - tarfile: the TarFile object + tar_ref: the TarFile object """ - self.tarfile = tarfile + self.tarfile = tar_ref self.stream = stream def close(self): @@ -506,7 +506,7 @@ def get_info(self, path: Path) -> JSONOBJECT: return fd_info @staticmethod - def extract(tarball_path: Path, path: Path) -> Inventory: + def extract(tarball_path: Path, path: str) -> Inventory: """Returns a file stream for a file within a tarball Args: @@ -552,7 +552,7 @@ def get_inventory(self, path: str) -> Optional[JSONOBJECT]: } else: file_path = Path(self.name) / path - stream = Tarball.extract(self.tarball_path, file_path) + stream = Tarball.extract(self.tarball_path, str(file_path)) info = {"name": file_path.name, "type": CacheType.FILE, "stream": stream} return info @@ -636,7 +636,8 @@ def unpack(self): self.cache.mkdir(parents=True) try: - tar_command = f"tar -x --no-same-owner --delay-directory-restore --force-local --file='{str(self.tarball_path)}'" + tar_command = "tar -x --no-same-owner --delay-directory-restore " + tar_command += f"--force-local --file='{str(self.tarball_path)}'" self.subprocess_run( tar_command, self.cache, TarballUnpackError, self.tarball_path ) @@ -770,18 +771,18 @@ def create( controller_dir.mkdir(exist_ok=True, mode=0o755) return cls(controller_dir, options.CACHE, logger) - def create_tarball(self, tarfile: Path) -> Tarball: + def create_tarball(self, tarfile_path: Path) -> Tarball: """Create a new dataset tarball object under the controller The new tarball object is linked to the controller so we can find it. Args: - tarfile: Path to source tarball file + tarfile_path: Path to source tarball file Returns: Tarball object """ - tarball = Tarball.create(tarfile, self) + tarball = Tarball.create(tarfile_path, self) self.datasets[tarball.resource_id] = tarball self.tarballs[tarball.name] = tarball return tarball @@ -1008,12 +1009,12 @@ def find_dataset(self, dataset_id: str) -> Tarball: # The dataset isn't already known; so search for it in the ARCHIVE tree # and (if found) discover the controller containing that dataset. - for dir in self.archive_root.iterdir(): - if dir.is_dir() and dir.name != self.TEMPORARY: - for file in dir.glob(f"*{Dataset.TARBALL_SUFFIX}"): + for dir_entry in self.archive_root.iterdir(): + if dir_entry.is_dir() and dir_entry.name != self.TEMPORARY: + for file in dir_entry.glob(f"*{Dataset.TARBALL_SUFFIX}"): md5 = get_tarball_md5(file) if md5 == dataset_id: - self._add_controller(dir) + self._add_controller(dir_entry) return self.datasets[dataset_id] raise TarballNotFound(dataset_id) @@ -1037,7 +1038,7 @@ def find_dataset(self, dataset_id: str) -> Tarball: # Remove the tarball and MD5 file from ARCHIVE after uncaching the # unpacked directory tree. - def create(self, tarfile: Path) -> Tarball: + def create(self, tarfile_path: Path) -> Tarball: """Bring a new tarball under cache manager management. Move a dataset tarball and companion MD5 file into the specified @@ -1045,8 +1046,7 @@ def create(self, tarfile: Path) -> Tarball: necessary. Args: - controller: associated controller name - tarfile: dataset tarball path + tarfile_path: dataset tarball path Raises BadDirpath: Failure on extracting the file from tarball @@ -1059,19 +1059,19 @@ def create(self, tarfile: Path) -> Tarball: Tarball object """ try: - metadata = Tarball._get_metadata(tarfile) + metadata = Tarball._get_metadata(tarfile_path) if metadata: controller_name = metadata["run"]["controller"] else: controller_name = "unknown" except Exception as exc: - raise MetadataError(tarfile, exc) + raise MetadataError(tarfile_path, exc) if not controller_name: - raise MetadataError(tarfile, "no controller value") - if not tarfile.is_file(): - raise BadFilename(tarfile) - name = Dataset.stem(tarfile) + raise MetadataError(tarfile_path, ValueError("no controller value")) + if not tarfile_path.is_file(): + raise BadFilename(tarfile_path) + name = Dataset.stem(tarfile_path) if name in self.tarballs: raise DuplicateTarball(name) if controller_name in self.controllers: @@ -1079,7 +1079,7 @@ def create(self, tarfile: Path) -> Tarball: else: controller = Controller.create(controller_name, self.options, self.logger) self.controllers[controller_name] = controller - tarball = controller.create_tarball(tarfile) + tarball = controller.create_tarball(tarfile_path) tarball.metadata = metadata self.tarballs[tarball.name] = tarball self.datasets[tarball.resource_id] = tarball @@ -1122,7 +1122,7 @@ def get_inventory(self, dataset_id: str, target: str) -> Optional[JSONOBJECT]: } Args: - dataset: Dataset resource ID + dataset_id: Dataset resource ID target: relative file path within the tarball Returns: