@@ -192,17 +192,17 @@ class Inventory:
192192 done. This eliminates interference with later operations.
193193 """
194194
195- def __init__ (self , stream : IO [bytes ], tarfile : Optional [tarfile .TarFile ] = None ):
195+ def __init__ (self , stream : IO [bytes ], tar_ref : Optional [tarfile .TarFile ] = None ):
196196 """Construct an instance to track extracted inventory
197197
198198 This encapsulates many byte stream operations so that it can be used
199199 as if it were a byte stream.
200200
201201 Args:
202202 stream: the data stream of a specific tarball member
203- tarfile : the TarFile object
203+ tar_ref : the TarFile object
204204 """
205- self .tarfile = tarfile
205+ self .tarfile = tar_ref
206206 self .stream = stream
207207
208208 def close (self ):
@@ -506,7 +506,7 @@ def get_info(self, path: Path) -> JSONOBJECT:
506506 return fd_info
507507
508508 @staticmethod
509- def extract (tarball_path : Path , path : Path ) -> Inventory :
509+ def extract (tarball_path : Path , path : str ) -> Inventory :
510510 """Returns a file stream for a file within a tarball
511511
512512 Args:
@@ -552,7 +552,7 @@ def get_inventory(self, path: str) -> Optional[JSONOBJECT]:
552552 }
553553 else :
554554 file_path = Path (self .name ) / path
555- stream = Tarball .extract (self .tarball_path , file_path )
555+ stream = Tarball .extract (self .tarball_path , str ( file_path ) )
556556 info = {"name" : file_path .name , "type" : CacheType .FILE , "stream" : stream }
557557
558558 return info
@@ -636,7 +636,8 @@ def unpack(self):
636636 self .cache .mkdir (parents = True )
637637
638638 try :
639- tar_command = f"tar -x --no-same-owner --delay-directory-restore --force-local --file='{ str (self .tarball_path )} '"
639+ tar_command = f"tar -x --no-same-owner --delay-directory-restore "
640+ tar_command += f"--force-local --file='{ str (self .tarball_path )} '"
640641 self .subprocess_run (
641642 tar_command , self .cache , TarballUnpackError , self .tarball_path
642643 )
@@ -770,18 +771,18 @@ def create(
770771 controller_dir .mkdir (exist_ok = True , mode = 0o755 )
771772 return cls (controller_dir , options .CACHE , logger )
772773
773- def create_tarball (self , tarfile : Path ) -> Tarball :
774+ def create_tarball (self , tarfile_path : Path ) -> Tarball :
774775 """Create a new dataset tarball object under the controller
775776
776777 The new tarball object is linked to the controller so we can find it.
777778
778779 Args:
779- tarfile : Path to source tarball file
780+ tarfile_path : Path to source tarball file
780781
781782 Returns:
782783 Tarball object
783784 """
784- tarball = Tarball .create (tarfile , self )
785+ tarball = Tarball .create (tarfile_path , self )
785786 self .datasets [tarball .resource_id ] = tarball
786787 self .tarballs [tarball .name ] = tarball
787788 return tarball
@@ -1008,12 +1009,12 @@ def find_dataset(self, dataset_id: str) -> Tarball:
10081009
10091010 # The dataset isn't already known; so search for it in the ARCHIVE tree
10101011 # and (if found) discover the controller containing that dataset.
1011- for dir in self .archive_root .iterdir ():
1012- if dir .is_dir () and dir .name != self .TEMPORARY :
1013- for file in dir .glob (f"*{ Dataset .TARBALL_SUFFIX } " ):
1012+ for dir_entry in self .archive_root .iterdir ():
1013+ if dir_entry .is_dir () and dir_entry .name != self .TEMPORARY :
1014+ for file in dir_entry .glob (f"*{ Dataset .TARBALL_SUFFIX } " ):
10141015 md5 = get_tarball_md5 (file )
10151016 if md5 == dataset_id :
1016- self ._add_controller (dir )
1017+ self ._add_controller (dir_entry )
10171018 return self .datasets [dataset_id ]
10181019 raise TarballNotFound (dataset_id )
10191020
@@ -1037,16 +1038,15 @@ def find_dataset(self, dataset_id: str) -> Tarball:
10371038 # Remove the tarball and MD5 file from ARCHIVE after uncaching the
10381039 # unpacked directory tree.
10391040
1040- def create (self , tarfile : Path ) -> Tarball :
1041+ def create (self , tarfile_path : Path ) -> Tarball :
10411042 """Bring a new tarball under cache manager management.
10421043
10431044 Move a dataset tarball and companion MD5 file into the specified
10441045 controller directory. The controller directory will be created if
10451046 necessary.
10461047
10471048 Args:
1048- controller: associated controller name
1049- tarfile: dataset tarball path
1049+ tarfile_path: dataset tarball path
10501050
10511051 Raises
10521052 BadDirpath: Failure on extracting the file from tarball
@@ -1059,27 +1059,27 @@ def create(self, tarfile: Path) -> Tarball:
10591059 Tarball object
10601060 """
10611061 try :
1062- metadata = Tarball ._get_metadata (tarfile )
1062+ metadata = Tarball ._get_metadata (tarfile_path )
10631063 if metadata :
10641064 controller_name = metadata ["run" ]["controller" ]
10651065 else :
10661066 controller_name = "unknown"
10671067 except Exception as exc :
1068- raise MetadataError (tarfile , exc )
1068+ raise MetadataError (tarfile_path , exc )
10691069
10701070 if not controller_name :
1071- raise MetadataError (tarfile , "no controller value" )
1072- if not tarfile .is_file ():
1073- raise BadFilename (tarfile )
1074- name = Dataset .stem (tarfile )
1071+ raise MetadataError (tarfile_path , ValueError ( "no controller value" ) )
1072+ if not tarfile_path .is_file ():
1073+ raise BadFilename (tarfile_path )
1074+ name = Dataset .stem (tarfile_path )
10751075 if name in self .tarballs :
10761076 raise DuplicateTarball (name )
10771077 if controller_name in self .controllers :
10781078 controller = self .controllers [controller_name ]
10791079 else :
10801080 controller = Controller .create (controller_name , self .options , self .logger )
10811081 self .controllers [controller_name ] = controller
1082- tarball = controller .create_tarball (tarfile )
1082+ tarball = controller .create_tarball (tarfile_path )
10831083 tarball .metadata = metadata
10841084 self .tarballs [tarball .name ] = tarball
10851085 self .datasets [tarball .resource_id ] = tarball
@@ -1122,7 +1122,7 @@ def get_inventory(self, dataset_id: str, target: str) -> Optional[JSONOBJECT]:
11221122 }
11231123
11241124 Args:
1125- dataset : Dataset resource ID
1125+ dataset_id : Dataset resource ID
11261126 target: relative file path within the tarball
11271127
11281128 Returns:
0 commit comments