Create an archive of the directory 'src'. The input 'src' must be an existing directory. If 'dst' does not exist, this function will create it. The directory specified via 'src' is removed after successful creation. Returns the path to the archive. Example:
(self, src: Path, dst: Path)
| 459 | raise RuntimeError(f"Unexpected error, failed to create archive: {archive_path}") |
| 460 | |
| 461 | def make_archive(self, src: Path, dst: Path) -> Path: |
| 462 | """Create an archive of the directory 'src'. |
| 463 | The input 'src' must be an existing directory. |
| 464 | If 'dst' does not exist, this function will create it. |
| 465 | The directory specified via 'src' is removed after successful creation. |
| 466 | Returns the path to the archive. |
| 467 | |
| 468 | Example: |
| 469 | payload = Payload(...) |
| 470 | foo = Path('foo') |
| 471 | bar = Path('bar') |
| 472 | targz = payload.make_archive(foo, bar) |
| 473 | This will create the file bar\\<payload.archive_name> containing 'foo' and all its contents. |
| 474 | |
| 475 | """ |
| 476 | if not src.is_dir(): |
| 477 | raise NotADirectoryError(src) |
| 478 | dst.mkdir(parents=True, exist_ok=True) |
| 479 | |
| 480 | archive_path = dst / self.archive_name |
| 481 | |
| 482 | archive_type = archive_path.suffix[1:] # since suffix starts with '.' |
| 483 | with tarfile.open(archive_path, mode=f"w:{archive_type}", compresslevel=1) as tar: |
| 484 | tar.add(src, arcname=src.name) |
| 485 | |
| 486 | shutil.rmtree(src) |
| 487 | return archive_path |
| 488 | |
| 489 | def render_templates(self) -> list[Path]: |
| 490 | """Render the configured templates under the payload root, |
no outgoing calls