@@ -480,20 +480,17 @@ def abs_or_rel_to(path: Path, base: Path) -> Path:
480480 return base / path
481481
482482
483- class BugReport :
483+ class BugReportBase :
484484 _bug_report : Path
485485 _command_id : int
486486 _defn_id : int
487487 _file_remap : dict [str , str ]
488488
489489 def __init__ (self , bug_report : Path ) -> None :
490- self ._bug_report = bug_report . with_suffix ( '.tar' )
490+ self ._bug_report = bug_report
491491 self ._command_id = 0
492492 self ._defn_id = 0
493493 self ._file_remap = {}
494- if self ._bug_report .exists ():
495- _LOGGER .warning (f'Bug report exists, removing: { self ._bug_report } ' )
496- self ._bug_report .unlink ()
497494
498495 def add_file (self , finput : Path , arcname : Path ) -> None :
499496 if str (finput ) not in self ._file_remap :
@@ -524,3 +521,26 @@ def _remap_arg(_a: str) -> str:
524521 shebang = '#!/usr/bin/env bash\n set -euxo pipefail\n '
525522 self .add_file_contents (shebang + ' ' .join (remapped_args ) + '\n ' , arcname )
526523 self ._command_id += 1
524+
525+
526+ class BugReport (BugReportBase ):
527+ def __init__ (self , bug_report : Path ) -> None :
528+ bug_report = bug_report .with_suffix ('.tar' )
529+ if bug_report .exists ():
530+ _LOGGER .warning (f'Bug report exists, removing: { bug_report } ' )
531+ bug_report .unlink ()
532+ super ().__init__ (bug_report )
533+
534+ def reporter (self , prefix : str ) -> BugReportBase :
535+ class BugReporter (BugReportBase ):
536+ _prefix : Path
537+
538+ def __init__ (self , bug_report : Path , prefix : Path ) -> None :
539+ super ().__init__ (bug_report )
540+ self ._prefix = prefix
541+
542+ def add_file (self , finput : Path , arcname : Path ) -> None :
543+ arcname = self ._prefix / arcname
544+ super ().add_file (finput , arcname )
545+
546+ return BugReporter (self ._bug_report , Path (prefix ))
0 commit comments