* commit '3248b9d33c14bef51a07146ce93ec810c07c01e3': Change update-tzdata.py to update ICU data as well
This commit is contained in:
commit
fa5903edf3
@ -1,36 +1,40 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
"""Updates the tzdata file."""
|
"""Updates the timezone data held in bionic and ICU."""
|
||||||
|
|
||||||
import ftplib
|
import ftplib
|
||||||
|
import glob
|
||||||
import httplib
|
import httplib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
# Find the bionic directory, searching upward from this script.
|
|
||||||
bionic_libc_tools_zoneinfo_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
|
|
||||||
bionic_libc_tools_dir = os.path.dirname(bionic_libc_tools_zoneinfo_dir)
|
|
||||||
bionic_libc_dir = os.path.dirname(bionic_libc_tools_dir)
|
|
||||||
bionic_dir = os.path.dirname(bionic_libc_dir)
|
|
||||||
bionic_libc_zoneinfo_dir = '%s/libc/zoneinfo' % bionic_dir
|
|
||||||
|
|
||||||
if not os.path.isdir(bionic_libc_tools_zoneinfo_dir):
|
|
||||||
print "Couldn't find bionic/libc/tools/zoneinfo!"
|
|
||||||
sys.exit(1)
|
|
||||||
if not os.path.isdir(bionic_libc_zoneinfo_dir):
|
|
||||||
print "Couldn't find bionic/libc/zoneinfo!"
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print 'Found bionic in %s...' % bionic_dir
|
|
||||||
|
|
||||||
|
|
||||||
regions = ['africa', 'antarctica', 'asia', 'australasia', 'backward',
|
regions = ['africa', 'antarctica', 'asia', 'australasia', 'backward',
|
||||||
'etcetera', 'europe', 'northamerica', 'southamerica']
|
'etcetera', 'europe', 'northamerica', 'southamerica']
|
||||||
|
|
||||||
|
def CheckDirExists(dir, dirname):
|
||||||
|
if not os.path.isdir(dir):
|
||||||
|
print "Couldn't find %s (%s)!" % (dirname, dir)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
bionic_libc_tools_zoneinfo_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
|
||||||
|
|
||||||
|
# Find the bionic directory, searching upward from this script.
|
||||||
|
bionic_dir = os.path.realpath('%s/../../..' % bionic_libc_tools_zoneinfo_dir)
|
||||||
|
bionic_libc_zoneinfo_dir = '%s/libc/zoneinfo' % bionic_dir
|
||||||
|
CheckDirExists(bionic_libc_zoneinfo_dir, 'bionic/libc/zoneinfo')
|
||||||
|
CheckDirExists(bionic_libc_tools_zoneinfo_dir, 'bionic/libc/tools/zoneinfo')
|
||||||
|
print 'Found bionic in %s ...' % bionic_dir
|
||||||
|
|
||||||
|
# Find the icu4c directory.
|
||||||
|
icu_dir = os.path.realpath('%s/../external/icu4c' % bionic_dir)
|
||||||
|
CheckDirExists(icu_dir, 'external/icu4c')
|
||||||
|
print 'Found icu in %s ...' % icu_dir
|
||||||
|
|
||||||
|
|
||||||
def GetCurrentTzDataVersion():
|
def GetCurrentTzDataVersion():
|
||||||
return open('%s/tzdata' % bionic_libc_zoneinfo_dir).read().split('\x00', 1)[0]
|
return open('%s/tzdata' % bionic_libc_zoneinfo_dir).read().split('\x00', 1)[0]
|
||||||
@ -65,50 +69,76 @@ def SwitchToNewTemporaryDirectory():
|
|||||||
print 'Created temporary directory "%s"...' % tmp_dir
|
print 'Created temporary directory "%s"...' % tmp_dir
|
||||||
|
|
||||||
|
|
||||||
def FtpRetrieve(ftp, filename):
|
def FtpRetrieveFile(ftp, filename):
|
||||||
ftp.retrbinary('RETR %s' % filename, open(filename, 'wb').write)
|
ftp.retrbinary('RETR %s' % filename, open(filename, 'wb').write)
|
||||||
|
|
||||||
|
|
||||||
def FtpUpgrade(ftp, data_filename):
|
def FtpRetrieveFileAndSignature(ftp, data_filename):
|
||||||
"""Downloads and repackages the given data from the given FTP server."""
|
"""Downloads and repackages the given data from the given FTP server."""
|
||||||
SwitchToNewTemporaryDirectory()
|
|
||||||
|
|
||||||
print 'Downloading data...'
|
print 'Downloading data...'
|
||||||
FtpRetrieve(ftp, data_filename)
|
FtpRetrieveFile(ftp, data_filename)
|
||||||
|
|
||||||
print 'Downloading signature...'
|
print 'Downloading signature...'
|
||||||
signature_filename = '%s.asc' % data_filename
|
signature_filename = '%s.asc' % data_filename
|
||||||
FtpRetrieve(ftp, signature_filename)
|
FtpRetrieveFile(ftp, signature_filename)
|
||||||
|
|
||||||
ExtractAndCompile(data_filename)
|
|
||||||
|
|
||||||
|
|
||||||
def HttpRetrieve(http, path, output_filename):
|
def HttpRetrieveFile(http, path, output_filename):
|
||||||
http.request("GET", path)
|
http.request("GET", path)
|
||||||
f = open(output_filename, 'wb')
|
f = open(output_filename, 'wb')
|
||||||
f.write(http.getresponse().read())
|
f.write(http.getresponse().read())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def HttpUpgrade(http, data_filename):
|
def HttpRetrieveFileAndSignature(http, data_filename):
|
||||||
"""Downloads and repackages the given data from the given HTTP server."""
|
"""Downloads and repackages the given data from the given HTTP server."""
|
||||||
SwitchToNewTemporaryDirectory()
|
|
||||||
|
|
||||||
path = "/time-zones/repository/releases/%s" % data_filename
|
path = "/time-zones/repository/releases/%s" % data_filename
|
||||||
|
|
||||||
print 'Downloading data...'
|
print 'Downloading data...'
|
||||||
HttpRetrieve(http, path, data_filename)
|
HttpRetrieveFile(http, path, data_filename)
|
||||||
|
|
||||||
print 'Downloading signature...'
|
print 'Downloading signature...'
|
||||||
signature_filename = '%s.asc' % data_filename
|
signature_filename = '%s.asc' % data_filename
|
||||||
HttpRetrieve(http, "%s.asc" % path, signature_filename)
|
HttpRetrievefile(http, "%s.asc" % path, signature_filename)
|
||||||
|
|
||||||
ExtractAndCompile(data_filename)
|
|
||||||
|
|
||||||
|
|
||||||
def ExtractAndCompile(data_filename):
|
def BuildIcuToolsAndData(data_filename):
|
||||||
new_version = re.search('(tzdata.+)\\.tar\\.gz', data_filename).group(1)
|
# Keep track of the original cwd so we can go back to it at the end.
|
||||||
|
original_working_dir = os.getcwd()
|
||||||
|
|
||||||
|
# Create a directory to run 'make' from.
|
||||||
|
icu_working_dir = '%s/icu' % original_working_dir
|
||||||
|
os.mkdir(icu_working_dir)
|
||||||
|
os.chdir(icu_working_dir)
|
||||||
|
|
||||||
|
# Build the ICU tools.
|
||||||
|
print 'Configuring ICU tools...'
|
||||||
|
subprocess.check_call(['%s/runConfigureICU' % icu_dir, 'Linux'])
|
||||||
|
print 'Making ICU tools...'
|
||||||
|
subprocess.check_call(['make', '-j6'])
|
||||||
|
|
||||||
|
# Run the ICU tools.
|
||||||
|
os.chdir('tools/tzcode')
|
||||||
|
shutil.copyfile('%s/%s' % (original_working_dir, data_filename), data_filename)
|
||||||
|
print 'Making ICU data...'
|
||||||
|
subprocess.check_call(['make'])
|
||||||
|
|
||||||
|
# Copy the output files to their ultimate destination.
|
||||||
|
icu_txt_data_dir = '%s/data/misc' % icu_dir
|
||||||
|
print 'Copying zoneinfo64.txt to %s ...' % icu_txt_data_dir
|
||||||
|
shutil.copy('zoneinfo64.txt', icu_txt_data_dir)
|
||||||
|
|
||||||
|
os.chdir(icu_working_dir)
|
||||||
|
icu_dat_data_dir = '%s/stubdata' % icu_dir
|
||||||
|
for file in glob.glob('data/out/tmp/*.dat'):
|
||||||
|
print 'Copying %s to %s ...' % (file, icu_dat_data_dir)
|
||||||
|
shutil.copy(file, icu_dat_data_dir)
|
||||||
|
|
||||||
|
# Switch back to the original working cwd.
|
||||||
|
os.chdir(original_working_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def CheckSignature(data_filename):
|
||||||
signature_filename = '%s.asc' % data_filename
|
signature_filename = '%s.asc' % data_filename
|
||||||
print 'Verifying signature...'
|
print 'Verifying signature...'
|
||||||
# If this fails for you, you probably need to import Paul Eggert's public key:
|
# If this fails for you, you probably need to import Paul Eggert's public key:
|
||||||
@ -116,6 +146,10 @@ def ExtractAndCompile(data_filename):
|
|||||||
subprocess.check_call(['gpg', '--trusted-key=ED97E90E62AA7E34', '--verify',
|
subprocess.check_call(['gpg', '--trusted-key=ED97E90E62AA7E34', '--verify',
|
||||||
signature_filename, data_filename])
|
signature_filename, data_filename])
|
||||||
|
|
||||||
|
|
||||||
|
def BuildBionicToolsAndData(data_filename):
|
||||||
|
new_version = re.search('(tzdata.+)\\.tar\\.gz', data_filename).group(1)
|
||||||
|
|
||||||
print 'Extracting...'
|
print 'Extracting...'
|
||||||
os.mkdir('extracted')
|
os.mkdir('extracted')
|
||||||
tar = tarfile.open(data_filename, 'r')
|
tar = tarfile.open(data_filename, 'r')
|
||||||
@ -175,10 +209,16 @@ def main():
|
|||||||
for filename in tzdata_filenames:
|
for filename in tzdata_filenames:
|
||||||
if filename > current_filename:
|
if filename > current_filename:
|
||||||
print 'Found new tzdata: %s' % filename
|
print 'Found new tzdata: %s' % filename
|
||||||
|
SwitchToNewTemporaryDirectory()
|
||||||
if use_ftp:
|
if use_ftp:
|
||||||
FtpUpgrade(ftp, filename)
|
FtpRetrieveFileAndSignature(ftp, filename)
|
||||||
else:
|
else:
|
||||||
HttpUpgrade(http, filename)
|
HttpRetrieveFileAndSignature(http, filename)
|
||||||
|
|
||||||
|
CheckSignature(filename)
|
||||||
|
BuildIcuToolsAndData(filename)
|
||||||
|
BuildBionicToolsAndData(filename)
|
||||||
|
print 'Look in %s and %s for new data files' % (bionic_dir, icu_dir)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
print 'You already have the latest tzdata (%s)!' % current_version
|
print 'You already have the latest tzdata (%s)!' % current_version
|
||||||
|
Loading…
Reference in New Issue
Block a user