| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Module to manage IDL files.""" | 6 """Module to manage IDL files.""" |
| 7 | 7 |
| 8 import copy | 8 import copy |
| 9 import pickle | 9 import pickle |
| 10 import logging | 10 import logging |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 def Cache(self): | 125 def Cache(self): |
| 126 """Serialize the database using pickle for faster startup in the future | 126 """Serialize the database using pickle for faster startup in the future |
| 127 """ | 127 """ |
| 128 output_file = open(os.path.join(self._root_dir, 'cache.pickle'), 'wb') | 128 output_file = open(os.path.join(self._root_dir, 'cache.pickle'), 'wb') |
| 129 pickle.dump(self._all_interfaces, output_file) | 129 pickle.dump(self._all_interfaces, output_file) |
| 130 pickle.dump(self._interfaces_to_delete, output_file) | 130 pickle.dump(self._interfaces_to_delete, output_file) |
| 131 | 131 |
| 132 def LoadFromCache(self): | 132 def LoadFromCache(self): |
| 133 """Deserialize the database using pickle for fast startup | 133 """Deserialize the database using pickle for fast startup |
| 134 """ | 134 """ |
| 135 input_file = open(os.path.join(self._root_dir, 'cache.pickle'), 'rb') | 135 input_file_name = os.path.join(self._root_dir, 'cache.pickle') |
| 136 if not os.path.isfile(input_file_name): |
| 137 self.Load() |
| 138 return |
| 139 input_file = open(input_file_name, 'rb') |
| 136 self._all_interfaces = pickle.load(input_file) | 140 self._all_interfaces = pickle.load(input_file) |
| 137 self._interfaces_to_delete = pickle.load(input_file) | 141 self._interfaces_to_delete = pickle.load(input_file) |
| 142 input_file.close() |
| 138 | 143 |
| 139 def Save(self): | 144 def Save(self): |
| 140 """Saves all in-memory interfaces into files.""" | 145 """Saves all in-memory interfaces into files.""" |
| 141 for interface in self._all_interfaces.values(): | 146 for interface in self._all_interfaces.values(): |
| 142 self._SaveInterfaceFile(interface) | 147 self._SaveInterfaceFile(interface) |
| 143 for interface_name in self._interfaces_to_delete: | 148 for interface_name in self._interfaces_to_delete: |
| 144 self._DeleteInterfaceFile(interface_name) | 149 self._DeleteInterfaceFile(interface_name) |
| 145 | 150 |
| 146 def _SaveInterfaceFile(self, interface): | 151 def _SaveInterfaceFile(self, interface): |
| 147 """Saves an interface into the database. | 152 """Saves an interface into the database. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 raise RuntimeError('Interface %s not found' % interface_name) | 218 raise RuntimeError('Interface %s not found' % interface_name) |
| 214 self._interfaces_to_delete.append(interface_name) | 219 self._interfaces_to_delete.append(interface_name) |
| 215 del self._all_interfaces[interface_name] | 220 del self._all_interfaces[interface_name] |
| 216 | 221 |
| 217 def _DeleteInterfaceFile(self, interface_name): | 222 def _DeleteInterfaceFile(self, interface_name): |
| 218 """Actual file deletion""" | 223 """Actual file deletion""" |
| 219 file_path = self._FilePath(interface_name) | 224 file_path = self._FilePath(interface_name) |
| 220 if os.path.exists(file_path): | 225 if os.path.exists(file_path): |
| 221 _logger.debug('deleting %s' % file_path) | 226 _logger.debug('deleting %s' % file_path) |
| 222 os.remove(file_path) | 227 os.remove(file_path) |
| OLD | NEW |