Chromium Code Reviews| Index: third_party/google_input_tools/update.py |
| diff --git a/third_party/google_input_tools/update.py b/third_party/google_input_tools/update.py |
| index ce0e79fdba8aaded71389da2bc582a61b62ffe4d..3e4cd7d237c071e9fb5268d23f3e5e3fa952c1d2 100755 |
| --- a/third_party/google_input_tools/update.py |
| +++ b/third_party/google_input_tools/update.py |
| @@ -1,5 +1,5 @@ |
| #!/usr/bin/python |
| -# Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +# Copyright 2014 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. |
| @@ -14,6 +14,14 @@ _BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)' |
| require_regex = re.compile(_BASE_REGEX_STRING % 'require') |
| provide_regex = re.compile(_BASE_REGEX_STRING % 'provide') |
| +preamble = [ |
|
bruthig
2014/10/28 19:20:44
You could do
preamble = os.linesep.join(['Line1',
kevers
2014/10/29 14:27:19
Done.
|
| + '# Copyright 2014 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.', |
| + '', |
| + '# This file is auto-generated using update.py.', |
| + ''] |
| + |
| # Entry-points required to build a virtual keyboard. |
| namespaces = [ |
| 'i18n.input.chrome.inputview.Controller', |
| @@ -171,19 +179,22 @@ def CopyFile(source, target): |
| source: Path to the source file to copy. |
| target: Path to the target location to copy the file. |
| """ |
| - print '%s --> %s' % (source, target) |
| + |
| if not os.path.exists(os.path.dirname(target)): |
| os.makedirs(os.path.dirname(target)) |
| shutil.copy(source, target) |
| -def UpdateFile(filename, input_source, closure_source): |
| +def UpdateFile(filename, input_source, closure_source, target_files): |
| """Updates files in third_party/google_input_tools. |
| + |
| Args: |
| filename: The file to update. |
| input_source: Root of the google_input_tools sandbox. |
| closure_source: Root of the closure_library sandbox. |
| + target_files: List of relative paths to target files. |
| """ |
| + |
| target = '' |
| if filename.startswith(input_source): |
| target = os.path.join('src', filename[len(input_source)+1:]) |
| @@ -192,8 +203,32 @@ def UpdateFile(filename, input_source, closure_source): |
| filename[len(closure_source)+1:]) |
| if len(target) > 0: |
| CopyFile(filename, target) |
| + target_files.append(os.path.relpath(target, os.getcwd())) |
| +def GenerateBuildFile(target_files): |
| + """Updates inputview.gypi. |
| + |
| + Args: |
| + target_files: List of files required to build inputview.js. |
| + """ |
| + |
|
bruthig
2014/10/28 19:20:45
I'm not 100% sure if it will work for the formatti
kevers
2014/10/29 14:27:20
Done.
|
| + sorted_files = sorted(target_files) |
| + file_handle = open('inputview.gypi', 'w') |
| + try: |
| + for line in preamble: |
| + file_handle.write('%s\n' % line) |
| + file_handle.write("{\n") |
| + file_handle.write(" 'variables': {\n") |
| + file_handle.write(" 'inputview_sources': [\n") |
| + for name in sorted_files: |
| + file_handle.write(" '%s',\n" % name) |
| + file_handle.write(" ],\n") |
| + file_handle.write(" }\n") |
| + file_handle.write("}\n") |
| + finally: |
| + file_handle.close() |
| + |
| def main(): |
| """The entrypoint for this script.""" |
| @@ -217,9 +252,6 @@ def main(): |
| input_path = GetGoogleInputToolsSandboxFromOptions(options) |
| closure_library_path = GetClosureLibrarySandboxFromOptions(options) |
| - print 'iput_path = %s' % input_path |
| - print 'closure_library_path = %s' % closure_library_path |
| - |
| if not os.path.isdir(input_path): |
| print 'Could not find google-input-tools sandbox.' |
| exit(1) |
| @@ -232,12 +264,14 @@ def main(): |
| closure_library_path]) |
| dependencies = set() |
| - |
| for name in namespaces: |
| ExtractDependencies(name, providers, requirements, dependencies) |
| + target_files = [] |
| for name in dependencies: |
| - UpdateFile(name, input_path, closure_library_path) |
| + UpdateFile(name, input_path, closure_library_path, target_files) |
| + |
| + GenerateBuildFile(target_files) |
| if __name__ == '__main__': |
| main() |