186e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller#!/usr/bin/python -B 286e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 356166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# Copyright 2017 The Android Open Source Project 456166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# 556166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# Licensed under the Apache License, Version 2.0 (the "License"); 656166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# you may not use this file except in compliance with the License. 756166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# You may obtain a copy of the License at 856166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# 956166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# http://www.apache.org/licenses/LICENSE-2.0 1056166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# 1156166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# Unless required by applicable law or agreed to in writing, software 1256166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# distributed under the License is distributed on an "AS IS" BASIS, 1356166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1456166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# See the License for the specific language governing permissions and 1556166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller# limitations under the License. 1656166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller 1756166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller"""Generates the timezone data files used by Android.""" 1886e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 1986e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerimport glob 2086e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerimport os 21cdf5695c2b83e2781c287d8d315eb903554940daNeil Fullerimport re 2286e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerimport subprocess 2386e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerimport sys 2486e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerimport tarfile 2586e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerimport tempfile 2686e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 27ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fullersys.path.append('%s/external/icu/tools' % os.environ.get('ANDROID_BUILD_TOP')) 2886e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerimport i18nutil 29fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fullerimport icuutil 3056166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fullerimport tzdatautil 3186e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 3286e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 3386e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller# Calculate the paths that are referred to by multiple functions. 3486e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerandroid_build_top = i18nutil.GetAndroidRootOrDie() 3556166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fullertimezone_dir = os.path.realpath('%s/system/timezone' % android_build_top) 3656166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fulleri18nutil.CheckDirExists(timezone_dir, 'system/timezone') 3786e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 388cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fullerandroid_host_out = i18nutil.GetAndroidHostOutOrDie() 398cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller 4056166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fullerzone_compactor_dir = os.path.realpath('%s/system/timezone/zone_compactor' % android_build_top) 4156166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fulleri18nutil.CheckDirExists(timezone_dir, 'system/timezone/zone_zompactor') 4256166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller 43cdf5695c2b83e2781c287d8d315eb903554940daNeil Fullertimezone_input_tools_dir = os.path.realpath('%s/input_tools' % timezone_dir) 4456166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fullertimezone_input_data_dir = os.path.realpath('%s/input_data' % timezone_dir) 4586e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 4635467e1256656196572e77251683e349d8f1055aNeil Fullertimezone_output_data_dir = '%s/output_data' % timezone_dir 4735467e1256656196572e77251683e349d8f1055aNeil Fulleri18nutil.CheckDirExists(timezone_output_data_dir, 'output_data') 4886e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 4956166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fullertmp_dir = tempfile.mkdtemp('-tzdata') 5086e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 51b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fullerdef GenerateZicInputFile(extracted_iana_data_dir): 52b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller # Android APIs assume DST means "summer time" so we follow the rearguard format 53b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller # introduced in 2018e. 54b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller zic_input_file_name = 'rearguard.zi' 5586e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 56b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller # 'NDATA=' is used to remove unnecessary rules files. 57b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller subprocess.check_call(['make', '-C', extracted_iana_data_dir, 'NDATA=', zic_input_file_name]) 58b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller 59b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller zic_input_file = '%s/%s' % (extracted_iana_data_dir, zic_input_file_name) 60b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller if not os.path.exists(zic_input_file): 61b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller print 'Could not find %s' % zic_input_file 62b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller sys.exit(1) 63b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller return zic_input_file 64b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller 65b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller 66b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fullerdef WriteSetupFile(zic_input_file): 6786e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller """Writes the list of zones that ZoneCompactor should process.""" 6886e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller links = [] 6986e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller zones = [] 70b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller for line in open(zic_input_file): 71b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller fields = line.split() 72b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller if fields: 73b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller if fields[0] == 'Link': 74b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller links.append('%s %s %s' % (fields[0], fields[1], fields[2])) 75b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller zones.append(fields[2]) 76b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller elif fields[0] == 'Zone': 77b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller zones.append(fields[1]) 7886e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller zones.sort() 7986e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 8086e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller zone_compactor_setup_file = '%s/setup' % tmp_dir 8186e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller setup = open(zone_compactor_setup_file, 'w') 8286e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller for link in sorted(set(links)): 8386e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller setup.write('%s\n' % link) 8486e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller for zone in sorted(set(zones)): 8586e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller setup.write('%s\n' % zone) 8686e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller setup.close() 8786e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller return zone_compactor_setup_file 8886e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 8986e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 90cdf5695c2b83e2781c287d8d315eb903554940daNeil Fullerdef BuildIcuData(iana_data_tar_file): 9186e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller icu_build_dir = '%s/icu' % tmp_dir 9286e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 93fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller icuutil.PrepareIcuBuild(icu_build_dir) 94cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller icuutil.MakeTzDataFiles(icu_build_dir, iana_data_tar_file) 95fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller 96fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller # Create ICU system image files. 97fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller icuutil.MakeAndCopyIcuDataFiles(icu_build_dir) 98fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller 99fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller # Create the ICU overlay time zone file. 100fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller icu_overlay_dat_file = '%s/icu_overlay/icu_tzdata.dat' % timezone_output_data_dir 101fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller icuutil.MakeAndCopyOverlayTzIcuData(icu_build_dir, icu_overlay_dat_file) 10286e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 10386e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 104cdf5695c2b83e2781c287d8d315eb903554940daNeil Fullerdef GetIanaVersion(iana_tar_file): 105cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_tar_filename = os.path.basename(iana_tar_file) 106cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_version = re.search('tz(?:data|code)(.+)\\.tar\\.gz', iana_tar_filename).group(1) 107ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller return iana_version 108ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 1098cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller 110cdf5695c2b83e2781c287d8d315eb903554940daNeil Fullerdef ExtractTarFile(tar_file, dir): 111cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Extracting %s...' % tar_file 112cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller if not os.path.exists(dir): 113cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller os.mkdir(dir) 114cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller tar = tarfile.open(tar_file, 'r') 115cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller tar.extractall(dir) 11686e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 117cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 118cdf5695c2b83e2781c287d8d315eb903554940daNeil Fullerdef BuildZic(iana_tools_dir): 119cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_zic_code_tar_file = tzdatautil.GetIanaTarFile(iana_tools_dir, 'code') 120cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_zic_code_version = GetIanaVersion(iana_zic_code_tar_file) 121cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_zic_data_tar_file = tzdatautil.GetIanaTarFile(iana_tools_dir, 'data') 122cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_zic_data_version = GetIanaVersion(iana_zic_data_tar_file) 123cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 124cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Found IANA zic release %s/%s in %s/%s ...' \ 125cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller % (iana_zic_code_version, iana_zic_data_version, iana_zic_code_tar_file, iana_zic_data_tar_file) 126cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 127cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller zic_build_dir = '%s/zic' % tmp_dir 128cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller ExtractTarFile(iana_zic_code_tar_file, zic_build_dir) 129cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller ExtractTarFile(iana_zic_data_tar_file, zic_build_dir) 130cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 131cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller # zic 132cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Building zic...' 133cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller # VERSION_DEPS= is to stop the build process looking for files that might not 134cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller # be present across different versions. 135cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller subprocess.check_call(['make', '-C', zic_build_dir, 'zic']) 136cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 137cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller zic_binary_file = '%s/zic' % zic_build_dir 138cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller if not os.path.exists(zic_binary_file): 139b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller print 'Could not find %s' % zic_binary_file 140b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller sys.exit(1) 141cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller return zic_binary_file 142cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 143cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 144cdf5695c2b83e2781c287d8d315eb903554940daNeil Fullerdef BuildTzdata(zic_binary_file, extracted_iana_data_dir, iana_data_version): 145b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller print 'Generating zic input file...' 146b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller zic_input_file = GenerateZicInputFile(extracted_iana_data_dir) 147b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller 148cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Calling zic...' 14986e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller zic_output_dir = '%s/data' % tmp_dir 15086e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller os.mkdir(zic_output_dir) 151b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller zic_cmd = [zic_binary_file, '-d', zic_output_dir, zic_input_file] 15286e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller subprocess.check_call(zic_cmd) 15386e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 154cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller # ZoneCompactor 155b3ff82bdc7cfb2c3bd1971d3ad5d843b7424b76aNeil Fuller zone_compactor_setup_file = WriteSetupFile(zic_input_file) 15686e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 157cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Calling ZoneCompactor to update tzdata to %s...' % iana_data_version 1588cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller subprocess.check_call(['make', '-C', android_build_top, '-j30', 'zone_compactor']) 15986e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 160cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller # Create args for ZoneCompactor 161cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller zone_tab_file = '%s/zone.tab' % extracted_iana_data_dir 1628cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller jar_file = '%s/framework/zone_compactor.jar' % android_host_out 163cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller header_string = 'tzdata%s' % iana_data_version 16435467e1256656196572e77251683e349d8f1055aNeil Fuller 165cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Executing ZoneCompactor...' 16635467e1256656196572e77251683e349d8f1055aNeil Fuller iana_output_data_dir = '%s/iana' % timezone_output_data_dir 1678cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller subprocess.check_call(['java', '-jar', jar_file, 16886e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller zone_compactor_setup_file, zic_output_dir, zone_tab_file, 169ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller iana_output_data_dir, header_string]) 17056166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller 17156166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller 1728cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fullerdef BuildTzlookup(iana_data_dir): 1738cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller countryzones_source_file = '%s/android/countryzones.txt' % timezone_input_data_dir 17435467e1256656196572e77251683e349d8f1055aNeil Fuller tzlookup_dest_file = '%s/android/tzlookup.xml' % timezone_output_data_dir 1758cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller 1768cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller print 'Calling TzLookupGenerator to create tzlookup.xml...' 1778cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller subprocess.check_call(['make', '-C', android_build_top, '-j30', 'tzlookup_generator']) 1788cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller 1798cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller jar_file = '%s/framework/tzlookup_generator.jar' % android_host_out 1808cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller zone_tab_file = '%s/zone.tab' % iana_data_dir 1818cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller subprocess.check_call(['java', '-jar', jar_file, 1828cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller countryzones_source_file, zone_tab_file, tzlookup_dest_file]) 18356166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller 18486e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 185cdf5695c2b83e2781c287d8d315eb903554940daNeil Fullerdef CreateDistroFiles(iana_data_version, output_dir): 186ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller create_distro_script = '%s/distro/tools/create-distro.py' % timezone_dir 187ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 188ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller tzdata_file = '%s/iana/tzdata' % timezone_output_data_dir 189ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller icu_file = '%s/icu_overlay/icu_tzdata.dat' % timezone_output_data_dir 190ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller tzlookup_file = '%s/android/tzlookup.xml' % timezone_output_data_dir 191ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 192ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller distro_file_pattern = '%s/*.zip' % output_dir 193ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller existing_distro_files = glob.glob(distro_file_pattern) 194ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 195ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller distro_file_metadata_pattern = '%s/*.txt' % output_dir 196ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller existing_distro_metadata_files = glob.glob(distro_file_metadata_pattern) 197ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller existing_files = existing_distro_files + existing_distro_metadata_files 198ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 199ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller print 'Removing %s' % existing_files 200ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller for existing_file in existing_files: 201ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller os.remove(existing_file) 202ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 203ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller subprocess.check_call([create_distro_script, 204cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller '-iana_version', iana_data_version, 205ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller '-tzdata', tzdata_file, 206ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller '-icu', icu_file, 207ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller '-tzlookup', tzlookup_file, 208ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller '-output', output_dir]) 209ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 210ad3c8765bbef6988a382bc834e1f30cf5a31d1abNeil Fullerdef UpdateTestFiles(): 211ad3c8765bbef6988a382bc834e1f30cf5a31d1abNeil Fuller testing_data_dir = '%s/testing/data' % timezone_dir 212ad3c8765bbef6988a382bc834e1f30cf5a31d1abNeil Fuller update_test_files_script = '%s/create-test-data.sh' % testing_data_dir 213ad3c8765bbef6988a382bc834e1f30cf5a31d1abNeil Fuller subprocess.check_call([update_test_files_script], cwd=testing_data_dir) 214ad3c8765bbef6988a382bc834e1f30cf5a31d1abNeil Fuller 21586e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 21686e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller# Run with no arguments from any directory, with no special setup required. 21786e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller# See http://www.iana.org/time-zones/ for more about the source of this data. 21886e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerdef main(): 219cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Source data file structure: %s' % timezone_input_data_dir 220cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Source tools file structure: %s' % timezone_input_tools_dir 221cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'Output data file structure: %s' % timezone_output_data_dir 22256166d33b6f3f7d96aef742fc0a52e961fd3cacfNeil Fuller 2238cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller iana_input_data_dir = '%s/iana' % timezone_input_data_dir 224cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_data_tar_file = tzdatautil.GetIanaTarFile(iana_input_data_dir, 'data') 225cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_data_version = GetIanaVersion(iana_data_tar_file) 226cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller print 'IANA time zone data release %s in %s ...' % (iana_data_version, iana_data_tar_file) 227fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller 228fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller icu_dir = icuutil.icuDir() 229fa89b0369c51916b0cda5e4456f134ec50be3ebaNeil Fuller print 'Found icu in %s ...' % icu_dir 23086e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 231cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller BuildIcuData(iana_data_tar_file) 232cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 233cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_tools_dir = '%s/iana' % timezone_input_tools_dir 234cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller zic_binary_file = BuildZic(iana_tools_dir) 235cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller 236cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller iana_data_dir = '%s/iana_data' % tmp_dir 237cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller ExtractTarFile(iana_data_tar_file, iana_data_dir) 238cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller BuildTzdata(zic_binary_file, iana_data_dir, iana_data_version) 2398cec561a92ae3675ae6a6a0ff932860f29a43a78Neil Fuller BuildTzlookup(iana_data_dir) 240ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 241ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller # Create a distro file from the output from prior stages. 242ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller distro_output_dir = '%s/distro' % timezone_output_data_dir 243cdf5695c2b83e2781c287d8d315eb903554940daNeil Fuller CreateDistroFiles(iana_data_version, distro_output_dir) 244ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller 245ad3c8765bbef6988a382bc834e1f30cf5a31d1abNeil Fuller # Update test versions of distro files too. 246ad3c8765bbef6988a382bc834e1f30cf5a31d1abNeil Fuller UpdateTestFiles() 247ad3c8765bbef6988a382bc834e1f30cf5a31d1abNeil Fuller 248ad7e81c00260b6dcb9d9ecf2c3c8aa161f555059Neil Fuller print 'Look in %s and %s for new files' % (timezone_output_data_dir, icu_dir) 24986e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller sys.exit(0) 25086e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 25186e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller 25286e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fullerif __name__ == '__main__': 25386e72c5e93b6f4ef2f0d15e65e90b0a26d105ea0Neil Fuller main() 254