15d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes#!/usr/bin/python 25b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 3246c6880207539d01e84a6f049cd639139a0691aNeil Fuller"""Updates the timezone data held in bionic and ICU.""" 4d40e63ee47e4a7f072a9d9a20e09c26f0090b02cElliott Hughes 55d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughesimport ftplib 6246c6880207539d01e84a6f049cd639139a0691aNeil Fullerimport glob 7f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughesimport httplib 85d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughesimport os 95d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughesimport re 10246c6880207539d01e84a6f049cd639139a0691aNeil Fullerimport shutil 115d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughesimport subprocess 125d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughesimport sys 135d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughesimport tarfile 145d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughesimport tempfile 155d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 16371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughesregions = ['africa', 'antarctica', 'asia', 'australasia', 17371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes 'etcetera', 'europe', 'northamerica', 'southamerica', 18371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes # These two deliberately come last so they override what came 19371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes # before (and each other). 20371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes 'backward', 'backzone' ] 215b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 22246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef CheckDirExists(dir, dirname): 23246c6880207539d01e84a6f049cd639139a0691aNeil Fuller if not os.path.isdir(dir): 24246c6880207539d01e84a6f049cd639139a0691aNeil Fuller print "Couldn't find %s (%s)!" % (dirname, dir) 25246c6880207539d01e84a6f049cd639139a0691aNeil Fuller sys.exit(1) 265b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 27246c6880207539d01e84a6f049cd639139a0691aNeil Fullerbionic_libc_tools_zoneinfo_dir = os.path.realpath(os.path.dirname(sys.argv[0])) 285d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 29246c6880207539d01e84a6f049cd639139a0691aNeil Fuller# Find the bionic directory, searching upward from this script. 30246c6880207539d01e84a6f049cd639139a0691aNeil Fullerbionic_dir = os.path.realpath('%s/../../..' % bionic_libc_tools_zoneinfo_dir) 31246c6880207539d01e84a6f049cd639139a0691aNeil Fullerbionic_libc_zoneinfo_dir = '%s/libc/zoneinfo' % bionic_dir 32246c6880207539d01e84a6f049cd639139a0691aNeil FullerCheckDirExists(bionic_libc_zoneinfo_dir, 'bionic/libc/zoneinfo') 33246c6880207539d01e84a6f049cd639139a0691aNeil FullerCheckDirExists(bionic_libc_tools_zoneinfo_dir, 'bionic/libc/tools/zoneinfo') 34246c6880207539d01e84a6f049cd639139a0691aNeil Fullerprint 'Found bionic in %s ...' % bionic_dir 355d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 36246c6880207539d01e84a6f049cd639139a0691aNeil Fuller# Find the icu4c directory. 3730ab93949626872b3e6ea35398c831017c4c378fElliott Hughesicu_dir = os.path.realpath('%s/../external/icu/icu4c/source' % bionic_dir) 3830ab93949626872b3e6ea35398c831017c4c378fElliott HughesCheckDirExists(icu_dir, 'external/icu/icu4c/source') 39246c6880207539d01e84a6f049cd639139a0691aNeil Fullerprint 'Found icu in %s ...' % icu_dir 405b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 415d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 425b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughesdef GetCurrentTzDataVersion(): 43e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes return open('%s/tzdata' % bionic_libc_zoneinfo_dir).read().split('\x00', 1)[0] 445d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 455d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 465b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughesdef WriteSetupFile(): 47e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes """Writes the list of zones that ZoneCompactor should process.""" 485b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes links = [] 495b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes zones = [] 505b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes for region in regions: 515b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes for line in open('extracted/%s' % region): 525b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes fields = line.split() 53e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes if fields: 54e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes if fields[0] == 'Link': 55371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes links.append('%s %s %s' % (fields[0], fields[1], fields[2])) 56e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes zones.append(fields[2]) 57e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes elif fields[0] == 'Zone': 58e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes zones.append(fields[1]) 595b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes zones.sort() 605d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 615b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes setup = open('setup', 'w') 62371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes for link in sorted(set(links)): 63371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes setup.write('%s\n' % link) 64371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes for zone in sorted(set(zones)): 655b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes setup.write('%s\n' % zone) 665b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes setup.close() 675d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 685d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 69f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughesdef SwitchToNewTemporaryDirectory(): 70f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes tmp_dir = tempfile.mkdtemp('-tzdata') 71f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes os.chdir(tmp_dir) 72f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes print 'Created temporary directory "%s"...' % tmp_dir 73e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes 74e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes 75246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef FtpRetrieveFile(ftp, filename): 76f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes ftp.retrbinary('RETR %s' % filename, open(filename, 'wb').write) 77e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes 785d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 79246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef FtpRetrieveFileAndSignature(ftp, data_filename): 80f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes """Downloads and repackages the given data from the given FTP server.""" 815d2ef8724d8978465b9795198099305d0f0b12d0Elliott Hughes print 'Downloading data...' 82246c6880207539d01e84a6f049cd639139a0691aNeil Fuller FtpRetrieveFile(ftp, data_filename) 835d2ef8724d8978465b9795198099305d0f0b12d0Elliott Hughes 845d2ef8724d8978465b9795198099305d0f0b12d0Elliott Hughes print 'Downloading signature...' 855d2ef8724d8978465b9795198099305d0f0b12d0Elliott Hughes signature_filename = '%s.asc' % data_filename 86246c6880207539d01e84a6f049cd639139a0691aNeil Fuller FtpRetrieveFile(ftp, signature_filename) 87f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 88f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 89246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef HttpRetrieveFile(http, path, output_filename): 90676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes http.request("GET", path) 91676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes f = open(output_filename, 'wb') 92676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes f.write(http.getresponse().read()) 93676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes f.close() 94676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes 95676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes 96246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef HttpRetrieveFileAndSignature(http, data_filename): 97f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes """Downloads and repackages the given data from the given HTTP server.""" 98676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes path = "/time-zones/repository/releases/%s" % data_filename 99676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes 100f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes print 'Downloading data...' 101246c6880207539d01e84a6f049cd639139a0691aNeil Fuller HttpRetrieveFile(http, path, data_filename) 102676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes 103676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes print 'Downloading signature...' 104676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes signature_filename = '%s.asc' % data_filename 105246c6880207539d01e84a6f049cd639139a0691aNeil Fuller HttpRetrievefile(http, "%s.asc" % path, signature_filename) 106f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 107f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 108246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef BuildIcuToolsAndData(data_filename): 109246c6880207539d01e84a6f049cd639139a0691aNeil Fuller # Keep track of the original cwd so we can go back to it at the end. 110246c6880207539d01e84a6f049cd639139a0691aNeil Fuller original_working_dir = os.getcwd() 111f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 112246c6880207539d01e84a6f049cd639139a0691aNeil Fuller # Create a directory to run 'make' from. 113246c6880207539d01e84a6f049cd639139a0691aNeil Fuller icu_working_dir = '%s/icu' % original_working_dir 114246c6880207539d01e84a6f049cd639139a0691aNeil Fuller os.mkdir(icu_working_dir) 115246c6880207539d01e84a6f049cd639139a0691aNeil Fuller os.chdir(icu_working_dir) 116246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 117246c6880207539d01e84a6f049cd639139a0691aNeil Fuller # Build the ICU tools. 118246c6880207539d01e84a6f049cd639139a0691aNeil Fuller print 'Configuring ICU tools...' 119246c6880207539d01e84a6f049cd639139a0691aNeil Fuller subprocess.check_call(['%s/runConfigureICU' % icu_dir, 'Linux']) 120246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 121246c6880207539d01e84a6f049cd639139a0691aNeil Fuller # Run the ICU tools. 122246c6880207539d01e84a6f049cd639139a0691aNeil Fuller os.chdir('tools/tzcode') 1234177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller 1244177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller # The tz2icu tool only picks up icuregions and icuzones in they are in the CWD 1254177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller for icu_data_file in [ 'icuregions', 'icuzones']: 1264177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller icu_data_file_source = '%s/tools/tzcode/%s' % (icu_dir, icu_data_file) 1274177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller icu_data_file_symlink = './%s' % icu_data_file 1284177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller os.symlink(icu_data_file_source, icu_data_file_symlink) 1294177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller 130246c6880207539d01e84a6f049cd639139a0691aNeil Fuller shutil.copyfile('%s/%s' % (original_working_dir, data_filename), data_filename) 131246c6880207539d01e84a6f049cd639139a0691aNeil Fuller print 'Making ICU data...' 1324177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller # The Makefile assumes the existence of the bin directory. 1334177bd8d16e0dc2d0d541fc54f81518c57651e55Neil Fuller os.mkdir('%s/bin' % icu_working_dir) 134246c6880207539d01e84a6f049cd639139a0691aNeil Fuller subprocess.check_call(['make']) 135246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 136b5f5b0e418e5c382573e367dd4aff9373180bbe4Elliott Hughes # Copy the source file to its ultimate destination. 137246c6880207539d01e84a6f049cd639139a0691aNeil Fuller icu_txt_data_dir = '%s/data/misc' % icu_dir 138246c6880207539d01e84a6f049cd639139a0691aNeil Fuller print 'Copying zoneinfo64.txt to %s ...' % icu_txt_data_dir 139246c6880207539d01e84a6f049cd639139a0691aNeil Fuller shutil.copy('zoneinfo64.txt', icu_txt_data_dir) 140246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 141b5f5b0e418e5c382573e367dd4aff9373180bbe4Elliott Hughes # Regenerate the .dat file. 142246c6880207539d01e84a6f049cd639139a0691aNeil Fuller os.chdir(icu_working_dir) 143b5f5b0e418e5c382573e367dd4aff9373180bbe4Elliott Hughes subprocess.check_call(['make', '-j32']) 144b5f5b0e418e5c382573e367dd4aff9373180bbe4Elliott Hughes 145b5f5b0e418e5c382573e367dd4aff9373180bbe4Elliott Hughes # Copy the .dat file to its ultimate destination. 146246c6880207539d01e84a6f049cd639139a0691aNeil Fuller icu_dat_data_dir = '%s/stubdata' % icu_dir 14743f37159532c1ef7218266957cc616f055b4dbacNeil Fuller datfiles = glob.glob('data/out/tmp/icudt??l.dat') 14843f37159532c1ef7218266957cc616f055b4dbacNeil Fuller if len(datfiles) != 1: 14943f37159532c1ef7218266957cc616f055b4dbacNeil Fuller print 'ERROR: Unexpectedly found %d .dat files (%s). Halting.' % (len(datfiles), datfiles) 15043f37159532c1ef7218266957cc616f055b4dbacNeil Fuller sys.exit(1) 15143f37159532c1ef7218266957cc616f055b4dbacNeil Fuller datfile = datfiles[0] 15243f37159532c1ef7218266957cc616f055b4dbacNeil Fuller print 'Copying %s to %s ...' % (datfile, icu_dat_data_dir) 15343f37159532c1ef7218266957cc616f055b4dbacNeil Fuller shutil.copy(datfile, icu_dat_data_dir) 154f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 155246c6880207539d01e84a6f049cd639139a0691aNeil Fuller # Switch back to the original working cwd. 156246c6880207539d01e84a6f049cd639139a0691aNeil Fuller os.chdir(original_working_dir) 157246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 158246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 159246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef CheckSignature(data_filename): 160676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes signature_filename = '%s.asc' % data_filename 161676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes print 'Verifying signature...' 162676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes # If this fails for you, you probably need to import Paul Eggert's public key: 163676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes # gpg --recv-keys ED97E90E62AA7E34 164676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes subprocess.check_call(['gpg', '--trusted-key=ED97E90E62AA7E34', '--verify', 165676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes signature_filename, data_filename]) 166676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes 167246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 168246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef BuildBionicToolsAndData(data_filename): 169246c6880207539d01e84a6f049cd639139a0691aNeil Fuller new_version = re.search('(tzdata.+)\\.tar\\.gz', data_filename).group(1) 170246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 1715d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes print 'Extracting...' 1725d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes os.mkdir('extracted') 173e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes tar = tarfile.open(data_filename, 'r') 1745d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes tar.extractall('extracted') 1755d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 1765d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes print 'Calling zic(1)...' 1775d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes os.mkdir('data') 178371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes zic_inputs = [ 'extracted/%s' % x for x in regions ] 179371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes zic_cmd = ['zic', '-d', 'data' ] 180371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes zic_cmd.extend(zic_inputs) 181371dcc189f62dbf5bc861aed41754a0ef1008ee5Elliott Hughes subprocess.check_call(zic_cmd) 1825d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 1835b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes WriteSetupFile() 1845d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes 1855b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes print 'Calling ZoneCompactor to update bionic to %s...' % new_version 1865d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes subprocess.check_call(['javac', '-d', '.', 18790cb5ffb85a9bc2e725824b3ca8db932d02c45dbElliott Hughes '%s/ZoneCompactor.java' % bionic_libc_tools_zoneinfo_dir]) 1885b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes subprocess.check_call(['java', 'ZoneCompactor', 1892393535f0d7df55dae3b4fbf5dbcfa7f87192762Elliott Hughes 'setup', 'data', 'extracted/zone.tab', 1902393535f0d7df55dae3b4fbf5dbcfa7f87192762Elliott Hughes bionic_libc_zoneinfo_dir, new_version]) 1915b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 1925b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 1935b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes# Run with no arguments from any directory, with no special setup required. 194e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes# See http://www.iana.org/time-zones/ for more about the source of this data. 1955b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughesdef main(): 1965b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes print 'Looking for new tzdata...' 197f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 1985b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes tzdata_filenames = [] 199f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 200f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes # The FTP server lets you download intermediate releases, and also lets you 20121da42ea91d45c43372d027f72467ecd66a33b29Elliott Hughes # download the signatures for verification, so it's your best choice. 202f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes use_ftp = True 203f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes 204f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes if use_ftp: 205f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes ftp = ftplib.FTP('ftp.iana.org') 206f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes ftp.login() 207f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes ftp.cwd('tz/releases') 208f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes for filename in ftp.nlst(): 209f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes if filename.startswith('tzdata20') and filename.endswith('.tar.gz'): 210f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes tzdata_filenames.append(filename) 211f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes tzdata_filenames.sort() 212f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes else: 213f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes http = httplib.HTTPConnection('www.iana.org') 214f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes http.request("GET", "/time-zones") 215f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes index_lines = http.getresponse().read().split('\n') 216f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes for line in index_lines: 217f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes m = re.compile('.*href="/time-zones/repository/releases/(tzdata20\d\d\c\.tar\.gz)".*').match(line) 218f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes if m: 219f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes tzdata_filenames.append(m.group(1)) 2205b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 2215b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes # If you're several releases behind, we'll walk you through the upgrades 2225b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes # one by one. 2235b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes current_version = GetCurrentTzDataVersion() 2245b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes current_filename = '%s.tar.gz' % current_version 2255b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes for filename in tzdata_filenames: 2265b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes if filename > current_filename: 2275b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes print 'Found new tzdata: %s' % filename 228246c6880207539d01e84a6f049cd639139a0691aNeil Fuller SwitchToNewTemporaryDirectory() 229f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes if use_ftp: 230246c6880207539d01e84a6f049cd639139a0691aNeil Fuller FtpRetrieveFileAndSignature(ftp, filename) 231f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes else: 232246c6880207539d01e84a6f049cd639139a0691aNeil Fuller HttpRetrieveFileAndSignature(http, filename) 233246c6880207539d01e84a6f049cd639139a0691aNeil Fuller 234246c6880207539d01e84a6f049cd639139a0691aNeil Fuller CheckSignature(filename) 235246c6880207539d01e84a6f049cd639139a0691aNeil Fuller BuildIcuToolsAndData(filename) 236246c6880207539d01e84a6f049cd639139a0691aNeil Fuller BuildBionicToolsAndData(filename) 237246c6880207539d01e84a6f049cd639139a0691aNeil Fuller print 'Look in %s and %s for new data files' % (bionic_dir, icu_dir) 2385b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes sys.exit(0) 2395b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 2405b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes print 'You already have the latest tzdata (%s)!' % current_version 2415b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes sys.exit(0) 2425b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 2435b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes 2445b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughesif __name__ == '__main__': 2455b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes main() 246