Skip to content

Commit fd4d44c

Browse files
committed
Add an option to remove zip files after unzipping.
Signed-off-by: Tully Foote <[email protected]>
1 parent 3c85e64 commit fd4d44c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
-
4747
name: Run bpc fetch
4848
run: |
49-
bpc fetch ipd
49+
bpc fetch ipd --remove-zip-after-extract
5050
-
5151
name: Run bpc test
5252
run: |

ibpc_py/src/ibpc/ibpc.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import hashlib
33
import os
4+
import pathlib
45
import shlex
56
import shutil
67
import signal
@@ -103,7 +104,7 @@ def sha256_file(filename):
103104
return sha256.hexdigest()
104105

105106

106-
def fetch_dataset(dataset, output_path):
107+
def fetch_dataset(dataset, output_path, remove_zip_after_extract):
107108
(url_base, files) = available_datasets[dataset]
108109
# Before we do anything make sure the directory exists
109110
dataset_dir = os.path.join(output_path, dataset)
@@ -165,6 +166,10 @@ def fetch_dataset(dataset, output_path):
165166
# with ZipFile(filename) as zfile:
166167
# zfile.extractall(output_path)
167168

169+
if remove_zip_after_extract:
170+
for filename in fetched_files:
171+
pathlib.Path(filename).unlink(missing_ok=True)
172+
168173

169174
def main():
170175

@@ -191,6 +196,12 @@ def main():
191196
fetch_parser = sub_parsers.add_parser("fetch")
192197
fetch_parser.add_argument("dataset", choices=available_datasets.keys())
193198
fetch_parser.add_argument("--dataset-path", default=".")
199+
fetch_parser.add_argument(
200+
"--remove-zip-after-extract",
201+
default=False,
202+
action="store_true",
203+
help="Remove the zip files after extracting to save disk space.",
204+
)
194205

195206
extension_manager = RockerExtensionManager()
196207

@@ -200,7 +211,9 @@ def main():
200211
dataset_name = args_dict["dataset"]
201212
dataset_directory = args_dict["dataset_path"]
202213
print(f"Fetching dataset {dataset_name} to {dataset_directory}")
203-
fetch_dataset(dataset_name, dataset_directory)
214+
fetch_dataset(
215+
dataset_name, dataset_directory, args_dict["remove_zip_after_extract"]
216+
)
204217
print("Fetch complete")
205218
return
206219

0 commit comments

Comments
 (0)