| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build
. | 5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build
. |
| 6 | 6 |
| 7 Design doc: http://www.chromium.org/developers/design-documents/idl-build | 7 Design doc: http://www.chromium.org/developers/design-documents/idl-build |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import os | 10 import os |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 idl_file_names = [file_name for file_name in file_names | 292 idl_file_names = [file_name for file_name in file_names |
| 293 if not file_name.startswith('/cygdrive')] | 293 if not file_name.startswith('/cygdrive')] |
| 294 cygdrive_names = [file_name for file_name in file_names | 294 cygdrive_names = [file_name for file_name in file_names |
| 295 if file_name.startswith('/cygdrive')] | 295 if file_name.startswith('/cygdrive')] |
| 296 idl_file_names.extend(resolve_cygpath(cygdrive_names)) | 296 idl_file_names.extend(resolve_cygpath(cygdrive_names)) |
| 297 return idl_file_names | 297 return idl_file_names |
| 298 | 298 |
| 299 | 299 |
| 300 def read_pickle_files(pickle_filenames): | 300 def read_pickle_files(pickle_filenames): |
| 301 for pickle_filename in pickle_filenames: | 301 for pickle_filename in pickle_filenames: |
| 302 with open(pickle_filename) as pickle_file: | 302 yield read_pickle_file(pickle_filename) |
| 303 yield pickle.load(pickle_file) | 303 |
| 304 |
| 305 def read_pickle_file(pickle_filename): |
| 306 with open(pickle_filename) as pickle_file: |
| 307 return pickle.load(pickle_file) |
| 304 | 308 |
| 305 | 309 |
| 306 def write_file(new_text, destination_filename): | 310 def write_file(new_text, destination_filename): |
| 307 # If |new_text| is same with the file content, we skip updating. | 311 # If |new_text| is same with the file content, we skip updating. |
| 308 if os.path.isfile(destination_filename): | 312 if os.path.isfile(destination_filename): |
| 309 with open(destination_filename) as destination_file: | 313 with open(destination_filename) as destination_file: |
| 310 if destination_file.read() == new_text: | 314 if destination_file.read() == new_text: |
| 311 return | 315 return |
| 312 | 316 |
| 313 destination_dirname = os.path.dirname(destination_filename) | 317 destination_dirname = os.path.dirname(destination_filename) |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 514 |
| 511 # Remember an open brace. | 515 # Remember an open brace. |
| 512 match = re_last_brace.search(line) | 516 match = re_last_brace.search(line) |
| 513 was_open_brace = (match and match.group('last') == '{' and 'namespace' n
ot in line) | 517 was_open_brace = (match and match.group('last') == '{' and 'namespace' n
ot in line) |
| 514 | 518 |
| 515 # Let |'\n'.join| emit the last newline. | 519 # Let |'\n'.join| emit the last newline. |
| 516 if output: | 520 if output: |
| 517 output.append('') | 521 output.append('') |
| 518 | 522 |
| 519 return '\n'.join(output) | 523 return '\n'.join(output) |
| OLD | NEW |