Merge "Add python3 support for tools"
diff --git a/distro/tools/create-distro.py b/distro/tools/create-distro.py
index ad665f6..fa15004 100755
--- a/distro/tools/create-distro.py
+++ b/distro/tools/create-distro.py
@@ -16,6 +16,8 @@
"""Generates a time zone distro file"""
+from __future__ import print_function
+
import argparse
import os
import shutil
@@ -107,8 +109,8 @@
output_distro_dir=output_distro_dir,
output_version_file=output_version_file)
- print 'Distro file created in %s' % output_distro_dir
- print 'Version file created as %s' % output_version_file
+ print('Distro file created in %s' % output_distro_dir)
+ print('Version file created as %s' % output_version_file)
sys.exit(0)
diff --git a/download-iana-data.py b/download-iana-data.py
index a29e2c9..1d33f5a 100755
--- a/download-iana-data.py
+++ b/download-iana-data.py
@@ -16,6 +16,8 @@
"""Downloads the latest IANA timezone data."""
+from __future__ import print_function
+
import ftplib
import os
import shutil
@@ -35,22 +37,22 @@
def CheckSignature(data_filename, signature_filename):
"""Checks the signature of a file."""
- print 'Verifying signature...'
+ print('Verifying signature...')
try:
subprocess.check_call(['gpg', '--trusted-key=ED97E90E62AA7E34', '--verify',
signature_filename, data_filename])
except subprocess.CalledProcessError as err:
- print 'Unable to verify signature'
- print '\n\n******'
- print 'If this fails for you, you probably need to import Paul Eggert''s public key:'
- print ' gpg --receive-keys ED97E90E62AA7E34'
- print '******\n\n'
+ print('Unable to verify signature')
+ print('\n\n******')
+ print('If this fails for you, you probably need to import Paul Eggert''s public key:')
+ print(' gpg --receive-keys ED97E90E62AA7E34')
+ print('******\n\n')
raise
# Run with no arguments from any directory, with no special setup required.
# See http://www.iana.org/time-zones/ for more about the source of this data.
def main():
- print 'Looking for new IANA tzdata...'
+ print('Looking for new IANA tzdata...')
tar_prefix = 'tzdata20'
# Use the input tzdata version name if it exists
@@ -64,7 +66,7 @@
ftp.cwd('tz/releases')
for filename in ftp.nlst():
if "/" in filename:
- print "FTP server returned bogus file name"
+ print("FTP server returned bogus file name")
sys.exit(1)
if filename.startswith(tar_prefix) and filename.endswith('.tar.gz'):
@@ -72,7 +74,7 @@
iana_tar_filenames.sort(reverse=True)
if len(iana_tar_filenames) == 0:
- print 'No tzdata files found'
+ print('No tzdata files found')
sys.exit(1)
latest_iana_tar_filename = iana_tar_filenames[0]
@@ -82,17 +84,17 @@
if local_iana_tar_file:
local_iana_tar_filename = os.path.basename(local_iana_tar_file)
if latest_iana_tar_filename <= local_iana_tar_filename:
- print 'Available data %s is older or the same as current data %s' % (latest_iana_tar_filename, local_iana_tar_filename)
+ print('Available data %s is older or the same as current data %s' % (latest_iana_tar_filename, local_iana_tar_filename))
sys.exit(0)
- print 'Found new tzdata: %s' % latest_iana_tar_filename
+ print('Found new tzdata: %s' % latest_iana_tar_filename)
i18nutil.SwitchToNewTemporaryDirectory()
- print 'Downloading data (%s)...' % latest_iana_tar_filename
+ print('Downloading data (%s)...' % latest_iana_tar_filename)
FtpRetrieveFile(ftp, latest_iana_tar_filename)
signature_filename = '%s.asc' % latest_iana_tar_filename
- print 'Downloading signature (%s)...' % signature_filename
+ print('Downloading signature (%s)...' % signature_filename)
FtpRetrieveFile(ftp, signature_filename)
CheckSignature(latest_iana_tar_filename, signature_filename)
@@ -110,7 +112,7 @@
if os.path.exists(local_signature_file):
os.remove(local_signature_file)
- print 'Look in %s for new IANA data files' % new_local_iana_tar_file
+ print('Look in %s for new IANA data files' % new_local_iana_tar_file)
sys.exit(0)
diff --git a/tzdatautil.py b/tzdatautil.py
index 839a9f4..b7f81e3 100644
--- a/tzdatautil.py
+++ b/tzdatautil.py
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
+
import os
import sys
@@ -28,6 +30,6 @@
elif len(matching_files) == 1:
return '%s/%s' % (dir_name, matching_files[0])
else:
- print 'Multiple tz%s files found unexpectedly %s' % (file_type, matching_files)
+ print('Multiple tz%s files found unexpectedly %s' % (file_type, matching_files))
sys.exit(1)
diff --git a/update-tzdata.py b/update-tzdata.py
index 2f4ef68..0d7aad9 100755
--- a/update-tzdata.py
+++ b/update-tzdata.py
@@ -16,6 +16,8 @@
"""Generates the timezone data files used by Android."""
+from __future__ import print_function
+
import glob
import os
import re
@@ -58,7 +60,7 @@
zic_input_file = '%s/%s' % (extracted_iana_data_dir, zic_input_file_name)
if not os.path.exists(zic_input_file):
- print 'Could not find %s' % zic_input_file
+ print('Could not find %s' % zic_input_file)
sys.exit(1)
return zic_input_file
@@ -113,7 +115,7 @@
def ExtractTarFile(tar_file, dir):
- print 'Extracting %s...' % tar_file
+ print('Extracting %s...' % tar_file)
if not os.path.exists(dir):
os.mkdir(dir)
tar = tarfile.open(tar_file, 'r')
@@ -126,31 +128,31 @@
iana_zic_data_tar_file = tzdatautil.GetIanaTarFile(iana_tools_dir, 'data')
iana_zic_data_version = GetIanaVersion(iana_zic_data_tar_file)
- print 'Found IANA zic release %s/%s in %s/%s ...' \
- % (iana_zic_code_version, iana_zic_data_version, iana_zic_code_tar_file, iana_zic_data_tar_file)
+ print('Found IANA zic release %s/%s in %s/%s ...' \
+ % (iana_zic_code_version, iana_zic_data_version, iana_zic_code_tar_file, iana_zic_data_tar_file))
zic_build_dir = '%s/zic' % tmp_dir
ExtractTarFile(iana_zic_code_tar_file, zic_build_dir)
ExtractTarFile(iana_zic_data_tar_file, zic_build_dir)
# zic
- print 'Building zic...'
+ print('Building zic...')
# VERSION_DEPS= is to stop the build process looking for files that might not
# be present across different versions.
subprocess.check_call(['make', '-C', zic_build_dir, 'zic'])
zic_binary_file = '%s/zic' % zic_build_dir
if not os.path.exists(zic_binary_file):
- print 'Could not find %s' % zic_binary_file
+ print('Could not find %s' % zic_binary_file)
sys.exit(1)
return zic_binary_file
def BuildTzdata(zic_binary_file, extracted_iana_data_dir, iana_data_version):
- print 'Generating zic input file...'
+ print('Generating zic input file...')
zic_input_file = GenerateZicInputFile(extracted_iana_data_dir)
- print 'Calling zic...'
+ print('Calling zic...')
zic_output_dir = '%s/data' % tmp_dir
os.mkdir(zic_output_dir)
zic_cmd = [zic_binary_file, '-d', zic_output_dir, zic_input_file]
@@ -159,7 +161,7 @@
# ZoneCompactor
zone_compactor_setup_file = WriteSetupFile(zic_input_file)
- print 'Calling ZoneCompactor to update tzdata to %s...' % iana_data_version
+ print('Calling ZoneCompactor to update tzdata to %s...' % iana_data_version)
subprocess.check_call(['make', '-C', android_build_top, '-j30', 'zone_compactor'])
# Create args for ZoneCompactor
@@ -167,7 +169,7 @@
jar_file = '%s/framework/zone_compactor.jar' % android_host_out
header_string = 'tzdata%s' % iana_data_version
- print 'Executing ZoneCompactor...'
+ print('Executing ZoneCompactor...')
iana_output_data_dir = '%s/iana' % timezone_output_data_dir
subprocess.check_call(['java', '-jar', jar_file,
zone_compactor_setup_file, zic_output_dir, zone_tab_file,
@@ -178,7 +180,7 @@
countryzones_source_file = '%s/android/countryzones.txt' % timezone_input_data_dir
tzlookup_dest_file = '%s/android/tzlookup.xml' % timezone_output_data_dir
- print 'Calling TzLookupGenerator to create tzlookup.xml...'
+ print('Calling TzLookupGenerator to create tzlookup.xml...')
subprocess.check_call(['make', '-C', android_build_top, '-j30', 'tzlookup_generator'])
jar_file = '%s/framework/tzlookup_generator.jar' % android_host_out
@@ -197,7 +199,7 @@
distro_file_pattern = '%s/*.zip' % output_distro_dir
existing_files = glob.glob(distro_file_pattern)
- print 'Removing %s' % existing_files
+ print('Removing %s' % existing_files)
for existing_file in existing_files:
os.remove(existing_file)
@@ -218,17 +220,17 @@
# Run with no arguments from any directory, with no special setup required.
# See http://www.iana.org/time-zones/ for more about the source of this data.
def main():
- print 'Source data file structure: %s' % timezone_input_data_dir
- print 'Source tools file structure: %s' % timezone_input_tools_dir
- print 'Output data file structure: %s' % timezone_output_data_dir
+ print('Source data file structure: %s' % timezone_input_data_dir)
+ print('Source tools file structure: %s' % timezone_input_tools_dir)
+ print('Output data file structure: %s' % timezone_output_data_dir)
iana_input_data_dir = '%s/iana' % timezone_input_data_dir
iana_data_tar_file = tzdatautil.GetIanaTarFile(iana_input_data_dir, 'data')
iana_data_version = GetIanaVersion(iana_data_tar_file)
- print 'IANA time zone data release %s in %s ...' % (iana_data_version, iana_data_tar_file)
+ print('IANA time zone data release %s in %s ...' % (iana_data_version, iana_data_tar_file))
icu_dir = icuutil.icuDir()
- print 'Found icu in %s ...' % icu_dir
+ print('Found icu in %s ...' % icu_dir)
BuildIcuData(iana_data_tar_file)
@@ -248,7 +250,7 @@
# Update test versions of distro files too.
UpdateTestFiles()
- print 'Look in %s and %s for new files' % (timezone_output_data_dir, icu_dir)
+ print('Look in %s and %s for new files' % (timezone_output_data_dir, icu_dir))
sys.exit(0)