• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python -B
2
3# Copyright 2017 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Generates a time zone distro file"""
18
19from __future__ import print_function
20
21import argparse
22import os
23import shutil
24import subprocess
25import sys
26
27sys.path.append('%s/external/icu/tools' % os.environ.get('ANDROID_BUILD_TOP'))
28import i18nutil
29
30sys.path.append('%s/system/timezone' % os.environ.get('ANDROID_BUILD_TOP'))
31import tzdatautil
32
33android_build_top = i18nutil.GetAndroidRootOrDie()
34android_host_out_dir = i18nutil.GetAndroidHostOutOrDie()
35timezone_dir = os.path.realpath('%s/system/timezone' % android_build_top)
36i18nutil.CheckDirExists(timezone_dir, 'system/timezone')
37
38def RunCreateTimeZoneDistro(properties_file):
39  # Build the libraries needed.
40  tzdatautil.InvokeSoong(android_build_top, ['create_time_zone_distro'])
41
42  # Run the CreateTimeZoneDistro tool
43  command = '%s/bin/create_time_zone_distro' % android_host_out_dir
44  subprocess.check_call([command, properties_file])
45
46
47def CreateTimeZoneDistro(
48    iana_version, revision, tzdata_file, icu_file, tzlookup_file, telephonylookup_file,
49    output_distro_dir, output_version_file):
50  original_cwd = os.getcwd()
51
52  i18nutil.SwitchToNewTemporaryDirectory()
53  working_dir = os.getcwd()
54
55  # Generate the properties file.
56  properties_file = '%s/distro.properties' % working_dir
57  with open(properties_file, "w") as properties:
58    properties.write('rules.version=%s\n' % iana_version)
59    properties.write('revision=%s\n' % revision)
60    properties.write('tzdata.file=%s\n' % tzdata_file)
61    properties.write('icu.file=%s\n' % icu_file)
62    properties.write('tzlookup.file=%s\n' % tzlookup_file)
63    properties.write('telephonylookup.file=%s\n' % telephonylookup_file)
64    properties.write('output.distro.dir=%s\n' % output_distro_dir)
65    properties.write('output.version.file=%s\n' % output_version_file)
66
67  RunCreateTimeZoneDistro(properties_file)
68
69  os.chdir(original_cwd)
70
71
72def main():
73  parser = argparse.ArgumentParser()
74  parser.add_argument('-iana_version', required=True,
75      help='The IANA time zone rules release version, e.g. 2017b')
76  parser.add_argument('-revision', type=int, default=1,
77      help='The distro revision for the IANA version, default = 1')
78  parser.add_argument('-tzdata', required=True, help='The location of the tzdata file to include')
79  parser.add_argument('-icu', required=True,
80      help='The location of the ICU overlay .dat file to include')
81  parser.add_argument('-tzlookup', required=True,
82      help='The location of the tzlookup.xml file to include')
83  parser.add_argument('-telephonylookup', required=True,
84      help='The location of the telephonylookup.xml file to include')
85  parser.add_argument('-output_distro_dir', required=True,
86      help='The output directory for the distro.zip')
87  parser.add_argument('-output_version_file', required=True,
88      help='The output path for the version file')
89  args = parser.parse_args()
90
91  iana_version = args.iana_version
92  revision = args.revision
93  tzdata_file = os.path.abspath(args.tzdata)
94  icu_file = os.path.abspath(args.icu)
95  tzlookup_file = os.path.abspath(args.tzlookup)
96  telephonylookup_file = os.path.abspath(args.telephonylookup)
97  output_distro_dir = os.path.abspath(args.output_distro_dir)
98  output_version_file = os.path.abspath(args.output_version_file)
99
100  CreateTimeZoneDistro(
101      iana_version=iana_version,
102      revision=revision,
103      tzdata_file=tzdata_file,
104      icu_file=icu_file,
105      tzlookup_file=tzlookup_file,
106      telephonylookup_file=telephonylookup_file,
107      output_distro_dir=output_distro_dir,
108      output_version_file=output_version_file)
109
110  print('Distro file created in %s' % output_distro_dir)
111  print('Version file created as %s' % output_version_file)
112  sys.exit(0)
113
114
115if __name__ == '__main__':
116  main()
117