Skip to content

Commit

Permalink
Pick lint
Browse files Browse the repository at this point in the history
  • Loading branch information
webbnh committed Jul 24, 2023
1 parent d0e8ad4 commit bdb9ed9
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions lib/pbench/server/cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ 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
as if it were a byte stream.
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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -1037,16 +1038,15 @@ 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
controller directory. The controller directory will be created if
necessary.
Args:
controller: associated controller name
tarfile: dataset tarball path
tarfile_path: dataset tarball path
Raises
BadDirpath: Failure on extracting the file from tarball
Expand All @@ -1059,27 +1059,27 @@ 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:
controller = self.controllers[controller_name]
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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bdb9ed9

Please sign in to comment.