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

Unified Diff: build/android/gyp/copy_resources_v17.py

Issue 14476011: [Android] Auto-generate API 14 resources from the existing API 17 resources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added copying script action. Pretty much complete I think Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
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))
+
« no previous file with comments | « no previous file | build/android/gyp/generate_v14_resources.py » ('j') | build/android/gyp/generate_v14_resources.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698