update-tzdata.py revision 90cb5ffb85a9bc2e725824b3ca8db932d02c45db
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
16246c6880207539d01e84a6f049cd639139a0691aNeil Fullerregions = ['africa', 'antarctica', 'asia', 'australasia', 'backward',
17246c6880207539d01e84a6f049cd639139a0691aNeil Fuller           'etcetera', 'europe', 'northamerica', 'southamerica']
185b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
19246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef CheckDirExists(dir, dirname):
20246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  if not os.path.isdir(dir):
21246c6880207539d01e84a6f049cd639139a0691aNeil Fuller    print "Couldn't find %s (%s)!" % (dirname, dir)
22246c6880207539d01e84a6f049cd639139a0691aNeil Fuller    sys.exit(1)
235b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
24246c6880207539d01e84a6f049cd639139a0691aNeil Fullerbionic_libc_tools_zoneinfo_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
255d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
26246c6880207539d01e84a6f049cd639139a0691aNeil Fuller# Find the bionic directory, searching upward from this script.
27246c6880207539d01e84a6f049cd639139a0691aNeil Fullerbionic_dir = os.path.realpath('%s/../../..' % bionic_libc_tools_zoneinfo_dir)
28246c6880207539d01e84a6f049cd639139a0691aNeil Fullerbionic_libc_zoneinfo_dir = '%s/libc/zoneinfo' % bionic_dir
29246c6880207539d01e84a6f049cd639139a0691aNeil FullerCheckDirExists(bionic_libc_zoneinfo_dir, 'bionic/libc/zoneinfo')
30246c6880207539d01e84a6f049cd639139a0691aNeil FullerCheckDirExists(bionic_libc_tools_zoneinfo_dir, 'bionic/libc/tools/zoneinfo')
31246c6880207539d01e84a6f049cd639139a0691aNeil Fullerprint 'Found bionic in %s ...' % bionic_dir
325d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
33246c6880207539d01e84a6f049cd639139a0691aNeil Fuller# Find the icu4c directory.
3430ab93949626872b3e6ea35398c831017c4c378fElliott Hughesicu_dir = os.path.realpath('%s/../external/icu/icu4c/source' % bionic_dir)
3530ab93949626872b3e6ea35398c831017c4c378fElliott HughesCheckDirExists(icu_dir, 'external/icu/icu4c/source')
36246c6880207539d01e84a6f049cd639139a0691aNeil Fullerprint 'Found icu in %s ...' % icu_dir
375b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
385d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
395b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughesdef GetCurrentTzDataVersion():
40e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes  return open('%s/tzdata' % bionic_libc_zoneinfo_dir).read().split('\x00', 1)[0]
415d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
425d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
435b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughesdef WriteSetupFile():
44e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes  """Writes the list of zones that ZoneCompactor should process."""
455b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  links = []
465b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  zones = []
475b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  for region in regions:
485b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes    for line in open('extracted/%s' % region):
495b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes      fields = line.split()
50e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes      if fields:
51e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes        if fields[0] == 'Link':
52e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes          links.append('%s %s %s\n' % (fields[0], fields[1], fields[2]))
53e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes          zones.append(fields[2])
54e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes        elif fields[0] == 'Zone':
55e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes          zones.append(fields[1])
565b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  zones.sort()
575d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
585b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  setup = open('setup', 'w')
595b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  for link in links:
605b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes    setup.write(link)
615b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  for zone in zones:
625b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes    setup.write('%s\n' % zone)
635b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  setup.close()
645d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
655d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
66f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughesdef SwitchToNewTemporaryDirectory():
67f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  tmp_dir = tempfile.mkdtemp('-tzdata')
68f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  os.chdir(tmp_dir)
69f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  print 'Created temporary directory "%s"...' % tmp_dir
70e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes
71e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes
72246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef FtpRetrieveFile(ftp, filename):
73f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  ftp.retrbinary('RETR %s' % filename, open(filename, 'wb').write)
74e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes
755d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
76246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef FtpRetrieveFileAndSignature(ftp, data_filename):
77f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  """Downloads and repackages the given data from the given FTP server."""
785d2ef8724d8978465b9795198099305d0f0b12d0Elliott Hughes  print 'Downloading data...'
79246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  FtpRetrieveFile(ftp, data_filename)
805d2ef8724d8978465b9795198099305d0f0b12d0Elliott Hughes
815d2ef8724d8978465b9795198099305d0f0b12d0Elliott Hughes  print 'Downloading signature...'
825d2ef8724d8978465b9795198099305d0f0b12d0Elliott Hughes  signature_filename = '%s.asc' % data_filename
83246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  FtpRetrieveFile(ftp, signature_filename)
84f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
85f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
86246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef HttpRetrieveFile(http, path, output_filename):
87676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  http.request("GET", path)
88676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  f = open(output_filename, 'wb')
89676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  f.write(http.getresponse().read())
90676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  f.close()
91676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes
92676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes
93246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef HttpRetrieveFileAndSignature(http, data_filename):
94f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  """Downloads and repackages the given data from the given HTTP server."""
95676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  path = "/time-zones/repository/releases/%s" % data_filename
96676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes
97f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  print 'Downloading data...'
98246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  HttpRetrieveFile(http, path, data_filename)
99676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes
100676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  print 'Downloading signature...'
101676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  signature_filename = '%s.asc' % data_filename
102246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  HttpRetrievefile(http, "%s.asc" % path, signature_filename)
103f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
104f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
105246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef BuildIcuToolsAndData(data_filename):
106246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  # Keep track of the original cwd so we can go back to it at the end.
107246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  original_working_dir = os.getcwd()
108f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
109246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  # Create a directory to run 'make' from.
110246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  icu_working_dir = '%s/icu' % original_working_dir
111246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  os.mkdir(icu_working_dir)
112246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  os.chdir(icu_working_dir)
113246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
114246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  # Build the ICU tools.
115246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  print 'Configuring ICU tools...'
116246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  subprocess.check_call(['%s/runConfigureICU' % icu_dir, 'Linux'])
117246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  print 'Making ICU tools...'
11890cb5ffb85a9bc2e725824b3ca8db932d02c45dbElliott Hughes  subprocess.check_call(['make', '-j32'])
119246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
120246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  # Run the ICU tools.
121246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  os.chdir('tools/tzcode')
122246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  shutil.copyfile('%s/%s' % (original_working_dir, data_filename), data_filename)
123246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  print 'Making ICU data...'
124246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  subprocess.check_call(['make'])
125246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
126246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  # Copy the output files to their ultimate destination.
127246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  icu_txt_data_dir = '%s/data/misc' % icu_dir
128246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  print 'Copying zoneinfo64.txt to %s ...' % icu_txt_data_dir
129246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  shutil.copy('zoneinfo64.txt', icu_txt_data_dir)
130246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
131246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  os.chdir(icu_working_dir)
132246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  icu_dat_data_dir = '%s/stubdata' % icu_dir
13343f37159532c1ef7218266957cc616f055b4dbacNeil Fuller  datfiles = glob.glob('data/out/tmp/icudt??l.dat')
13443f37159532c1ef7218266957cc616f055b4dbacNeil Fuller  if len(datfiles) != 1:
13543f37159532c1ef7218266957cc616f055b4dbacNeil Fuller    print 'ERROR: Unexpectedly found %d .dat files (%s). Halting.' % (len(datfiles), datfiles)
13643f37159532c1ef7218266957cc616f055b4dbacNeil Fuller    sys.exit(1)
13743f37159532c1ef7218266957cc616f055b4dbacNeil Fuller
13843f37159532c1ef7218266957cc616f055b4dbacNeil Fuller  datfile = datfiles[0]
13943f37159532c1ef7218266957cc616f055b4dbacNeil Fuller  print 'Copying %s to %s ...' % (datfile, icu_dat_data_dir)
14043f37159532c1ef7218266957cc616f055b4dbacNeil Fuller  shutil.copy(datfile, icu_dat_data_dir)
141f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
142246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  # Switch back to the original working cwd.
143246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  os.chdir(original_working_dir)
144246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
145246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
146246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef CheckSignature(data_filename):
147676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  signature_filename = '%s.asc' % data_filename
148676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  print 'Verifying signature...'
149676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  # If this fails for you, you probably need to import Paul Eggert's public key:
150676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  # gpg --recv-keys ED97E90E62AA7E34
151676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes  subprocess.check_call(['gpg', '--trusted-key=ED97E90E62AA7E34', '--verify',
152676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes                         signature_filename, data_filename])
153676e66db251cb54b51be5f6f8190a47a8b131738Elliott Hughes
154246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
155246c6880207539d01e84a6f049cd639139a0691aNeil Fullerdef BuildBionicToolsAndData(data_filename):
156246c6880207539d01e84a6f049cd639139a0691aNeil Fuller  new_version = re.search('(tzdata.+)\\.tar\\.gz', data_filename).group(1)
157246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
1585d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes  print 'Extracting...'
1595d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes  os.mkdir('extracted')
160e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes  tar = tarfile.open(data_filename, 'r')
1615d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes  tar.extractall('extracted')
1625d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
1635d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes  print 'Calling zic(1)...'
1645d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes  os.mkdir('data')
1655d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes  for region in regions:
1665d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes    if region != 'backward':
1675d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes      subprocess.check_call(['zic', '-d', 'data', 'extracted/%s' % region])
1685d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
1695b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  WriteSetupFile()
1705d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes
1715b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  print 'Calling ZoneCompactor to update bionic to %s...' % new_version
1725d967e43d03e9c916548b9c290b0c4138df2f1f8Elliott Hughes  subprocess.check_call(['javac', '-d', '.',
17390cb5ffb85a9bc2e725824b3ca8db932d02c45dbElliott Hughes                         '%s/ZoneCompactor.java' % bionic_libc_tools_zoneinfo_dir])
1745b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  subprocess.check_call(['java', 'ZoneCompactor',
1752393535f0d7df55dae3b4fbf5dbcfa7f87192762Elliott Hughes                         'setup', 'data', 'extracted/zone.tab',
1762393535f0d7df55dae3b4fbf5dbcfa7f87192762Elliott Hughes                         bionic_libc_zoneinfo_dir, new_version])
1775b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
1785b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
1795b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes# Run with no arguments from any directory, with no special setup required.
180e3063f4e5520caa84f48896cf9127d97fd2796baElliott Hughes# See http://www.iana.org/time-zones/ for more about the source of this data.
1815b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughesdef main():
1825b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  print 'Looking for new tzdata...'
183f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
1845b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  tzdata_filenames = []
185f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
186f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  # The FTP server lets you download intermediate releases, and also lets you
18721da42ea91d45c43372d027f72467ecd66a33b29Elliott Hughes  # download the signatures for verification, so it's your best choice.
188f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  use_ftp = True
189f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes
190f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  if use_ftp:
191f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    ftp = ftplib.FTP('ftp.iana.org')
192f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    ftp.login()
193f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    ftp.cwd('tz/releases')
194f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    for filename in ftp.nlst():
195f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes      if filename.startswith('tzdata20') and filename.endswith('.tar.gz'):
196f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes        tzdata_filenames.append(filename)
197f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    tzdata_filenames.sort()
198f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes  else:
199f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    http = httplib.HTTPConnection('www.iana.org')
200f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    http.request("GET", "/time-zones")
201f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    index_lines = http.getresponse().read().split('\n')
202f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes    for line in index_lines:
203f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes      m = re.compile('.*href="/time-zones/repository/releases/(tzdata20\d\d\c\.tar\.gz)".*').match(line)
204f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes      if m:
205f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes        tzdata_filenames.append(m.group(1))
2065b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
2075b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  # If you're several releases behind, we'll walk you through the upgrades
2085b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  # one by one.
2095b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  current_version = GetCurrentTzDataVersion()
2105b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  current_filename = '%s.tar.gz' % current_version
2115b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  for filename in tzdata_filenames:
2125b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes    if filename > current_filename:
2135b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes      print 'Found new tzdata: %s' % filename
214246c6880207539d01e84a6f049cd639139a0691aNeil Fuller      SwitchToNewTemporaryDirectory()
215f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes      if use_ftp:
216246c6880207539d01e84a6f049cd639139a0691aNeil Fuller        FtpRetrieveFileAndSignature(ftp, filename)
217f8dff7d44933f3eaf736f36e39f7b95fe151c3bcElliott Hughes      else:
218246c6880207539d01e84a6f049cd639139a0691aNeil Fuller        HttpRetrieveFileAndSignature(http, filename)
219246c6880207539d01e84a6f049cd639139a0691aNeil Fuller
220246c6880207539d01e84a6f049cd639139a0691aNeil Fuller      CheckSignature(filename)
221246c6880207539d01e84a6f049cd639139a0691aNeil Fuller      BuildIcuToolsAndData(filename)
222246c6880207539d01e84a6f049cd639139a0691aNeil Fuller      BuildBionicToolsAndData(filename)
223246c6880207539d01e84a6f049cd639139a0691aNeil Fuller      print 'Look in %s and %s for new data files' % (bionic_dir, icu_dir)
2245b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes      sys.exit(0)
2255b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
2265b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  print 'You already have the latest tzdata (%s)!' % current_version
2275b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  sys.exit(0)
2285b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
2295b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes
2305b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughesif __name__ == '__main__':
2315b1497acdbcbfd21f57d11511294b541b6fb1130Elliott Hughes  main()
232