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 31 matching lines...) Loading... |
42 for pickle_filename in pickle_filenames: | 42 for pickle_filename in pickle_filenames: |
43 with open(pickle_filename) as pickle_file: | 43 with open(pickle_filename) as pickle_file: |
44 yield pickle.load(pickle_file) | 44 yield pickle.load(pickle_file) |
45 | 45 |
46 | 46 |
47 def write_file(new_text, destination_filename, only_if_changed): | 47 def write_file(new_text, destination_filename, only_if_changed): |
48 if only_if_changed and os.path.isfile(destination_filename): | 48 if only_if_changed and os.path.isfile(destination_filename): |
49 with open(destination_filename) as destination_file: | 49 with open(destination_filename) as destination_file: |
50 if destination_file.read() == new_text: | 50 if destination_file.read() == new_text: |
51 return | 51 return |
| 52 destination_dirname = os.path.dirname(destination_filename) |
| 53 if not os.path.exists(destination_dirname): |
| 54 os.makedirs(destination_dirname) |
52 with open(destination_filename, 'w') as destination_file: | 55 with open(destination_filename, 'w') as destination_file: |
53 destination_file.write(new_text) | 56 destination_file.write(new_text) |
54 | 57 |
55 | 58 |
56 def write_pickle_file(pickle_filename, data, only_if_changed): | 59 def write_pickle_file(pickle_filename, data, only_if_changed): |
57 if only_if_changed and os.path.isfile(pickle_filename): | 60 if only_if_changed and os.path.isfile(pickle_filename): |
58 with open(pickle_filename) as pickle_file: | 61 with open(pickle_filename) as pickle_file: |
59 try: | 62 try: |
60 if pickle.load(pickle_file) == data: | 63 if pickle.load(pickle_file) == data: |
61 return | 64 return |
(...skipping 105 matching lines...) Loading... |
167 | 170 |
168 def get_put_forward_interfaces_from_idl(file_contents): | 171 def get_put_forward_interfaces_from_idl(file_contents): |
169 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' | 172 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' |
170 r'readonly\s+' | 173 r'readonly\s+' |
171 r'attribute\s+' | 174 r'attribute\s+' |
172 r'(\w+)') | 175 r'(\w+)') |
173 return sorted(set(match.group(1) | 176 return sorted(set(match.group(1) |
174 for match in re.finditer(put_forwards_pattern, | 177 for match in re.finditer(put_forwards_pattern, |
175 file_contents, | 178 file_contents, |
176 flags=re.DOTALL))) | 179 flags=re.DOTALL))) |
OLD | NEW |