| 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 20 matching lines...) Expand all Loading... |
| 31 with open(filename) as f: | 31 with open(filename) as f: |
| 32 return f.read() | 32 return f.read() |
| 33 | 33 |
| 34 | 34 |
| 35 def read_file_to_list(filename): | 35 def read_file_to_list(filename): |
| 36 """Returns a list of (stripped) lines for a given filename.""" | 36 """Returns a list of (stripped) lines for a given filename.""" |
| 37 with open(filename) as f: | 37 with open(filename) as f: |
| 38 return [line.rstrip('\n') for line in f] | 38 return [line.rstrip('\n') for line in f] |
| 39 | 39 |
| 40 | 40 |
| 41 def read_pickle_files(pickle_filenames): |
| 42 for pickle_filename in pickle_filenames: |
| 43 with open(pickle_filename) as pickle_file: |
| 44 yield pickle.load(pickle_file) |
| 45 |
| 46 |
| 41 def write_file(new_text, destination_filename, only_if_changed): | 47 def write_file(new_text, destination_filename, only_if_changed): |
| 42 if only_if_changed and os.path.isfile(destination_filename): | 48 if only_if_changed and os.path.isfile(destination_filename): |
| 43 with open(destination_filename) as destination_file: | 49 with open(destination_filename) as destination_file: |
| 44 if destination_file.read() == new_text: | 50 if destination_file.read() == new_text: |
| 45 return | 51 return |
| 46 with open(destination_filename, 'w') as destination_file: | 52 with open(destination_filename, 'w') as destination_file: |
| 47 destination_file.write(new_text) | 53 destination_file.write(new_text) |
| 48 | 54 |
| 49 | 55 |
| 50 def write_pickle_file(pickle_filename, data, only_if_changed): | 56 def write_pickle_file(pickle_filename, data, only_if_changed): |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 162 |
| 157 def get_put_forward_interfaces_from_idl(file_contents): | 163 def get_put_forward_interfaces_from_idl(file_contents): |
| 158 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' | 164 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' |
| 159 r'readonly\s+' | 165 r'readonly\s+' |
| 160 r'attribute\s+' | 166 r'attribute\s+' |
| 161 r'(\w+)') | 167 r'(\w+)') |
| 162 return sorted(set(match.group(1) | 168 return sorted(set(match.group(1) |
| 163 for match in re.finditer(put_forwards_pattern, | 169 for match in re.finditer(put_forwards_pattern, |
| 164 file_contents, | 170 file_contents, |
| 165 flags=re.DOTALL))) | 171 flags=re.DOTALL))) |
| OLD | NEW |