Datasets:
update unpack_dataset.py
Browse files- scripts/unpack_dataset.py +11 -0
scripts/unpack_dataset.py
CHANGED
|
@@ -26,6 +26,16 @@ def extract_archive(archive: Path, dest: Path, *, dry_run: bool) -> None:
|
|
| 26 |
print(f"extracted {archive} -> {dest}")
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def remove_dot_underscore_files(root: Path) -> None:
|
| 30 |
"""Remove macOS resource fork files like ._foo."""
|
| 31 |
for path in root.rglob("._*"):
|
|
@@ -70,6 +80,7 @@ def main() -> int:
|
|
| 70 |
extract_archive(archive, archive.parent, dry_run=args.dry_run)
|
| 71 |
|
| 72 |
if not args.dry_run:
|
|
|
|
| 73 |
for target in targets:
|
| 74 |
if target.is_dir():
|
| 75 |
remove_dot_underscore_files(target)
|
|
|
|
| 26 |
print(f"extracted {archive} -> {dest}")
|
| 27 |
|
| 28 |
|
| 29 |
+
def delete_archives(archives: list[Path]) -> None:
|
| 30 |
+
"""Delete archives after successful extraction to save space."""
|
| 31 |
+
for archive in archives:
|
| 32 |
+
try:
|
| 33 |
+
archive.unlink()
|
| 34 |
+
print(f"deleted {archive}")
|
| 35 |
+
except FileNotFoundError:
|
| 36 |
+
continue
|
| 37 |
+
|
| 38 |
+
|
| 39 |
def remove_dot_underscore_files(root: Path) -> None:
|
| 40 |
"""Remove macOS resource fork files like ._foo."""
|
| 41 |
for path in root.rglob("._*"):
|
|
|
|
| 80 |
extract_archive(archive, archive.parent, dry_run=args.dry_run)
|
| 81 |
|
| 82 |
if not args.dry_run:
|
| 83 |
+
delete_archives(archives)
|
| 84 |
for target in targets:
|
| 85 |
if target.is_dir():
|
| 86 |
remove_dot_underscore_files(target)
|