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 | |
| 29 | |
| 30 | # Calculate the paths that are referred to by multiple functions. |
| 31 | android_build_top = i18nutil.GetAndroidRootOrDie() |
| 32 | timezone_dir = os.path.realpath('%s/system/timezone' % android_build_top) |
| 33 | i18nutil.CheckDirExists(timezone_dir, 'system/timezone') |
| 34 | |
| 35 | android_host_out = i18nutil.GetAndroidHostOutOrDie() |
| 36 | |
| 37 | debug_tools_dir = os.path.realpath('%s/system/timezone/debug_tools/host' % android_build_top) |
| 38 | i18nutil.CheckDirExists(debug_tools_dir, 'system/timezone/debug_tools/host') |
| 39 | |
| 40 | |
| 41 | def BuildDebugTools(): |
| 42 | subprocess.check_call(['make', '-C', android_build_top, '-j30', 'timezone_host_debug_tools']) |
| 43 | |
| 44 | |
| 45 | def SplitTzData(tzdata_file, output_dir): |
| 46 | jar_file = '%s/framework/timezone_host_debug_tools.jar' % android_host_out |
| 47 | subprocess.check_call(['java', '-cp', jar_file, 'ZoneSplitter', tzdata_file, output_dir]) |
| 48 | |
| 49 | |
| 50 | def CreateCsvFiles(zones_dir, csvs_dir): |
| 51 | jar_file = '%s/framework/timezone_host_debug_tools.jar' % android_host_out |
| 52 | subprocess.check_call(['java', '-cp', jar_file, 'TzFileDumper', zones_dir, csvs_dir]) |
| 53 | |
| 54 | |
| 55 | def CheckFileExists(file, filename): |
| 56 | if not os.path.isfile(file): |
| 57 | print("Couldn't find %s (%s)!" % (filename, file)) |
| 58 | sys.exit(1) |
| 59 | |
| 60 | |
| 61 | def main(): |
| 62 | parser = argparse.ArgumentParser() |
| 63 | parser.add_argument('-tzdata', required=True, |
| 64 | help='The tzdata file to process') |
| 65 | parser.add_argument('-output', required=True, |
| 66 | help='The output directory for the dump') |
| 67 | args = parser.parse_args() |
| 68 | |
| 69 | tzdata_file = args.tzdata |
| 70 | output_dir = args.output |
| 71 | |
| 72 | CheckFileExists(tzdata_file, '-tzdata') |
| 73 | if not os.path.exists(output_dir): |
| 74 | print('Creating dir: %s' % output_dir) |
| 75 | os.mkdir(output_dir) |
| 76 | i18nutil.CheckDirExists(output_dir, '-output') |
| 77 | |
| 78 | BuildDebugTools() |
| 79 | |
| 80 | SplitTzData(tzdata_file, output_dir) |
| 81 | |
| 82 | zones_dir = '%s/zones' % output_dir |
| 83 | csvs_dir = '%s/csvs' % output_dir |
| 84 | |
| 85 | i18nutil.CheckDirExists(zones_dir, 'zones output dir') |
| 86 | if not os.path.exists(csvs_dir): |
| 87 | os.mkdir(csvs_dir) |
| 88 | |
| 89 | CreateCsvFiles(zones_dir, csvs_dir) |
| 90 | |
| 91 | print('Look in %s for all extracted files' % output_dir) |
| 92 | print('Look in %s for dumped CSVs' % csvs_dir) |
| 93 | sys.exit(0) |
| 94 | |
| 95 | |
| 96 | if __name__ == '__main__': |
| 97 | main() |