Skip to content

Commit a047430

Browse files
committed
Add progress bar and logging to shared library downloader
1 parent 9b6ec66 commit a047430

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

scripts/update_shared_library.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
import requests
22
import os
33
import re
4+
from tqdm import tqdm
45

56
REPO = "bogdanfinn/tls-client"
67
DEST_DIR = "../async_tls_client/dependencies/"
78
MAJOR_VERSION = "1"
89

9-
# Regex to strip version from filenames like -v1.8.0
1010
version_pattern = re.compile(r"-v?\d+\.\d+\.\d+")
1111

12-
# Mapping from original GitHub filenames (without version) to local dependency filenames
1312
rename_map = {
14-
# Windows
1513
"tls-client-windows-32.dll": "tls-client-32.dll",
1614
"tls-client-windows-64.dll": "tls-client-64.dll",
17-
# MacOS
1815
"tls-client-darwin-arm64.dylib": "tls-client-arm64.dylib",
1916
"tls-client-darwin-amd64.dylib": "tls-client-x86.dylib",
20-
# Linux
2117
"tls-client-linux-alpine-amd64.so": "tls-client-amd64.so",
2218
"tls-client-linux-ubuntu-amd64.so": "tls-client-x86.so",
2319
"tls-client-linux-arm64.so": "tls-client-arm64.so",
2420
}
2521

26-
# Fetch all releases
2722
releases_url = f"https://api.github.com/repos/{REPO}/releases"
23+
print(f"Fetching releases from {releases_url}")
2824
releases = requests.get(releases_url).json()
2925

30-
# Find the latest release with the desired major version
3126
latest_release = None
3227
for release in releases:
3328
tag = release.get("tag_name", "")
@@ -37,28 +32,33 @@
3732
break
3833

3934
if not latest_release:
40-
print(f"No release found with major version {MAJOR_VERSION}.")
35+
print(f"[!] No release found with major version {MAJOR_VERSION}.")
4136
exit(1)
4237

4338
tag_name = latest_release["tag_name"]
4439
assets = latest_release.get("assets", [])
40+
print(f"Latest release found: {tag_name} with {len(assets)} assets")
4541
os.makedirs(DEST_DIR, exist_ok=True)
4642

4743
for asset in assets:
4844
name = asset["name"]
49-
50-
# Strip version from filename
5145
name_stripped = version_pattern.sub("", name)
52-
53-
# Apply renaming if matched
5446
target_name = rename_map.get(name_stripped)
47+
5548
if not target_name:
56-
print(f"Skipping unmatched file: {name}")
49+
print(f"[skip] Unmatched file: {name}")
5750
continue
5851

5952
download_url = asset["browser_download_url"]
60-
print(f"Downloading {name}{target_name}")
53+
print(f"[→] Downloading {name}{target_name}")
54+
response = requests.get(download_url, stream=True)
55+
total = int(response.headers.get("content-length", 0))
56+
57+
with open(os.path.join(DEST_DIR, target_name), "wb") as f, tqdm(
58+
total=total, unit="B", unit_scale=True, unit_divisor=1024
59+
) as bar:
60+
for chunk in response.iter_content(chunk_size=8192):
61+
f.write(chunk)
62+
bar.update(len(chunk))
6163

62-
response = requests.get(download_url)
63-
with open(os.path.join(DEST_DIR, target_name), "wb") as f:
64-
f.write(response.content)
64+
print("[✓] All matched assets downloaded.")

0 commit comments

Comments
 (0)