Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ deps =
requests
click
parver
python-gnupg
commands =
python update.py {posargs}

Expand Down
28 changes: 26 additions & 2 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from datetime import datetime, timezone

import click
import gnupg # type: ignore
import parver # type: ignore
import requests

Expand All @@ -37,13 +38,15 @@ def download_tzdb_tarballs(
"""Download the tzdata and tzcode tarballs."""
tzdata_file = f"tzdata{version}.tar.gz"
tzcode_file = f"tzcode{version}.tar.gz"
tzdata_file_asc = tzdata_file + ".asc"
tzcode_file_asc = tzcode_file + ".asc"

target_dir = working_dir / version / "download"
# mkdir -p target_dir
target_dir.mkdir(parents=True, exist_ok=True)

download_locations = []
for filename in [tzdata_file, tzcode_file]:
for filename in [tzdata_file, tzcode_file, tzdata_file_asc, tzcode_file_asc]:
download_location = target_dir / filename
download_locations.append(download_location)

Expand All @@ -58,6 +61,25 @@ def download_tzdb_tarballs(
with open(download_location, "wb") as f:
f.write(r.content)

# Verify tarballs
gpg_home = tempfile.TemporaryDirectory()
gpg = gnupg.GPG(gnupghome=gpg_home.name)
gpg.recv_keys("hkps://keyserver.ubuntu.com", "ed97e90e62aa7e34")

for tar, asc in [(tzdata_file, tzdata_file_asc), (tzcode_file, tzcode_file_asc)]:
tar_path = target_dir / tar
sig_path = target_dir / asc

if not tar_path.exists() or not sig_path.exists():
raise FileNotFoundError(
f"Missing file or signature: {tar_path}, {sig_path}"
)

with open(sig_path, "rb") as f:
check = gpg.verify_file(f, str(tar_path))
if not check.valid:
raise RuntimeError(f"signature verification failed for {tar_path}")

return download_locations


Expand Down Expand Up @@ -95,7 +117,7 @@ def retrieve_local_tarballs(
def unpack_tzdb_tarballs(
download_locations: Sequence[pathlib.Path],
) -> pathlib.Path:
assert len(download_locations) == 2
assert len(download_locations) == 4
assert download_locations[0].parent == download_locations[1].parent
base_dir = download_locations[0].parent.parent
target_dir = base_dir / "tzdb"
Expand All @@ -107,6 +129,8 @@ def unpack_tzdb_tarballs(
target_dir.mkdir()

for tarball in download_locations:
if tarball.suffix == ".asc":
continue
logging.info("Unpacking %s to %s", tarball, target_dir)
subprocess.run(
["tar", "-xf", os.fspath(tarball.absolute())],
Expand Down
Loading