2424from .utils import CommandInfo , HPSSType , tars_table_exists
2525
2626
27- def extract (keep_files : bool = True ):
27+ def extract (do_extract_files : bool = True ):
2828 """
2929 Given an HPSS path in the zstash database or passed via the command line,
3030 extract the archived data based on the file pattern (if given).
3131 """
3232 command_info = CommandInfo ("extract" )
3333 args : argparse .Namespace = setup_extract (command_info )
34- failures : List [FilesRow ] = extract_database (command_info , args , keep_files )
34+ failures : List [FilesRow ] = extract_database (command_info , args , do_extract_files )
3535
3636 if failures :
3737 logger .error ("Encountered an error for files:" )
@@ -45,7 +45,7 @@ def extract(keep_files: bool = True):
4545 for tar in broken_tars :
4646 logger .error (tar )
4747 else :
48- verb : str = "extracting" if keep_files else "checking"
48+ verb : str = "extracting" if do_extract_files else "checking"
4949 logger .info (
5050 'No failures detected when {} the files. If you have a log file, run "grep -i Exception <log-file>" to double check.' .format (
5151 verb
@@ -149,7 +149,7 @@ def parse_tars_option(tars: str, first_tar: str, last_tar: str) -> List[str]:
149149
150150
151151def extract_database (
152- command_info : CommandInfo , args : argparse .Namespace , keep_files : bool
152+ command_info : CommandInfo , args : argparse .Namespace , do_extract_files : bool
153153) -> List [FilesRow ]:
154154
155155 # Open database
@@ -172,13 +172,15 @@ def extract_database(
172172 command_info .update_config_using_db (cur )
173173 command_info .validate_maxsize ()
174174
175- if command_info .hpss_type == HPSSType .NO_HPSS :
175+ if command_info .hpss_type in [HPSSType .NO_HPSS , HPSSType .UNDEFINED ]:
176+ if command_info .config .hpss != "none" :
177+ raise ValueError (f"Invalid config.hpss={ command_info .config .hpss } " )
176178 # If not using HPSS, always keep the files.
177179 command_info .keep = True
178180 # else: keep command_info.keep set to args.keep
179181
180182 # Start doing actual work
181- cmd : str = "extract" if keep_files else "check"
183+ cmd : str = "extract" if do_extract_files else "check"
182184
183185 logger .debug ("Running zstash " + cmd )
184186 logger .debug (f"Local path : { command_info .config .path } " )
@@ -257,12 +259,12 @@ def extract_database(
257259 args .workers ,
258260 command_info ,
259261 matches ,
260- keep_files ,
262+ do_extract_files ,
261263 cur ,
262264 args ,
263265 )
264266 else :
265- failures = extractFiles (command_info , matches , keep_files , cur , args )
267+ failures = extractFiles (command_info , matches , do_extract_files , cur , args )
266268
267269 # Close database
268270 logger .debug ("Closing index database" )
@@ -275,7 +277,7 @@ def multiprocess_extract(
275277 num_workers : int ,
276278 command_info : CommandInfo ,
277279 matches : List [FilesRow ],
278- keep_files : bool ,
280+ do_extract_files : bool ,
279281 cur : sqlite3 .Cursor ,
280282 args : argparse .Namespace ,
281283) -> List [FilesRow ]:
@@ -350,7 +352,7 @@ def multiprocess_extract(
350352 )
351353 process : multiprocessing .Process = multiprocessing .Process (
352354 target = extractFiles ,
353- args = (command_info , matches , keep_files , cur , args , worker ),
355+ args = (command_info , matches , do_extract_files , cur , args , worker ),
354356 daemon = True ,
355357 )
356358 process .start ()
@@ -396,7 +398,7 @@ def check_sizes_match(cur, tfname):
396398def extractFiles ( # noqa: C901
397399 command_info : CommandInfo ,
398400 files : List [FilesRow ],
399- keep_files : bool ,
401+ do_extract_files : bool ,
400402 cur : sqlite3 .Cursor ,
401403 args : argparse .Namespace ,
402404 multiprocess_worker : Optional [parallel .ExtractWorker ] = None ,
@@ -405,7 +407,7 @@ def extractFiles( # noqa: C901
405407 Given a list of database rows, extract the files from the
406408 tar archives to the current location on disk.
407409
408- If keep_files is False, the files are not extracted.
410+ If do_extract_files is False, the files are not extracted.
409411 This is used for when checking if the files in an HPSS
410412 repository are valid.
411413
@@ -483,12 +485,12 @@ def extractFiles( # noqa: C901
483485 tar : tarfile .TarFile = tarfile .open (tfname , "r" )
484486
485487 # Extract file
486- cmd : str = "Extracting" if keep_files else "Checking"
488+ cmd : str = "Extracting" if do_extract_files else "Checking"
487489 logger .info (cmd + " %s" % (files_row .name ))
488490 # if multiprocess_worker:
489491 # print('{} is {} {} from {}'.format(multiprocess_worker, cmd, file[1], file[5]))
490492
491- if keep_files and not should_extract_file (files_row ):
493+ if do_extract_files and not should_extract_file (files_row ):
492494 # If we were going to extract, but aren't
493495 # because a matching file is on disk
494496 msg : str = "Not extracting {}, because it"
@@ -497,7 +499,7 @@ def extractFiles( # noqa: C901
497499 logger .info (msg .format (files_row .name ))
498500
499501 # True if we should actually extract the file from the tar
500- extract_this_file : bool = keep_files and should_extract_file (files_row )
502+ extract_this_file : bool = do_extract_files and should_extract_file (files_row )
501503
502504 try :
503505 # Seek file position
@@ -600,16 +602,19 @@ def extractFiles( # noqa: C901
600602
601603 if multiprocess_worker :
602604 multiprocess_worker .done_enqueuing_output_for_tar (files_row .tar )
603-
604605 # Open new archive next time
605606 newtar = True
606607
607608 # Delete this tar if the corresponding command-line arg was used.
609+ logger .debug (f"hpss type={ command_info .hpss_type } " )
608610 if not command_info .keep :
609611 if tfname is not None :
612+ logger .debug (f"Removing tar archive { tfname } " )
610613 os .remove (tfname )
611614 else :
612- raise TypeError ("Invalid tfname={}" .format (tfname ))
615+ raise TypeError (f"Invalid tfname={ tfname } " )
616+ else :
617+ logger .debug (f"Keeping tar archive { tfname } " )
613618
614619 if multiprocess_worker :
615620 # If there are things left to print, print them.
0 commit comments