Left: | ||
Right: |
LEFT | RIGHT |
---|---|
(no file at all) | |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """The fake storage intended for testing.""" | 2 """The fake storage intended for testing.""" |
3 | 3 |
4 import heapq | 4 import heapq |
5 | 5 |
6 from plaso.lib import definitions | 6 from plaso.lib import definitions |
7 from plaso.lib import py2to3 | 7 from plaso.lib import py2to3 |
8 from plaso.storage import interface | 8 from plaso.storage import interface |
9 | 9 |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 Args: | 87 Args: |
88 session (Session): session the storage changes are part of. | 88 session (Session): session the storage changes are part of. |
89 storage_type (Optional[str]): storage type. | 89 storage_type (Optional[str]): storage type. |
90 task(Optional[Task]): task. | 90 task(Optional[Task]): task. |
91 """ | 91 """ |
92 super(FakeStorageWriter, self).__init__( | 92 super(FakeStorageWriter, self).__init__( |
93 session, storage_type=storage_type, task=task) | 93 session, storage_type=storage_type, task=task) |
94 self._errors = [] | 94 self._errors = [] |
95 self._events = [] | 95 self._events = [] |
96 self._is_open = False | 96 self._is_open = False |
97 self._task_storage_writers = {} | |
97 self.analysis_reports = [] | 98 self.analysis_reports = [] |
98 self.event_sources = [] | 99 self.event_sources = [] |
99 self.event_tags = [] | 100 self.event_tags = [] |
100 self.session_completion = None | 101 self.session_completion = None |
101 self.session_start = None | 102 self.session_start = None |
102 self.task_completion = None | 103 self.task_completion = None |
103 self.task_start = None | 104 self.task_start = None |
104 | 105 |
105 def _RaiseIfNotWritable(self): | 106 def _RaiseIfNotWritable(self): |
106 """Raises if the storage file is not writable. | 107 """Raises if the storage file is not writable. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 Args: | 186 Args: |
186 event_tag (EventTag): event tag. | 187 event_tag (EventTag): event tag. |
187 | 188 |
188 Raises: | 189 Raises: |
189 IOError: when the storage writer is closed. | 190 IOError: when the storage writer is closed. |
190 """ | 191 """ |
191 self._RaiseIfNotWritable() | 192 self._RaiseIfNotWritable() |
192 | 193 |
193 self.event_tags.append(event_tag) | 194 self.event_tags.append(event_tag) |
194 | 195 |
195 def CreateTaskStorage(self, unused_task): | 196 def CreateTaskStorage(self, task): |
196 """Creates a task storage. | 197 """Creates a task storage. |
197 | 198 |
198 Args: | 199 Args: |
199 task (Task): task. | 200 task (Task): task. |
200 | 201 |
201 Returns: | 202 Returns: |
202 StorageWriter: storage writer. | 203 FakeStorageWriter: storage writer. |
203 | 204 |
204 Raises: | 205 Raises: |
205 NotImplementedError: since there is no implementation. | 206 IOError: if the task storage already exist. |
onager
2017/07/25 08:31:47
exists
Joachim Metz
2017/07/27 06:55:03
Done.
| |
206 """ | 207 """ |
207 raise NotImplementedError() | 208 if task.identifier in self._task_storage_writers: |
209 raise IOError(u'Storage writer for task: {0:s} already exists.'.format( | |
210 task.identifier)) | |
211 | |
212 storage_writer = FakeStorageWriter( | |
213 self._session, storage_type=definitions.STORAGE_TYPE_TASK, task=task) | |
214 self._task_storage_writers[task.identifier] = storage_writer | |
215 return storage_writer | |
208 | 216 |
209 def Close(self): | 217 def Close(self): |
210 """Closes the storage writer. | 218 """Closes the storage writer. |
211 | 219 |
212 Raises: | 220 Raises: |
213 IOError: when the storage writer is closed. | 221 IOError: when the storage writer is closed. |
214 """ | 222 """ |
215 self._RaiseIfNotWritable() | 223 self._RaiseIfNotWritable() |
216 | 224 |
217 self._is_open = False | 225 self._is_open = False |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 IOError: if the storage writer is already opened. | 333 IOError: if the storage writer is already opened. |
326 """ | 334 """ |
327 if self._is_open: | 335 if self._is_open: |
328 raise IOError(u'Storage writer already opened.') | 336 raise IOError(u'Storage writer already opened.') |
329 | 337 |
330 self._is_open = True | 338 self._is_open = True |
331 | 339 |
332 self._first_written_event_source_index = len(self.event_sources) | 340 self._first_written_event_source_index = len(self.event_sources) |
333 self._written_event_source_index = self._first_written_event_source_index | 341 self._written_event_source_index = self._first_written_event_source_index |
334 | 342 |
335 def PrepareMergeTaskStorage(self, unused_task): | 343 def PrepareMergeTaskStorage(self, task): |
336 """Prepares a task storage for merging. | 344 """Prepares a task storage for merging. |
337 | 345 |
338 Args: | 346 Args: |
339 task (Task): task. | 347 task (Task): task. |
340 | 348 |
341 Raises: | 349 Raises: |
342 IOError: if the storage type is not supported or | 350 IOError: if the task storage does not exist. |
343 if the temporary path for the task storage does no exist. | 351 """ |
344 """ | 352 if task.identifier not in self._task_storage_writers: |
345 raise NotImplementedError() | 353 raise IOError(u'Storage writer for task: {0:s} does not exist.'.format( |
354 task.identifier)) | |
346 | 355 |
347 def ReadPreprocessingInformation(self, unused_knowledge_base): | 356 def ReadPreprocessingInformation(self, unused_knowledge_base): |
348 """Reads preprocessing information. | 357 """Reads preprocessing information. |
349 | 358 |
350 The preprocessing information contains the system configuration which | 359 The preprocessing information contains the system configuration which |
351 contains information about various system specific configuration data, | 360 contains information about various system specific configuration data, |
352 for example the user accounts. | 361 for example the user accounts. |
353 | 362 |
354 Args: | 363 Args: |
355 knowledge_base (KnowledgeBase): is used to store the preprocessing | 364 knowledge_base (KnowledgeBase): is used to store the preprocessing |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 Raises: | 456 Raises: |
448 IOError: if the storage type does not support writing a task | 457 IOError: if the storage type does not support writing a task |
449 start or when the storage writer is closed. | 458 start or when the storage writer is closed. |
450 """ | 459 """ |
451 self._RaiseIfNotWritable() | 460 self._RaiseIfNotWritable() |
452 | 461 |
453 if self._storage_type != definitions.STORAGE_TYPE_TASK: | 462 if self._storage_type != definitions.STORAGE_TYPE_TASK: |
454 raise IOError(u'Task start not supported by storage type.') | 463 raise IOError(u'Task start not supported by storage type.') |
455 | 464 |
456 self.task_start = self._task.CreateTaskStart() | 465 self.task_start = self._task.CreateTaskStart() |
LEFT | RIGHT |