-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactories.py
33 lines (24 loc) · 870 Bytes
/
factories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
from hashed_file import HashedFile
from search_types import SearchTypes
class TrieSplitMethodFactory:
def __init__(self):
self.__mapping = {
SearchTypes.BY_HASH: self.__split_by_hash,
SearchTypes.BY_NAME: self.__split_by_name
}
def __getitem__(self, item):
return self.__mapping.get(item, None)
def __split_by_hash(self, hfile: HashedFile):
while not hfile.end_of_file():
yield hfile.get_chunk_hash()
def __split_by_name(self, hfile: HashedFile):
yield hfile.get_base_name()
class FileGrouperFactory:
__mapping = {
SearchTypes.BY_HASH: lambda path: os.stat(path).st_size,
SearchTypes.BY_NAME: lambda path: os.path.splitext(path)[-1]
}
@classmethod
def __class_getitem__(cls, item):
return cls.__mapping.get(item, None)