Skip to content

Commit 7cc27da

Browse files
authored
Make downloading more windows-friendly (#2810)
* Make downloading more windows-friendly * Remove unnecessary f-strings
1 parent 0dfefbf commit 7cc27da

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

nerfstudio/scripts/downloads/download_data.py

+26-23
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import json
1919
import os
2020
import shutil
21+
import subprocess
2122
import tarfile
2223
import zipfile
2324
from dataclasses import dataclass
@@ -143,10 +144,10 @@ def download_capture_name(save_dir: Path, dataset_name: str, capture_name: str,
143144
file_id_or_zip_url = capture_name_to_file_id[capture_name]
144145
if file_id_or_zip_url.endswith(".zip"):
145146
url = file_id_or_zip_url # zip url
146-
target_path = str(save_dir / f"{dataset_name}/{capture_name}")
147+
target_path = str(save_dir / dataset_name / capture_name)
147148
os.makedirs(target_path, exist_ok=True)
148149
download_path = Path(f"{target_path}.zip")
149-
tmp_path = str(save_dir / ".temp")
150+
tmp_path = str(save_dir / dataset_name / f".temp_{capture_name}")
150151
shutil.rmtree(tmp_path, ignore_errors=True)
151152
os.makedirs(tmp_path, exist_ok=True)
152153
try:
@@ -156,10 +157,10 @@ def download_capture_name(save_dir: Path, dataset_name: str, capture_name: str,
156157
run_command(f"wget {url} -O {download_path}", verbose=True)
157158
else:
158159
url = f"https://drive.google.com/uc?id={file_id_or_zip_url}" # file id
159-
target_path = str(save_dir / f"{dataset_name}/{capture_name}")
160+
target_path = str(save_dir / dataset_name / capture_name)
160161
os.makedirs(target_path, exist_ok=True)
161162
download_path = Path(f"{target_path}.zip")
162-
tmp_path = str(save_dir / ".temp")
163+
tmp_path = str(save_dir / dataset_name / f".temp_{capture_name}")
163164
shutil.rmtree(tmp_path, ignore_errors=True)
164165
os.makedirs(tmp_path, exist_ok=True)
165166
try:
@@ -170,7 +171,7 @@ def download_capture_name(save_dir: Path, dataset_name: str, capture_name: str,
170171
with zipfile.ZipFile(download_path, "r") as zip_ref:
171172
zip_ref.extractall(tmp_path)
172173
inner_folders = os.listdir(tmp_path)
173-
assert len(inner_folders) == 1, "There is more than one folder inside this zip file."
174+
assert len(inner_folders) == 1, f"There is more than one folder inside this zip file: {inner_folders}"
174175
folder = os.path.join(tmp_path, inner_folders[0])
175176
shutil.rmtree(target_path)
176177
shutil.move(folder, target_path)
@@ -239,7 +240,9 @@ def download(self, save_dir: Path):
239240
if os.path.exists(final_path):
240241
shutil.rmtree(str(final_path))
241242
download_path = save_dir / "dnerf_data.zip"
242-
os.system(f"curl -L https://www.dropbox.com/s/raw/0bf6fl0ye2vz3vr/data.zip > {download_path}")
243+
subprocess.run(
244+
["curl", "-L", "https://www.dropbox.com/s/raw/0bf6fl0ye2vz3vr/data.zip", "-o", download_path], check=True
245+
)
243246
with zipfile.ZipFile(download_path, "r") as zip_ref:
244247
zip_ref.extractall(str(save_dir))
245248
unzip_path = save_dir / Path("data")
@@ -289,20 +292,20 @@ def download(self, save_dir: Path):
289292
self.capture_name in phototourism_downloads
290293
), f"Capture name {self.capture_name} not found in {phototourism_downloads.keys()}"
291294
url = phototourism_downloads[self.capture_name]
292-
target_path = str(save_dir / f"phototourism/{self.capture_name}")
295+
target_path = str(save_dir / "phototourism" / self.capture_name)
293296
os.makedirs(target_path, exist_ok=True)
294297
download_path = Path(f"{target_path}.tar.gz")
295-
tmp_path = str(save_dir / ".temp")
298+
tmp_path = str(save_dir / "phototourism" / f".temp_{self.capture_name}")
296299
shutil.rmtree(tmp_path, ignore_errors=True)
297300
os.makedirs(tmp_path, exist_ok=True)
298301

299-
os.system(f"curl -L {url} > {download_path}")
302+
subprocess.run(["curl", "-L", url, "-o", download_path], check=True)
300303

301304
with tarfile.open(download_path, "r:gz") as tar_ref:
302305
tar_ref.extractall(str(tmp_path))
303306

304307
inner_folders = os.listdir(tmp_path)
305-
assert len(inner_folders) == 1, "There is more than one folder inside this zip file."
308+
assert len(inner_folders) == 1, f"There is more than one folder inside this zip file: {inner_folders}"
306309
folder = os.path.join(tmp_path, inner_folders[0])
307310
shutil.rmtree(target_path)
308311
shutil.move(folder, target_path)
@@ -337,7 +340,7 @@ class SDFstudioDemoDownload(DatasetDownload):
337340
dataset_name: SDFstudioCaptureName = "sdfstudio-demo-data"
338341

339342
def download(self, save_dir: Path):
340-
"""Download the D-NeRF dataset (https://github.com/albertpumarola/D-NeRF)."""
343+
"""Download the sdfstudio dataset (https://autonomousvision.github.io/sdfstudio/)."""
341344
# TODO: give this code the same structure as download_nerfstudio
342345

343346
if self.dataset_name == "all":
@@ -352,17 +355,17 @@ def download(self, save_dir: Path):
352355

353356
url = sdfstudio_downloads[self.dataset_name]
354357

355-
target_path = str(save_dir / self.dataset_name)
358+
target_path = str(save_dir / "sdfstudio" / self.dataset_name)
356359
os.makedirs(target_path, exist_ok=True)
357360

358361
file_format = url[-4:]
359362

360363
download_path = Path(f"{target_path}{file_format}")
361-
tmp_path = str(save_dir / ".temp")
364+
tmp_path = str(save_dir / "sdfstudio" / f".temp_{self.dataset_name}")
362365
shutil.rmtree(tmp_path, ignore_errors=True)
363366
os.makedirs(tmp_path, exist_ok=True)
364367

365-
os.system(f"curl -L {url} > {download_path}")
368+
subprocess.run(["curl", "-L", url, "-o", download_path], check=True)
366369
if file_format == ".tar":
367370
with tarfile.open(download_path, "r") as tar_ref:
368371
tar_ref.extractall(str(tmp_path))
@@ -374,7 +377,7 @@ def download(self, save_dir: Path):
374377
raise NotImplementedError
375378

376379
inner_folders = os.listdir(tmp_path)
377-
assert len(inner_folders) == 1, "There is more than one folder inside this zip file."
380+
assert len(inner_folders) == 1, f"There is more than one folder inside this zip file: {inner_folders}"
378381
folder = os.path.join(tmp_path, inner_folders[0])
379382
shutil.rmtree(target_path)
380383
shutil.move(folder, target_path)
@@ -421,21 +424,21 @@ def download(self, save_dir: Path):
421424
self.capture_name in nerfosr_downloads
422425
), f"Capture name {self.capture_name} not found in {nerfosr_downloads.keys()}"
423426
url = nerfosr_downloads[self.capture_name]
424-
target_path = str(save_dir / f"NeRF-OSR/Data/{self.capture_name}")
427+
target_path = str(save_dir / "nerfosr" / self.capture_name)
425428
os.makedirs(target_path, exist_ok=True)
426429
download_path = Path(f"{target_path}.zip")
427-
tmp_path = str(save_dir / ".temp")
430+
tmp_path = str(save_dir / "nerfosr" / f".temp_{self.capture_name}")
428431
shutil.rmtree(tmp_path, ignore_errors=True)
429432
os.makedirs(tmp_path, exist_ok=True)
430433

431-
os.system(f"curl -L '{url}' > {download_path}")
434+
subprocess.run(["curl", "-L", url, "-o", download_path], check=True)
432435

433436
# Extract the zip file
434437
with zipfile.ZipFile(download_path, "r") as zip_ref:
435438
zip_ref.extractall(tmp_path)
436439

437440
inner_folders = os.listdir(tmp_path)
438-
assert len(inner_folders) == 1, "There is more than one folder inside this zip file."
441+
assert len(inner_folders) == 1, f"There is more than one folder inside this zip file: {inner_folders}"
439442
folder = os.path.join(tmp_path, inner_folders[0])
440443
shutil.rmtree(target_path)
441444
shutil.move(folder, target_path)
@@ -475,20 +478,20 @@ def download(self, save_dir: Path) -> None:
475478
self.capture_name in mill19_downloads
476479
), f"Capture name {self.capture_name} not found in {mill19_downloads.keys()}"
477480
url = mill19_downloads[self.capture_name]
478-
target_path = save_dir / f"mill19/{self.capture_name}"
481+
target_path = save_dir / "mill19" / self.capture_name
479482
target_path.mkdir(parents=True, exist_ok=True)
480483
download_path = Path(f"{target_path}.tgz")
481-
tmp_path = save_dir / ".temp"
484+
tmp_path = save_dir / "mill19" / f".temp_{self.capture_name}"
482485
shutil.rmtree(tmp_path, ignore_errors=True)
483486
tmp_path.mkdir(parents=True, exist_ok=True)
484487

485-
os.system(f"curl -L {url} > {download_path}")
488+
subprocess.run(["curl", "-L", url, "-o", download_path], check=True)
486489

487490
with tarfile.open(download_path, "r:gz") as tar_ref:
488491
tar_ref.extractall(tmp_path)
489492

490493
inner_folders = list(tmp_path.iterdir())
491-
assert len(inner_folders) == 1, "There is more than one folder inside this zip file."
494+
assert len(inner_folders) == 1, f"There is more than one folder inside this zip file: {inner_folders}"
492495
folder = inner_folders[0]
493496
shutil.rmtree(target_path)
494497
folder.rename(target_path)

0 commit comments

Comments
 (0)