Chromium Code Reviews| Index: build/android/gyp/copy_resources_v17.py |
| diff --git a/build/android/gyp/copy_resources_v17.py b/build/android/gyp/copy_resources_v17.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4ec07765c71f16778968737c12f26a0f06932269 |
| --- /dev/null |
| +++ b/build/android/gyp/copy_resources_v17.py |
| @@ -0,0 +1,84 @@ |
| +#!/usr/bin/env python |
| +# |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import optparse |
| +import os |
| +import sys |
| + |
| +from util import build_utils |
| + |
| + |
| +def copy_resources_in_dir(input_dir, output_dir): |
|
cjhopman
2013/04/26 20:57:31
Chrome uses MixedCase for function names (except f
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done.
|
| + """Copy resources in the directory recursively. |
| + """ |
| + |
| + for root, dirs, files in os.walk(input_dir, followlinks=True): |
| + relative_dir = os.path.relpath(root, input_dir) |
| + for file_name in files: |
| + if not file_name.lower().endswith('.xml'): |
| + continue |
|
cjhopman
2013/04/26 20:57:31
You could use build_utils.FindInDirectory() here.
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done. Much shorter thanks!
|
| + input_filename = os.path.join(input_dir, relative_dir, file_name) |
| + output_filename = os.path.join(output_dir, relative_dir, file_name) |
| + |
| + build_utils.MakeDirectory(os.path.dirname(input_filename)) |
|
cjhopman
2013/04/26 20:57:31
I don't think you need to make the input directory
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done.
|
| + build_utils.MakeDirectory(os.path.dirname(output_filename)) |
| + build_utils.CopyFile(input_filename, output_filename) |
| + |
| + |
| +def ParseArgs(): |
| + """Parses command line options. |
| + |
| + Returns: |
| + An options object as from optparse.OptionsParser.parse_args() |
| + """ |
| + parser = optparse.OptionParser() |
| + parser.add_option('--res-dir', |
| + help='directory containing resources to be copied') |
| + parser.add_option('--res-v17-dir', |
| + help='dest directory to be copied.') |
| + |
| + (options, args) = parser.parse_args() |
|
cjhopman
2013/04/26 20:57:31
don't need parentheses, just "options, args"
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done.
|
| + |
| + if args: |
| + parser.error('No positional arguments should be given.') |
| + |
| + # Check that required options have been provided. |
| + required_options = ('res_dir', 'res_v17_dir') |
| + build_utils.CheckOptions(options, parser, required=required_options) |
| + return options |
| + |
| + |
| +def main(argv): |
| + """Copy resource files and add -v17 to the sub directory names. |
|
cjhopman
2013/04/26 20:57:31
I'd prefer a file-level docstring (or have both).
Kibeom Kim (inactive)
2013/04/27 00:05:07
Done.
|
| + """ |
| + options = ParseArgs() |
| + |
| + res_sub_dir_names = os.walk(options.res_dir).next()[1] |
| + build_utils.MakeDirectory(options.res_v17_dir) |
| + |
| + for res_sub_dir_name in res_sub_dir_names: |
| + dir_pieces = res_sub_dir_name.split('-') |
| + resource_type = dir_pieces[0] |
| + qualifiers = dir_pieces[1:] |
| + |
| + # We only copy resources under layout*/ and xml*/. |
| + if resource_type not in ('layout', 'xml'): |
| + continue |
| + |
| + # Skip RTL resources because they are not supported by API 14. |
| + if 'ldrtl' in qualifiers: |
| + continue |
| + |
| + # Copy all the resource files recursively. |
| + copy_resources_in_dir(os.path.join(options.res_dir, |
| + res_sub_dir_name), |
| + os.path.join(options.res_v17_dir, |
| + res_sub_dir_name + '-v17')) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv)) |
| + |