Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: android_webview/tools/webview_locales_rename_paks.py

Issue 868673003: [WebView] Repack the .pak files for all the locales. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Helper script to repack paks for a list of locales for the Android WebView.
7
8 Gyp doesn't have any built-in looping capability, so this just provides a way to
9 loop over a list of locales when repacking pak files. Based on
10 chrome/tools/build/repack_locales.py
11 """
12
13 import optparse
14 import os
15 import sys
16
17 def calc_output(locale):
18 """Determine the file that will be generated for the given locale."""
19 return os.path.join(PRODUCT_DIR, 'android_webview_assets', locale + '.pak')
mkosiba (inactive) 2015/01/27 10:26:15 maybe let's have a separate folder just for the lo
Ignacio Solla 2015/02/02 17:53:58 Done.
20
21 def calc_input(locale):
22 """Determine the file that needs processing for the given locale."""
23 return os.path.join(SHARE_INT_DIR, 'content', 'app', 'strings',
24 'content_strings_%s.pak' % locale)
25
26 def list_outputs(locales):
27 """Returns the names of the files that will be generated for the given
28 locales.
29
30 This is to provide gyp the list of output files, so build targets can
31 properly track what needs to be built.
32 """
33 return list_files(locales, calc_output)
34
35 def list_inputs(locales):
36 """Returns the names of the files that will be processed for the given
37 locales.
38
39 This is to provide gyp the list of input files, so build targets can properly
40 track their prerequisites.
41 """
42 return list_files(locales, calc_input)
43
44 def list_files(locales, filename_func):
45 """Returns the names of the files generated by filename_func for a list of
46 locales.
47
48 :param filename_func: function that generates a filename for a given locale
49 """
50 files = []
51 for locale in locales:
52 files.append(filename_func(locale))
53 return " ".join(['"%s"' % x for x in files])
54
55 def rename_locales(locales):
56 """ Loop over and renames the given locales."""
57 for locale in locales:
58 os.rename(calc_input(locale), calc_output(locale))
59
60 def DoMain(argv):
61 global SHARE_INT_DIR
62 global PRODUCT_DIR
63
64 parser = optparse.OptionParser("usage: %prog [options] locales")
65 parser.add_option("-i", action="store_true", dest="inputs", default=False,
66 help="Print the expected input file list, then exit.")
67 parser.add_option("-o", action="store_true", dest="outputs", default=False,
68 help="Print the expected output file list, then exit.")
69 parser.add_option("-p", action="store", dest="product_dir",
70 help="Product build files output directory.")
71 parser.add_option("-s", action="store", dest="share_int_dir",
72 help="Shared intermediate build files output directory.")
73 options, locales = parser.parse_args(argv)
74 if not locales:
75 parser.error('Please specify at least one locale to process.\n')
76
77 print_inputs = options.inputs
78 print_outputs = options.outputs
79 SHARE_INT_DIR = options.share_int_dir
80 PRODUCT_DIR = options.product_dir
81
82 if print_inputs and print_outputs:
83 parser.error('Please specify only one of "-i" or "-o".\n')
84
85 if print_inputs:
86 return list_inputs(locales)
87
88 if print_outputs:
89 return list_outputs(locales)
90
91 return rename_locales(locales)
92
93 if __name__ == '__main__':
94 results = DoMain(sys.argv[1:])
95 if results:
96 print results
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698