Align public download utilities with GitHub
Browse files- README.md +2 -0
- Utils/3D_ASSETS_DOWNLOAD.md +4 -0
- Utils/LEADERBOARD_DOWNLOAD.md +9 -0
- Utils/scripts/download_data.py +285 -51
- Utils/scripts/download_selected.py +33 -26
README.md
CHANGED
|
@@ -535,6 +535,8 @@ git clone https://github.com/vLAR-group/PhysInOne.git
|
|
| 535 |
cd PhysInOne
|
| 536 |
```
|
| 537 |
|
|
|
|
|
|
|
| 538 |
Each row is a complete command that can be copied directly. The remote Leaderboard folder names remain unchanged, while the downloader creates space-free local task directories.
|
| 539 |
|
| 540 |
| Task | Copy command | Local directory |
|
|
|
|
| 535 |
cd PhysInOne
|
| 536 |
```
|
| 537 |
|
| 538 |
+
Interactive downloads show one live progress bar with file count, transferred and estimated total size, current speed, and ETA. Redirected output uses periodic plain-text snapshots, while full per-file details remain in `_download_logs/`.
|
| 539 |
+
|
| 540 |
Each row is a complete command that can be copied directly. The remote Leaderboard folder names remain unchanged, while the downloader creates space-free local task directories.
|
| 541 |
|
| 542 |
| Task | Copy command | Local directory |
|
Utils/3D_ASSETS_DOWNLOAD.md
CHANGED
|
@@ -38,6 +38,10 @@ The default command:
|
|
| 38 |
4. Extracts all eight validation ZIP files into their correct parent directories.
|
| 39 |
5. Merges scene and trajectory batches without overwriting different files.
|
| 40 |
6. Writes resumable extraction markers and detailed success/failure logs.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
After completion, launch this project with Unreal Engine 5.5.4:
|
| 43 |
|
|
|
|
| 38 |
4. Extracts all eight validation ZIP files into their correct parent directories.
|
| 39 |
5. Merges scene and trajectory batches without overwriting different files.
|
| 40 |
6. Writes resumable extraction markers and detailed success/failure logs.
|
| 41 |
+
7. Shows live file count, estimated size, download speed, and ETA in interactive terminals.
|
| 42 |
+
|
| 43 |
+
When output is redirected, the progress display automatically becomes periodic
|
| 44 |
+
plain-text snapshots without terminal control characters.
|
| 45 |
|
| 46 |
After completion, launch this project with Unreal Engine 5.5.4:
|
| 47 |
|
Utils/LEADERBOARD_DOWNLOAD.md
CHANGED
|
@@ -30,6 +30,15 @@ cd PhysInOne
|
|
| 30 |
The same script tree is mirrored under `Utils/scripts/` in the Hugging Face
|
| 31 |
dataset repository.
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
## Quick start
|
| 34 |
|
| 35 |
Run these commands from the cloned GitHub repository root.
|
|
|
|
| 30 |
The same script tree is mirrored under `Utils/scripts/` in the Hugging Face
|
| 31 |
dataset repository.
|
| 32 |
|
| 33 |
+
## Progress display
|
| 34 |
+
|
| 35 |
+
Interactive terminals show a single live progress bar with completed file count,
|
| 36 |
+
transferred and estimated total size, current download speed, and ETA. Because
|
| 37 |
+
the manifests do not store object sizes, the total size and ETA are estimates
|
| 38 |
+
that become more accurate as Hugging Face responses provide file sizes. Redirected
|
| 39 |
+
output automatically uses periodic plain-text snapshots, and complete per-file
|
| 40 |
+
records remain available under `_download_logs/`.
|
| 41 |
+
|
| 42 |
## Quick start
|
| 43 |
|
| 44 |
Run these commands from the cloned GitHub repository root.
|
Utils/scripts/download_data.py
CHANGED
|
@@ -16,11 +16,12 @@ import time
|
|
| 16 |
import urllib.error
|
| 17 |
import urllib.request
|
| 18 |
import zipfile
|
|
|
|
| 19 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 20 |
from dataclasses import dataclass
|
| 21 |
from datetime import datetime, timezone
|
| 22 |
from pathlib import Path, PurePosixPath
|
| 23 |
-
from typing import Iterable, Optional, Sequence
|
| 24 |
from urllib.parse import quote, unquote
|
| 25 |
|
| 26 |
|
|
@@ -30,6 +31,209 @@ CHUNK_SIZE = 8 * 1024 * 1024
|
|
| 30 |
USER_AGENT = "PhysInOne-public-downloader/1.0"
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
@dataclass(frozen=True)
|
| 34 |
class TaskSpec:
|
| 35 |
manifest: str
|
|
@@ -185,6 +389,8 @@ def download_once(
|
|
| 185 |
destination: Path,
|
| 186 |
timeout: float,
|
| 187 |
resume: bool,
|
|
|
|
|
|
|
| 188 |
) -> tuple[str, int]:
|
| 189 |
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 190 |
partial = destination.with_name(f"{destination.name}.part")
|
|
@@ -215,6 +421,9 @@ def download_once(
|
|
| 215 |
starting_size = offset if append else 0
|
| 216 |
expected_raw = response.headers.get("Content-Length")
|
| 217 |
expected = int(expected_raw) if expected_raw and expected_raw.isdigit() else None
|
|
|
|
|
|
|
|
|
|
| 218 |
written = 0
|
| 219 |
with partial.open(mode) as handle:
|
| 220 |
while True:
|
|
@@ -223,6 +432,8 @@ def download_once(
|
|
| 223 |
break
|
| 224 |
handle.write(chunk)
|
| 225 |
written += len(chunk)
|
|
|
|
|
|
|
| 226 |
if expected is not None and written != expected:
|
| 227 |
raise IOError(
|
| 228 |
f"incomplete response: expected {expected} bytes, received {written}"
|
|
@@ -245,6 +456,8 @@ def download_file(
|
|
| 245 |
force: bool,
|
| 246 |
skip_removed_archive: bool,
|
| 247 |
repository: str = REPOSITORY,
|
|
|
|
|
|
|
| 248 |
) -> DownloadResult:
|
| 249 |
if skip_removed_archive and not destination.exists() and marker_matches(destination):
|
| 250 |
return DownloadResult(
|
|
@@ -269,7 +482,9 @@ def download_file(
|
|
| 269 |
error = ""
|
| 270 |
for attempt in range(retries + 1):
|
| 271 |
try:
|
| 272 |
-
status, written = download_once(
|
|
|
|
|
|
|
| 273 |
return DownloadResult(
|
| 274 |
task, remote_path, str(destination), status, bytes_written=written
|
| 275 |
)
|
|
@@ -637,33 +852,41 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
| 637 |
run_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 638 |
logs = RunLogs(output_dir / "_download_logs" / run_id)
|
| 639 |
results: list[DownloadResult] = []
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
args.
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 667 |
|
| 668 |
extraction_results: list[ExtractionResult] = []
|
| 669 |
successful = {
|
|
@@ -671,28 +894,39 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
| 671 |
for result in results
|
| 672 |
if not result.error
|
| 673 |
}
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
if
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
task,
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
|
| 697 |
download_failures = sum(1 for result in results if result.error)
|
| 698 |
extraction_failures = sum(1 for result in extraction_results if result.error)
|
|
|
|
| 16 |
import urllib.error
|
| 17 |
import urllib.request
|
| 18 |
import zipfile
|
| 19 |
+
from collections import deque
|
| 20 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 21 |
from dataclasses import dataclass
|
| 22 |
from datetime import datetime, timezone
|
| 23 |
from pathlib import Path, PurePosixPath
|
| 24 |
+
from typing import Hashable, Iterable, Optional, Sequence, TextIO
|
| 25 |
from urllib.parse import quote, unquote
|
| 26 |
|
| 27 |
|
|
|
|
| 31 |
USER_AGENT = "PhysInOne-public-downloader/1.0"
|
| 32 |
|
| 33 |
|
| 34 |
+
def format_bytes(value: float) -> str:
|
| 35 |
+
units = ("B", "KiB", "MiB", "GiB", "TiB")
|
| 36 |
+
amount = float(max(0.0, value))
|
| 37 |
+
for unit in units:
|
| 38 |
+
if amount < 1024.0 or unit == units[-1]:
|
| 39 |
+
if unit == "B":
|
| 40 |
+
return f"{amount:.0f} {unit}"
|
| 41 |
+
return f"{amount:.1f} {unit}"
|
| 42 |
+
amount /= 1024.0
|
| 43 |
+
return f"{amount:.1f} TiB"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def format_duration(seconds: Optional[float]) -> str:
|
| 47 |
+
if seconds is None or seconds < 0 or seconds == float("inf"):
|
| 48 |
+
return "--:--"
|
| 49 |
+
value = int(seconds + 0.5)
|
| 50 |
+
hours, remainder = divmod(value, 3600)
|
| 51 |
+
minutes, secs = divmod(remainder, 60)
|
| 52 |
+
if hours:
|
| 53 |
+
return f"{hours:d}:{minutes:02d}:{secs:02d}"
|
| 54 |
+
return f"{minutes:02d}:{secs:02d}"
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class DownloadProgress:
|
| 58 |
+
"""Thread-safe aggregate progress bar with a clean non-TTY fallback."""
|
| 59 |
+
|
| 60 |
+
def __init__(
|
| 61 |
+
self,
|
| 62 |
+
total_files: int,
|
| 63 |
+
label: str = "Downloading",
|
| 64 |
+
*,
|
| 65 |
+
show_bytes: bool = True,
|
| 66 |
+
stream: Optional[TextIO] = None,
|
| 67 |
+
refresh_interval: float = 0.2,
|
| 68 |
+
log_interval: float = 10.0,
|
| 69 |
+
) -> None:
|
| 70 |
+
self.total_files = max(0, int(total_files))
|
| 71 |
+
self.label = label
|
| 72 |
+
self.show_bytes = show_bytes
|
| 73 |
+
self.stream = stream or sys.stderr
|
| 74 |
+
self.interactive = bool(
|
| 75 |
+
getattr(self.stream, "isatty", lambda: False)()
|
| 76 |
+
and not bool(getattr(self.stream, "closed", False))
|
| 77 |
+
)
|
| 78 |
+
self.refresh_interval = max(0.05, refresh_interval)
|
| 79 |
+
self.log_interval = max(1.0, log_interval)
|
| 80 |
+
self.started_at = time.monotonic()
|
| 81 |
+
self._last_render = 0.0
|
| 82 |
+
self._completed = 0
|
| 83 |
+
self._failed = 0
|
| 84 |
+
self._network_bytes = 0
|
| 85 |
+
self._states: dict[Hashable, list[Optional[int]]] = {}
|
| 86 |
+
self._samples: deque[tuple[float, int]] = deque()
|
| 87 |
+
self._lock = threading.Lock()
|
| 88 |
+
self._closed = False
|
| 89 |
+
self._dirty = True
|
| 90 |
+
|
| 91 |
+
def begin_file(
|
| 92 |
+
self,
|
| 93 |
+
key: Hashable,
|
| 94 |
+
existing_bytes: int = 0,
|
| 95 |
+
total_bytes: Optional[int] = None,
|
| 96 |
+
) -> None:
|
| 97 |
+
with self._lock:
|
| 98 |
+
self._states[key] = [
|
| 99 |
+
max(0, int(existing_bytes)),
|
| 100 |
+
None if total_bytes is None else max(0, int(total_bytes)),
|
| 101 |
+
]
|
| 102 |
+
self._dirty = True
|
| 103 |
+
self._render_locked()
|
| 104 |
+
|
| 105 |
+
def advance(self, key: Hashable, amount: int) -> None:
|
| 106 |
+
increment = max(0, int(amount))
|
| 107 |
+
if not increment:
|
| 108 |
+
return
|
| 109 |
+
with self._lock:
|
| 110 |
+
state = self._states.setdefault(key, [0, None])
|
| 111 |
+
state[0] = int(state[0] or 0) + increment
|
| 112 |
+
self._network_bytes += increment
|
| 113 |
+
self._dirty = True
|
| 114 |
+
current = time.monotonic()
|
| 115 |
+
self._samples.append((current, self._network_bytes))
|
| 116 |
+
cutoff = current - 12.0
|
| 117 |
+
while len(self._samples) > 2 and self._samples[0][0] < cutoff:
|
| 118 |
+
self._samples.popleft()
|
| 119 |
+
self._render_locked(current)
|
| 120 |
+
|
| 121 |
+
def complete(
|
| 122 |
+
self,
|
| 123 |
+
key: Hashable,
|
| 124 |
+
status: str,
|
| 125 |
+
local_path: str = "",
|
| 126 |
+
failed: bool = False,
|
| 127 |
+
) -> None:
|
| 128 |
+
with self._lock:
|
| 129 |
+
state = self._states.setdefault(key, [0, None])
|
| 130 |
+
if not failed and local_path:
|
| 131 |
+
path = Path(local_path)
|
| 132 |
+
try:
|
| 133 |
+
size = path.stat().st_size if path.is_file() else None
|
| 134 |
+
except OSError:
|
| 135 |
+
size = None
|
| 136 |
+
if size is not None:
|
| 137 |
+
state[0] = size
|
| 138 |
+
state[1] = size
|
| 139 |
+
self._completed += 1
|
| 140 |
+
if failed:
|
| 141 |
+
self._failed += 1
|
| 142 |
+
self._dirty = True
|
| 143 |
+
self._render_locked(force=self._completed == self.total_files)
|
| 144 |
+
|
| 145 |
+
def finish(self) -> None:
|
| 146 |
+
with self._lock:
|
| 147 |
+
if self._closed:
|
| 148 |
+
return
|
| 149 |
+
if self.total_files:
|
| 150 |
+
if self._dirty:
|
| 151 |
+
self._render_locked(force=True)
|
| 152 |
+
if self.interactive:
|
| 153 |
+
self.stream.write("\n")
|
| 154 |
+
self.stream.flush()
|
| 155 |
+
self._closed = True
|
| 156 |
+
|
| 157 |
+
def _speed_locked(self, current: float) -> tuple[float, float]:
|
| 158 |
+
elapsed = max(current - self.started_at, 1e-6)
|
| 159 |
+
average = self._network_bytes / elapsed
|
| 160 |
+
if len(self._samples) >= 2:
|
| 161 |
+
first_time, first_bytes = self._samples[0]
|
| 162 |
+
window = max(current - first_time, 1e-6)
|
| 163 |
+
recent = (self._network_bytes - first_bytes) / window
|
| 164 |
+
else:
|
| 165 |
+
recent = average
|
| 166 |
+
return recent, average
|
| 167 |
+
|
| 168 |
+
def _byte_totals_locked(self) -> tuple[int, Optional[int]]:
|
| 169 |
+
current_bytes = sum(int(state[0] or 0) for state in self._states.values())
|
| 170 |
+
known = [int(state[1]) for state in self._states.values() if state[1] is not None]
|
| 171 |
+
if not known:
|
| 172 |
+
return current_bytes, None
|
| 173 |
+
average_size = sum(known) / len(known)
|
| 174 |
+
estimated = int(sum(known) + average_size * (self.total_files - len(known)))
|
| 175 |
+
return current_bytes, max(current_bytes, estimated)
|
| 176 |
+
|
| 177 |
+
def _line_locked(self, current: float) -> str:
|
| 178 |
+
ratio = self._completed / self.total_files if self.total_files else 1.0
|
| 179 |
+
width = shutil.get_terminal_size(fallback=(120, 24)).columns
|
| 180 |
+
bar_width = 10 if width < 120 else min(24, max(12, width // 10))
|
| 181 |
+
filled = min(bar_width, int(ratio * bar_width))
|
| 182 |
+
if filled < bar_width and self._completed < self.total_files:
|
| 183 |
+
bar = "=" * filled + ">" + "." * (bar_width - filled - 1)
|
| 184 |
+
else:
|
| 185 |
+
bar = "=" * filled + "." * (bar_width - filled)
|
| 186 |
+
elapsed = max(current - self.started_at, 1e-6)
|
| 187 |
+
headline = f"{self.label} [{bar}] {self._completed}/{self.total_files}"
|
| 188 |
+
if self._failed:
|
| 189 |
+
headline += f" fail:{self._failed}"
|
| 190 |
+
parts = [headline]
|
| 191 |
+
if self.show_bytes:
|
| 192 |
+
current_bytes, estimated_bytes = self._byte_totals_locked()
|
| 193 |
+
recent, average = self._speed_locked(current)
|
| 194 |
+
current_text = format_bytes(current_bytes).replace(" ", "")
|
| 195 |
+
if estimated_bytes is None:
|
| 196 |
+
byte_text = current_text
|
| 197 |
+
eta = None
|
| 198 |
+
else:
|
| 199 |
+
total_text = format_bytes(estimated_bytes).replace(" ", "")
|
| 200 |
+
byte_text = f"{current_text}/~{total_text}"
|
| 201 |
+
eta = (
|
| 202 |
+
max(0, estimated_bytes - current_bytes) / recent
|
| 203 |
+
if recent > 0
|
| 204 |
+
else None
|
| 205 |
+
)
|
| 206 |
+
recent_text = format_bytes(recent).replace(" ", "")
|
| 207 |
+
parts.extend([byte_text, f"{recent_text}/s", f"ETA {format_duration(eta)}"])
|
| 208 |
+
if width >= 120:
|
| 209 |
+
average_text = format_bytes(average).replace(" ", "")
|
| 210 |
+
parts.append(f"avg {average_text}/s")
|
| 211 |
+
else:
|
| 212 |
+
rate = self._completed / elapsed
|
| 213 |
+
remaining = max(0, self.total_files - self._completed)
|
| 214 |
+
eta = remaining / rate if rate > 0 else None
|
| 215 |
+
parts.extend([f"{rate:.1f} files/s", f"ETA {format_duration(eta)}"])
|
| 216 |
+
return " | ".join(parts)
|
| 217 |
+
|
| 218 |
+
def _render_locked(self, current: Optional[float] = None, force: bool = False) -> None:
|
| 219 |
+
if self._closed:
|
| 220 |
+
return
|
| 221 |
+
timestamp = current if current is not None else time.monotonic()
|
| 222 |
+
interval = self.refresh_interval if self.interactive else self.log_interval
|
| 223 |
+
if not force and timestamp - self._last_render < interval:
|
| 224 |
+
return
|
| 225 |
+
line = self._line_locked(timestamp)
|
| 226 |
+
if self.interactive:
|
| 227 |
+
width = shutil.get_terminal_size(fallback=(120, 24)).columns
|
| 228 |
+
clipped = line[: max(1, width - 1)]
|
| 229 |
+
self.stream.write("\r\033[2K" + clipped)
|
| 230 |
+
else:
|
| 231 |
+
self.stream.write(line + "\n")
|
| 232 |
+
self.stream.flush()
|
| 233 |
+
self._last_render = timestamp
|
| 234 |
+
self._dirty = False
|
| 235 |
+
|
| 236 |
+
|
| 237 |
@dataclass(frozen=True)
|
| 238 |
class TaskSpec:
|
| 239 |
manifest: str
|
|
|
|
| 389 |
destination: Path,
|
| 390 |
timeout: float,
|
| 391 |
resume: bool,
|
| 392 |
+
progress: Optional[DownloadProgress] = None,
|
| 393 |
+
progress_key: object = "",
|
| 394 |
) -> tuple[str, int]:
|
| 395 |
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 396 |
partial = destination.with_name(f"{destination.name}.part")
|
|
|
|
| 421 |
starting_size = offset if append else 0
|
| 422 |
expected_raw = response.headers.get("Content-Length")
|
| 423 |
expected = int(expected_raw) if expected_raw and expected_raw.isdigit() else None
|
| 424 |
+
if progress is not None:
|
| 425 |
+
total_bytes = starting_size + expected if expected is not None else None
|
| 426 |
+
progress.begin_file(progress_key, starting_size, total_bytes)
|
| 427 |
written = 0
|
| 428 |
with partial.open(mode) as handle:
|
| 429 |
while True:
|
|
|
|
| 432 |
break
|
| 433 |
handle.write(chunk)
|
| 434 |
written += len(chunk)
|
| 435 |
+
if progress is not None:
|
| 436 |
+
progress.advance(progress_key, len(chunk))
|
| 437 |
if expected is not None and written != expected:
|
| 438 |
raise IOError(
|
| 439 |
f"incomplete response: expected {expected} bytes, received {written}"
|
|
|
|
| 456 |
force: bool,
|
| 457 |
skip_removed_archive: bool,
|
| 458 |
repository: str = REPOSITORY,
|
| 459 |
+
progress: Optional[DownloadProgress] = None,
|
| 460 |
+
progress_key: object = "",
|
| 461 |
) -> DownloadResult:
|
| 462 |
if skip_removed_archive and not destination.exists() and marker_matches(destination):
|
| 463 |
return DownloadResult(
|
|
|
|
| 482 |
error = ""
|
| 483 |
for attempt in range(retries + 1):
|
| 484 |
try:
|
| 485 |
+
status, written = download_once(
|
| 486 |
+
url, destination, timeout, resume, progress, progress_key
|
| 487 |
+
)
|
| 488 |
return DownloadResult(
|
| 489 |
task, remote_path, str(destination), status, bytes_written=written
|
| 490 |
)
|
|
|
|
| 852 |
run_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 853 |
logs = RunLogs(output_dir / "_download_logs" / run_id)
|
| 854 |
results: list[DownloadResult] = []
|
| 855 |
+
progress = DownloadProgress(len(selections), "Downloading")
|
| 856 |
+
try:
|
| 857 |
+
with ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 858 |
+
futures = {
|
| 859 |
+
pool.submit(
|
| 860 |
+
download_file,
|
| 861 |
+
task,
|
| 862 |
+
remote_path,
|
| 863 |
+
destination,
|
| 864 |
+
args.revision,
|
| 865 |
+
args.timeout,
|
| 866 |
+
args.retries,
|
| 867 |
+
not args.no_resume,
|
| 868 |
+
args.force,
|
| 869 |
+
(
|
| 870 |
+
args.delete_zip_after_extract
|
| 871 |
+
and should_extract(task, args.extract)
|
| 872 |
+
and remote_path.lower().endswith(".zip")
|
| 873 |
+
),
|
| 874 |
+
REPOSITORY,
|
| 875 |
+
progress,
|
| 876 |
+
index,
|
| 877 |
+
): index
|
| 878 |
+
for index, (task, remote_path, destination) in enumerate(selections)
|
| 879 |
+
}
|
| 880 |
+
for future in as_completed(futures):
|
| 881 |
+
key = futures[future]
|
| 882 |
+
result = future.result()
|
| 883 |
+
results.append(result)
|
| 884 |
+
logs.record_download(result)
|
| 885 |
+
progress.complete(
|
| 886 |
+
key, result.status, result.local_path, failed=bool(result.error)
|
| 887 |
+
)
|
| 888 |
+
finally:
|
| 889 |
+
progress.finish()
|
| 890 |
|
| 891 |
extraction_results: list[ExtractionResult] = []
|
| 892 |
successful = {
|
|
|
|
| 894 |
for result in results
|
| 895 |
if not result.error
|
| 896 |
}
|
| 897 |
+
extraction_plan = [
|
| 898 |
+
item
|
| 899 |
+
for item in selections
|
| 900 |
+
if item[1].lower().endswith(".zip") and should_extract(item[0], args.extract)
|
| 901 |
+
]
|
| 902 |
+
if extraction_plan:
|
| 903 |
+
extraction_progress = DownloadProgress(
|
| 904 |
+
len(extraction_plan), "Extracting", show_bytes=False
|
| 905 |
+
)
|
| 906 |
+
try:
|
| 907 |
+
for index, (task, remote_path, destination) in enumerate(extraction_plan):
|
| 908 |
+
archive = successful.get((task, remote_path), destination)
|
| 909 |
+
marker = extraction_marker(archive)
|
| 910 |
+
if not archive.is_file() and marker_matches(archive):
|
| 911 |
+
result = ExtractionResult(
|
| 912 |
+
task, str(archive), "already_extracted_zip_removed"
|
| 913 |
+
)
|
| 914 |
+
elif not archive.is_file():
|
| 915 |
+
result = ExtractionResult(
|
| 916 |
+
task,
|
| 917 |
+
str(archive),
|
| 918 |
+
"failed",
|
| 919 |
+
error="archive is unavailable because its download failed",
|
| 920 |
+
)
|
| 921 |
+
else:
|
| 922 |
+
result = extract_download(task, archive, args.delete_zip_after_extract)
|
| 923 |
+
extraction_results.append(result)
|
| 924 |
+
logs.record_extraction(result)
|
| 925 |
+
extraction_progress.complete(
|
| 926 |
+
index, result.status, result.archive, failed=bool(result.error)
|
| 927 |
+
)
|
| 928 |
+
finally:
|
| 929 |
+
extraction_progress.finish()
|
| 930 |
|
| 931 |
download_failures = sum(1 for result in results if result.error)
|
| 932 |
extraction_failures = sum(1 for result in extraction_results if result.error)
|
Utils/scripts/download_selected.py
CHANGED
|
@@ -14,7 +14,7 @@ from pathlib import Path, PurePosixPath
|
|
| 14 |
from typing import Optional, Sequence
|
| 15 |
from urllib.parse import quote, urlparse
|
| 16 |
|
| 17 |
-
from download_data import DownloadResult, download_file, utc_now
|
| 18 |
|
| 19 |
|
| 20 |
SCRIPT_ROOT = Path(__file__).resolve().parent
|
|
@@ -229,31 +229,38 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
| 229 |
run_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 230 |
logs = Logs(output_dir / "_download_logs" / run_id)
|
| 231 |
results = []
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
failures = sum(1 for result in results if result.error)
|
| 259 |
summary = {
|
|
|
|
| 14 |
from typing import Optional, Sequence
|
| 15 |
from urllib.parse import quote, urlparse
|
| 16 |
|
| 17 |
+
from download_data import DownloadProgress, DownloadResult, download_file, utc_now
|
| 18 |
|
| 19 |
|
| 20 |
SCRIPT_ROOT = Path(__file__).resolve().parent
|
|
|
|
| 229 |
run_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 230 |
logs = Logs(output_dir / "_download_logs" / run_id)
|
| 231 |
results = []
|
| 232 |
+
progress = DownloadProgress(len(planned), "Downloading")
|
| 233 |
+
try:
|
| 234 |
+
with ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 235 |
+
futures = {
|
| 236 |
+
pool.submit(
|
| 237 |
+
download_file,
|
| 238 |
+
"full_dataset",
|
| 239 |
+
remote_path,
|
| 240 |
+
destination,
|
| 241 |
+
args.revision,
|
| 242 |
+
args.timeout,
|
| 243 |
+
args.retries,
|
| 244 |
+
not args.no_resume,
|
| 245 |
+
args.overwrite,
|
| 246 |
+
False,
|
| 247 |
+
repository,
|
| 248 |
+
progress,
|
| 249 |
+
index,
|
| 250 |
+
): (index, case_id, repository)
|
| 251 |
+
for index, (case_id, repository, remote_path, destination)
|
| 252 |
+
in enumerate(planned)
|
| 253 |
+
}
|
| 254 |
+
for future in as_completed(futures):
|
| 255 |
+
key, case_id, repository = futures[future]
|
| 256 |
+
result = future.result()
|
| 257 |
+
results.append(result)
|
| 258 |
+
logs.record(case_id, repository, result)
|
| 259 |
+
progress.complete(
|
| 260 |
+
key, result.status, result.local_path, failed=bool(result.error)
|
| 261 |
+
)
|
| 262 |
+
finally:
|
| 263 |
+
progress.finish()
|
| 264 |
|
| 265 |
failures = sum(1 for result in results if result.error)
|
| 266 |
summary = {
|