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 logging | 10 import logging |
10 import os | 11 import os |
11 import os.path | 12 import os.path |
12 import shutil | 13 import shutil |
13 import idlnode | 14 import idlnode |
14 import idlparser | 15 import idlparser |
15 import idlrenderer | 16 import idlrenderer |
16 | 17 |
17 _logger = logging.getLogger('database') | 18 _logger = logging.getLogger('database') |
18 | 19 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 interface = idl_file.interfaces[0] | 113 interface = idl_file.interfaces[0] |
113 self._all_interfaces[interface_name] = interface | 114 self._all_interfaces[interface_name] = interface |
114 return interface | 115 return interface |
115 | 116 |
116 def Load(self): | 117 def Load(self): |
117 """Loads all interfaces into memory. | 118 """Loads all interfaces into memory. |
118 """ | 119 """ |
119 # FIXME: Speed this up by multi-threading. | 120 # FIXME: Speed this up by multi-threading. |
120 for (interface_name) in self._ScanForInterfaces(): | 121 for (interface_name) in self._ScanForInterfaces(): |
121 self._LoadInterfaceFile(interface_name) | 122 self._LoadInterfaceFile(interface_name) |
| 123 self.Cache() |
| 124 |
| 125 def Cache(self): |
| 126 """Serialize the database using pickle for faster startup in the future |
| 127 """ |
| 128 output_file = open('../database/cache.pickle', 'wb') |
| 129 pickle.dump(self._all_interfaces, output_file) |
| 130 pickle.dump(self._interfaces_to_delete, output_file) |
| 131 |
| 132 def LoadFromCache(self): |
| 133 """Deserialize the database using pickle for fast startup |
| 134 """ |
| 135 input_file = open('../database/cache.pickle', 'rb') |
| 136 self._all_interfaces = pickle.load(input_file) |
| 137 self._interfaces_to_delete = pickle.load(input_file) |
122 | 138 |
123 def Save(self): | 139 def Save(self): |
124 """Saves all in-memory interfaces into files.""" | 140 """Saves all in-memory interfaces into files.""" |
125 for interface in self._all_interfaces.values(): | 141 for interface in self._all_interfaces.values(): |
126 self._SaveInterfaceFile(interface) | 142 self._SaveInterfaceFile(interface) |
127 for interface_name in self._interfaces_to_delete: | 143 for interface_name in self._interfaces_to_delete: |
128 self._DeleteInterfaceFile(interface_name) | 144 self._DeleteInterfaceFile(interface_name) |
129 | 145 |
130 def _SaveInterfaceFile(self, interface): | 146 def _SaveInterfaceFile(self, interface): |
131 """Saves an interface into the database. | 147 """Saves an interface into the database. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 raise RuntimeError('Interface %s not found' % interface_name) | 213 raise RuntimeError('Interface %s not found' % interface_name) |
198 self._interfaces_to_delete.append(interface_name) | 214 self._interfaces_to_delete.append(interface_name) |
199 del self._all_interfaces[interface_name] | 215 del self._all_interfaces[interface_name] |
200 | 216 |
201 def _DeleteInterfaceFile(self, interface_name): | 217 def _DeleteInterfaceFile(self, interface_name): |
202 """Actual file deletion""" | 218 """Actual file deletion""" |
203 file_path = self._FilePath(interface_name) | 219 file_path = self._FilePath(interface_name) |
204 if os.path.exists(file_path): | 220 if os.path.exists(file_path): |
205 _logger.debug('deleting %s' % file_path) | 221 _logger.debug('deleting %s' % file_path) |
206 os.remove(file_path) | 222 os.remove(file_path) |
OLD | NEW |