Skip to content

Commit 6cd9f64

Browse files
committed
Use a python script instead
1 parent d077dd9 commit 6cd9f64

File tree

2 files changed

+69
-32
lines changed

2 files changed

+69
-32
lines changed

.github/workflows/httomolibgpu_tests_run_iris.yml

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,41 +33,12 @@ jobs:
3333

3434
- name: Download test data from Zenodo
3535
run: |
36-
# Install required tools
37-
dnf install -y epel-release
38-
dnf install -y curl jq
36+
chmod +x ./.scripts/download_zenodo.py
3937
40-
# Create a directory to store test data
41-
mkdir -p tests/large_data_archive
42-
cd tests/large_data_archive
38+
./.scripts/download_zenodo.py tests/large_data_archive
4339
44-
# Download and process all files from Zenodo
45-
echo "Fetching files from Zenodo record 14338424..."
46-
curl -s "https://zenodo.org/api/records/14338424" | \
47-
jq -r '.files.entries[] | [.key, .links.content, .checksum] | @tsv' | \
48-
while IFS=$'\t' read -r filename url checksum; do
49-
echo "Downloading ${filename}..."
50-
curl -L -o "${filename}" "${url}"
51-
52-
# Extract MD5 from checksum string (removes 'md5:' prefix)
53-
expected_md5=${checksum#md5:}
54-
actual_md5=$(md5sum "${filename}" | cut -d' ' -f1)
55-
56-
if [ "${actual_md5}" = "${expected_md5}" ]; then
57-
echo "✓ Verified ${filename}"
58-
else
59-
echo "✗ Checksum verification failed for ${filename}"
60-
echo "Expected: ${expected_md5}"
61-
echo "Got: ${actual_md5}"
62-
exit 1
63-
fi
64-
done
65-
66-
# Show downloaded files
6740
echo -e "\nDownloaded files:"
68-
ls -lh
69-
70-
cd ../..
41+
ls -lh tests/large_data_archive
7142
7243
- name: Install httomolibgpu
7344
run: |

.scripts/download_zenodo.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import urllib.request
5+
import hashlib
6+
import sys
7+
import os
8+
from pathlib import Path
9+
10+
11+
def calculate_md5(filename):
12+
"""Calculate MD5 hash of a file."""
13+
md5_hash = hashlib.md5()
14+
with open(filename, "rb") as f:
15+
for chunk in iter(lambda: f.read(4096), b""):
16+
md5_hash.update(chunk)
17+
return md5_hash.hexdigest()
18+
19+
20+
def download_zenodo_files(output_dir: Path):
21+
"""
22+
Download all files from Zenodo record 14338424 and verify their checksums.
23+
24+
Args:
25+
output_dir: Directory where files should be downloaded
26+
"""
27+
try:
28+
print("Fetching files from Zenodo record 14338424...")
29+
with urllib.request.urlopen("https://zenodo.org/api/records/14338424") as response:
30+
data = json.loads(response.read())
31+
32+
# Create output directory if it doesn't exist
33+
output_dir.mkdir(parents=True, exist_ok=True)
34+
35+
for filename, file_info in data["files"]["entries"].items():
36+
output_file = output_dir / filename
37+
print(f"Downloading {filename}...")
38+
url = file_info["links"]["content"]
39+
expected_md5 = file_info["checksum"].split(":")[1]
40+
41+
# Download file
42+
urllib.request.urlretrieve(url, output_file)
43+
44+
# Verify checksum
45+
actual_md5 = calculate_md5(output_file)
46+
if actual_md5 == expected_md5:
47+
print(f"✓ Verified {filename}")
48+
else:
49+
print(f"✗ Checksum verification failed for {filename}")
50+
print(f"Expected: {expected_md5}")
51+
print(f"Got: {actual_md5}")
52+
sys.exit(1)
53+
54+
print("\nAll files downloaded and verified successfully!")
55+
56+
except Exception as e:
57+
print(f"Error: {str(e)}", file=sys.stderr)
58+
sys.exit(1)
59+
60+
if __name__ == "__main__":
61+
if len(sys.argv) != 2:
62+
print("Usage: download_zenodo.py <output_directory>")
63+
sys.exit(1)
64+
65+
output_dir = Path(sys.argv[1])
66+
download_zenodo_files(output_dir)

0 commit comments

Comments
 (0)