Neil Fuller | 0480f46 | 2019-04-09 19:23:35 +0100 | [diff] [blame] | 1 | #!/usr/bin/python -B |
| 2 | |
| 3 | # Copyright 2019 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 | """Dumps the contents of a tzdata file.""" |
| 18 | |
| 19 | from __future__ import print_function |
| 20 | |
| 21 | import argparse |
| 22 | import os |
| 23 | import subprocess |
| 24 | import sys |
| 25 | |
| 26 | sys.path.append('%s/external/icu/tools' % os.environ.get('ANDROID_BUILD_TOP')) |
| 27 | import i18nutil |
| 28 | |
Neil Fuller | 3bd3a57 | 2020-03-18 10:14:29 +0000 | [diff] [blame] | 29 | sys.path.append('%s/system/timezone' % os.environ.get('ANDROID_BUILD_TOP')) |
| 30 | import tzdatautil |
| 31 | |
Neil Fuller | 0480f46 | 2019-04-09 19:23:35 +0100 | [diff] [blame] | 32 | |
| 33 | # Calculate the paths that are referred to by multiple functions. |
| 34 | android_build_top = i18nutil.GetAndroidRootOrDie() |
| 35 | timezone_dir = os.path.realpath('%s/system/timezone' % android_build_top) |
| 36 | i18nutil.CheckDirExists(timezone_dir, 'system/timezone') |
| 37 | |
| 38 | android_host_out = i18nutil.GetAndroidHostOutOrDie() |
| 39 | |
| 40 | debug_tools_dir = os.path.realpath('%s/system/timezone/debug_tools/host' % android_build_top) |
| 41 | i18nutil.CheckDirExists(debug_tools_dir, 'system/timezone/debug_tools/host') |
| 42 | |
| 43 | |
| 44 | def BuildDebugTools(): |
Neil Fuller | beb929c | 2020-04-21 13:51:26 +0100 | [diff] [blame] | 45 | tzdatautil.InvokeSoong(android_build_top, ['zone_splitter', 'tz_file_dumper']) |
Neil Fuller | 0480f46 | 2019-04-09 19:23:35 +0100 | [diff] [blame] | 46 | |
| 47 | |
| 48 | def SplitTzData(tzdata_file, output_dir): |
Neil Fuller | beb929c | 2020-04-21 13:51:26 +0100 | [diff] [blame] | 49 | jar_file = '%s/framework/zone_splitter.jar' % android_host_out |
| 50 | subprocess.check_call(['java', '-jar', jar_file, tzdata_file, output_dir]) |
Neil Fuller | 0480f46 | 2019-04-09 19:23:35 +0100 | [diff] [blame] | 51 | |
| 52 | |
| 53 | def CreateCsvFiles(zones_dir, csvs_dir): |
Neil Fuller | beb929c | 2020-04-21 13:51:26 +0100 | [diff] [blame] | 54 | jar_file = '%s/framework/tz_file_dumper.jar' % android_host_out |
| 55 | subprocess.check_call(['java', '-jar', jar_file, zones_dir, csvs_dir]) |
Neil Fuller | 0480f46 | 2019-04-09 19:23:35 +0100 | [diff] [blame] | 56 | |
| 57 | |
| 58 | def CheckFileExists(file, filename): |
| 59 | if not os.path.isfile(file): |
| 60 | print("Couldn't find %s (%s)!" % (filename, file)) |
| 61 | sys.exit(1) |
| 62 | |
| 63 | |
| 64 | def main(): |
| 65 | parser = argparse.ArgumentParser() |
| 66 | parser.add_argument('-tzdata', required=True, |
| 67 | help='The tzdata file to process') |
| 68 | parser.add_argument('-output', required=True, |
| 69 | help='The output directory for the dump') |
| 70 | args = parser.parse_args() |
| 71 | |
| 72 | tzdata_file = args.tzdata |
| 73 | output_dir = args.output |
| 74 | |
| 75 | CheckFileExists(tzdata_file, '-tzdata') |
| 76 | if not os.path.exists(output_dir): |
| 77 | print('Creating dir: %s' % output_dir) |
| 78 | os.mkdir(output_dir) |
| 79 | i18nutil.CheckDirExists(output_dir, '-output') |
| 80 | |
| 81 | BuildDebugTools() |
| 82 | |
| 83 | SplitTzData(tzdata_file, output_dir) |
| 84 | |
| 85 | zones_dir = '%s/zones' % output_dir |
| 86 | csvs_dir = '%s/csvs' % output_dir |
| 87 | |
| 88 | i18nutil.CheckDirExists(zones_dir, 'zones output dir') |
| 89 | if not os.path.exists(csvs_dir): |
| 90 | os.mkdir(csvs_dir) |
| 91 | |
| 92 | CreateCsvFiles(zones_dir, csvs_dir) |
| 93 | |
| 94 | print('Look in %s for all extracted files' % output_dir) |
| 95 | print('Look in %s for dumped CSVs' % csvs_dir) |
| 96 | sys.exit(0) |
| 97 | |
| 98 | |
| 99 | if __name__ == '__main__': |
| 100 | main() |