Skip to content

Commit 55e41d6

Browse files
committed
Add generation of the "zones" file.
This is a newline-delimited list of all the time zones in the package.
1 parent 03bacbc commit 55e41d6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

update.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def unpack_tzdb_tarballs(download_locations: typing.List[pathlib.Path]) -> pathl
7272
return target_dir
7373

7474

75-
def load_zonefiles(base_dir: pathlib.Path) -> pathlib.Path:
75+
def load_zonefiles(
76+
base_dir: pathlib.Path,
77+
) -> typing.Tuple[typing.List[str], pathlib.Path]:
7678
target_dir = base_dir.parent / "zoneinfo"
7779
if target_dir.exists():
7880
shutil.rmtree(target_dir)
@@ -85,14 +87,21 @@ def load_zonefiles(base_dir: pathlib.Path) -> pathlib.Path:
8587
["make", f"DESTDIR={td}", "ZFLAGS=-b slim", "install"], cwd=base_dir
8688
)
8789

90+
proc = subprocess.run(
91+
["make", "zonenames"], cwd=base_dir, stdout=subprocess.PIPE, check=True
92+
)
93+
zonenames = list(map(str.strip, proc.stdout.decode("utf-8").split("\n")))
94+
8895
# Move the zoneinfo files into the target directory
8996
src_dir = td_path / "usr" / "share" / "zoneinfo"
9097
shutil.move(os.fspath(src_dir), os.fspath(target_dir))
9198

92-
return target_dir
99+
return zonenames, target_dir
93100

94101

95-
def create_package(version: str, zoneinfo_dir: pathlib.Path):
102+
def create_package(
103+
version: str, zonenames: typing.List[str], zoneinfo_dir: pathlib.Path
104+
):
96105
"""Creates the tzdata package"""
97106
# First remove the existing package contents
98107
target_dir = PKG_BASE / "tzdata"
@@ -112,6 +121,10 @@ def create_package(version: str, zoneinfo_dir: pathlib.Path):
112121
with open(target_dir / "__init__.py", "w") as f_out:
113122
f_out.write(contents)
114123

124+
# Generate the "zones" file as a newline-delimited list
125+
with open(target_dir / "zones", "w") as f:
126+
f.write("\n".join(zonenames))
127+
115128
# Now recursively create __init__.py files in every directory we need to
116129
for dirpath, _, filenames in os.walk(data_dir):
117130
if "__init__.py" not in filenames:
@@ -151,9 +164,9 @@ def main(version: str):
151164
download_locations = download_tzdb_tarballs(version)
152165
tzdb_location = unpack_tzdb_tarballs(download_locations)
153166

154-
zonefile_path = load_zonefiles(tzdb_location)
167+
zonenames, zonefile_path = load_zonefiles(tzdb_location)
155168

156-
create_package(version, zonefile_path)
169+
create_package(version, zonenames, zonefile_path)
157170

158171

159172
if __name__ == "__main__":

0 commit comments

Comments
 (0)