Skip to content

Commit e6b47c2

Browse files
committed
Intermediate changes
commit_hash:12a7066cdbc92f34c31f175afc939d2a2e2e3ed7
1 parent d39c61a commit e6b47c2

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

contrib/libs/cctz/tzdata/update_tzdata.py renamed to contrib/libs/cctz/tzdata/update.py

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import glob
44
import hashlib
5+
import io
56
import os
67
import re
78
import shutil
@@ -12,6 +13,7 @@
1213
import tempfile
1314
import urllib.request
1415

16+
1517
def create_cmakelists(zoneinfo_dir):
1618
tz_to_hash = {}
1719
hash_to_content = {}
@@ -53,62 +55,74 @@ def create_cmakelists(zoneinfo_dir):
5355
with open('ya.make.resources', 'w') as f:
5456
print(yamake_template.format(resources), file=f)
5557

56-
def get_latest_iana_version():
58+
59+
def get_latest_version():
60+
# Temporary here for the purposes of reimport
61+
return "2024a"
5762
index_html = urllib.request.urlopen('http://www.iana.org/time-zones').read()
5863
version_match = re.search('<a href="[^"]*">tzdata(.*).tar.gz</a>', index_html.decode())
5964
if not version_match:
6065
raise Exception('Failed to determine the latest tzdata version')
6166
return version_match.group(1)
6267

68+
6369
def get_current_version():
6470
try:
6571
with open('VERSION') as f:
6672
return f.read()
6773
except:
6874
return 0
6975

76+
7077
def prepare_tzdata(version):
71-
temp_dir = tempfile.mkdtemp()
72-
try:
73-
for file_type in ('data', 'code'):
74-
file_name = 'tz{}{}.tar.gz'.format(file_type, version)
75-
full_url = 'http://www.iana.org/time-zones/repository/releases/{}'.format(file_name)
76-
print('Downloading {}'.format(full_url))
78+
temp_dir = "tmp"
79+
shutil.rmtree(temp_dir, ignore_errors=True)
7780

78-
local_file_name = os.path.join(temp_dir, file_name)
79-
with open(local_file_name, 'wb') as f:
80-
f.write(urllib.request.urlopen(full_url).read())
81+
EXCLUDE = [
82+
"iso3166.tab",
83+
"zone.tab",
84+
"zonenow.tab",
85+
]
8186

82-
print('Extracting {}'.format(local_file_name))
83-
with tarfile.open(local_file_name) as f:
87+
try:
88+
for type in ('data', 'code'):
89+
filename = f'tz{type}{version}.tar.gz'
90+
url = f'http://www.iana.org/time-zones/repository/releases/{filename}'
91+
print(f'Downloading {url}')
92+
93+
bytestream = io.BytesIO(urllib.request.urlopen(url).read())
94+
print(f'Extracting {filename}')
95+
with tarfile.open(fileobj=bytestream, mode="r:gz") as f:
8496
f.extractall(path=temp_dir)
85-
97+
8698
print('Converting tzdata to binary format')
87-
subprocess.check_call(['make', '-s', '-C', temp_dir, 'TOPDIR={}'.format(temp_dir), 'install'])
99+
subprocess.check_call(
100+
['make', "--silent", "TOPDIR=.", 'install'],
101+
cwd=temp_dir,
102+
)
103+
104+
shutil.rmtree(f"{temp_dir}/usr/share/zoneinfo/etc")
105+
for path in EXCLUDE:
106+
os.remove(f"{temp_dir}/usr/share/zoneinfo/{path}")
107+
108+
# keep posixrules for now
109+
shutil.copyfile(
110+
"generated/58543f30ac34b6510b552b9b3e82b772",
111+
f"{temp_dir}/usr/share/zoneinfo/posixrules",
112+
)
88113

89114
print('Preparing ya.make.resources')
90-
zoneinfo_dir = os.path.join(temp_dir, 'usr', 'share', 'zoneinfo')
91-
create_cmakelists(zoneinfo_dir)
115+
create_cmakelists(f"{temp_dir}/usr/share/zoneinfo")
92116
finally:
93117
shutil.rmtree(temp_dir)
94118

119+
95120
def main():
96-
current_version, latest_version = get_current_version(), get_latest_iana_version()
97-
print('The current version of tzdata is {}'.format(current_version))
98-
print('The latest version of tzdata on the IANA site is {}'.format(latest_version))
99-
if current_version == latest_version:
100-
print('You already have the latest version')
101-
return
102-
print('Updating from {} to {}'.format(current_version, latest_version))
103-
prepare_tzdata(latest_version)
104-
105-
with open('VERSION', 'w') as f:
106-
f.write(latest_version)
107-
108-
print('All good! Now make sure the tests pass, and run this:')
109-
print('arc add VERSION update_tzdata.py ya.make.resources')
110-
print('arc co -b tzdata.{}'.format(latest_version))
111-
print('arc ci . -m "Updated tzdata from {} to {}"'.format(current_version, latest_version))
121+
version_current = get_current_version()
122+
version_latest = get_latest_version()
123+
print(f'Updating from {version_current} to {version_latest}')
124+
prepare_tzdata(version_latest)
112125

113126
if __name__ == '__main__':
127+
114128
main()

0 commit comments

Comments
 (0)