LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """This file contains the storage factory class.""" | 2 """This file contains the storage factory class.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
| 6 from plaso.lib import definitions |
| 7 from plaso.storage.sqlite import reader as sqlite_reader |
6 from plaso.storage.sqlite import sqlite_file | 8 from plaso.storage.sqlite import sqlite_file |
7 from plaso.storage.sqlite import reader as sqlite_reader | |
8 from plaso.storage.sqlite import writer as sqlite_writer | 9 from plaso.storage.sqlite import writer as sqlite_writer |
9 | |
10 | 10 |
11 class StorageFactory(object): | 11 class StorageFactory(object): |
12 """Storage factory.""" | 12 """Storage factory.""" |
| 13 |
| 14 @classmethod |
| 15 def CreateStorageFile(cls, storage_format): |
| 16 """Creates a storage file. |
| 17 |
| 18 Args: |
| 19 storage_format (str): storage format. |
| 20 |
| 21 Returns: |
| 22 StorageFile: a storage file or None if the storage file cannot be |
| 23 opened or the storage format is not supported. |
| 24 """ |
| 25 if storage_format == definitions.STORAGE_FORMAT_SQLITE: |
| 26 return sqlite_file.SQLiteStorageFile() |
13 | 27 |
14 @classmethod | 28 @classmethod |
15 def CreateStorageFileForFile(cls, path): | 29 def CreateStorageFileForFile(cls, path): |
16 """Creates a storage file based on the file. | 30 """Creates a storage file based on the file. |
17 | 31 |
18 Args: | 32 Args: |
19 path (str): path to the storage file. | 33 path (str): path to the storage file. |
20 | 34 |
21 Returns: | 35 Returns: |
22 StorageFile: a storage file or None if the storage file cannot be | 36 StorageFile: a storage file or None if the storage file cannot be |
(...skipping 10 matching lines...) Expand all Loading... |
33 path (str): path to the storage file. | 47 path (str): path to the storage file. |
34 | 48 |
35 Returns: | 49 Returns: |
36 StorageReader: a storage reader or None if the storage file cannot be | 50 StorageReader: a storage reader or None if the storage file cannot be |
37 opened or the storage format is not supported. | 51 opened or the storage format is not supported. |
38 """ | 52 """ |
39 if sqlite_file.SQLiteStorageFile.CheckSupportedFormat(path): | 53 if sqlite_file.SQLiteStorageFile.CheckSupportedFormat(path): |
40 return sqlite_reader.SQLiteStorageFileReader(path) | 54 return sqlite_reader.SQLiteStorageFileReader(path) |
41 | 55 |
42 @classmethod | 56 @classmethod |
| 57 def CreateStorageWriter(cls, storage_format, session, path): |
| 58 """Creates a storage writer. |
| 59 |
| 60 Args: |
| 61 session (Session): session the storage changes are part of. |
| 62 path (str): path to the storage file. |
| 63 storage_format (str): storage format. |
| 64 |
| 65 Returns: |
| 66 StorageWriter: a storage writer or None if the storage file cannot be |
| 67 opened or the storage format is not supported. |
| 68 """ |
| 69 if storage_format == definitions.STORAGE_FORMAT_SQLITE: |
| 70 return sqlite_writer.SQLiteStorageFileWriter(session, path) |
| 71 |
| 72 @classmethod |
43 def CreateStorageWriterForFile(cls, session, path): | 73 def CreateStorageWriterForFile(cls, session, path): |
44 """Creates a storage writer based on the file. | 74 """Creates a storage writer based on the file. |
45 | 75 |
46 Args: | 76 Args: |
47 session (Session): session the storage changes are part of. | 77 session (Session): session the storage changes are part of. |
48 path (str): path to the storage file. | 78 path (str): path to the storage file. |
49 | 79 |
50 Returns: | 80 Returns: |
51 StorageWriter: a storage writer or None if the storage file cannot be | 81 StorageWriter: a storage writer or None if the storage file cannot be |
52 opened or the storage format is not supported. | 82 opened or the storage format is not supported. |
53 """ | 83 """ |
54 if sqlite_file.SQLiteStorageFile.CheckSupportedFormat(path): | 84 if sqlite_file.SQLiteStorageFile.CheckSupportedFormat(path): |
55 return sqlite_writer.SQLiteStorageFileWriter(session, path) | 85 return sqlite_writer.SQLiteStorageFileWriter(session, path) |
LEFT | RIGHT |