-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastructures.py
56 lines (51 loc) · 1.38 KB
/
datastructures.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from dataclasses import dataclass,field
from datetime import datetime,date
from dataclasses_json import dataclass_json
from typing import List,Any,Dict
import os
import logging
logger = logging.getLogger()
@dataclass_json
@dataclass
class IndexedFile:
Directory: str=None
Name: str=None
#inode number
st_ino: int=None
#device inode
st_dev: int=None
#size in bytes
st_size: int=None
#last access time
st_atime: datetime=None
#last modified time
st_mtime: datetime=None
#created time
st_ctime: datetime=None
SHA256:str=None
EXIF: Dict[str,str]=None
NodeType:str='FILE'
@dataclass_json
@dataclass
class Volume:
files: List[IndexedFile]
Description: str
DeviceID: str
FileSystem: str
FreeSpace: str
Size: str
SystemName: str
VolumeName: str
VolumeSerialNumber: str
BasePath: str
NodeType: str='Volume'
def load_index_if_exists(filepath):
if os.path.exists(filepath):
data = open(filepath, mode='r', encoding='utf-8').read()
return Volume.schema().loads(data, many=True)
else:
logger.warning(f'{filepath} does not exist. creating new index')
return []
def save_index(volumes, filepath):
with open(filepath, mode='w', encoding='utf-8') as f:
f.write(Volume.schema().dumps(volumes, many=True))