| #!/usr/bin/python3 -B |
| |
| # Copyright 2017 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| """Generates a time zone distro file""" |
| |
| from __future__ import print_function |
| |
| import argparse |
| import os |
| import shutil |
| import subprocess |
| import sys |
| |
| sys.path.append('%s/external/icu/tools' % os.environ.get('ANDROID_BUILD_TOP')) |
| import i18nutil |
| |
| sys.path.append('%s/system/timezone' % os.environ.get('ANDROID_BUILD_TOP')) |
| import tzdatautil |
| |
| android_build_top = i18nutil.GetAndroidRootOrDie() |
| android_host_out_dir = i18nutil.GetAndroidHostOutOrDie() |
| timezone_dir = os.path.realpath('%s/system/timezone' % android_build_top) |
| i18nutil.CheckDirExists(timezone_dir, 'system/timezone') |
| |
| def RunCreateTimeZoneDistro(properties_file): |
| # Build the libraries needed. |
| tzdatautil.InvokeSoong(android_build_top, ['create_time_zone_distro']) |
| |
| # Run the CreateTimeZoneDistro tool |
| command = '%s/bin/create_time_zone_distro' % android_host_out_dir |
| subprocess.check_call([command, properties_file]) |
| |
| |
| def CreateTimeZoneDistro( |
| iana_version, revision, tzdata_file, icu_file, tzlookup_file, telephonylookup_file, |
| output_distro_dir, output_version_file): |
| original_cwd = os.getcwd() |
| |
| i18nutil.SwitchToNewTemporaryDirectory() |
| working_dir = os.getcwd() |
| |
| # Generate the properties file. |
| properties_file = '%s/distro.properties' % working_dir |
| with open(properties_file, "w") as properties: |
| properties.write('rules.version=%s\n' % iana_version) |
| properties.write('revision=%s\n' % revision) |
| properties.write('tzdata.file=%s\n' % tzdata_file) |
| properties.write('icu.file=%s\n' % icu_file) |
| properties.write('tzlookup.file=%s\n' % tzlookup_file) |
| properties.write('telephonylookup.file=%s\n' % telephonylookup_file) |
| properties.write('output.distro.dir=%s\n' % output_distro_dir) |
| properties.write('output.version.file=%s\n' % output_version_file) |
| |
| RunCreateTimeZoneDistro(properties_file) |
| |
| os.chdir(original_cwd) |
| |
| |
| def main(): |
| parser = argparse.ArgumentParser() |
| parser.add_argument('-iana_version', required=True, |
| help='The IANA time zone rules release version, e.g. 2017b') |
| parser.add_argument('-revision', type=int, default=1, |
| help='The distro revision for the IANA version, default = 1') |
| parser.add_argument('-tzdata', required=True, help='The location of the tzdata file to include') |
| parser.add_argument('-icu_dir', required=True, |
| help='Directory with the ICU overlay .dat and license files') |
| parser.add_argument('-tzlookup', required=True, |
| help='The location of the tzlookup.xml file to include') |
| parser.add_argument('-telephonylookup', required=True, |
| help='The location of the telephonylookup.xml file to include') |
| parser.add_argument('-output_distro_dir', required=True, |
| help='The output directory for the distro.zip') |
| parser.add_argument('-output_version_file', required=True, |
| help='The output path for the version file') |
| args = parser.parse_args() |
| |
| iana_version = args.iana_version |
| revision = args.revision |
| icu_dir = args.icu_dir |
| tzdata_file = os.path.abspath(args.tzdata) |
| icu_file = os.path.abspath('%s/icu_tzdata.dat' % icu_dir) |
| icu_license = os.path.abspath('%s/LICENSE' % icu_dir) |
| tzlookup_file = os.path.abspath(args.tzlookup) |
| telephonylookup_file = os.path.abspath(args.telephonylookup) |
| output_distro_dir = os.path.abspath(args.output_distro_dir) |
| output_version_file = os.path.abspath(args.output_version_file) |
| |
| if not os.path.isfile(icu_license): |
| raise Exception("ICU license file was not found in %s" % icu_dir) |
| |
| print("Copying %s to %s" % (icu_license, output_distro_dir)) |
| shutil.copy(icu_license, output_distro_dir) |
| |
| CreateTimeZoneDistro( |
| iana_version=iana_version, |
| revision=revision, |
| tzdata_file=tzdata_file, |
| icu_file=icu_file, |
| tzlookup_file=tzlookup_file, |
| telephonylookup_file=telephonylookup_file, |
| 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) |
| sys.exit(0) |
| |
| |
| if __name__ == '__main__': |
| main() |