-
Notifications
You must be signed in to change notification settings - Fork 1
/
encfilesinfo.py
56 lines (41 loc) · 1.5 KB
/
encfilesinfo.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
import json
import os
from aesmix import MixSlice
def size_decrypt(path, public_metadata):
reader = MixSlice.load_from_file(path, public_metadata)
return len(reader.decrypt())
class EncFilesInfo():
def __init__(self, path, public_metadata, file_finfo):
self._path = path
self._public_metadata = public_metadata
self._file_finfo = file_finfo
self._size = size_decrypt(path, public_metadata)
self._update_finfo()
# ------------------------------------------------------ Helpers
def _update_finfo(self):
finfo = {}
if os.path.isfile(self._file_finfo):
with open(self._file_finfo) as f:
finfo = json.load(f)
finfo['size'] = self._size
with open(self._file_finfo, 'w') as f:
json.dump(finfo, f)
# ------------------------------------------------------ Methods
def rename(self, path, public_metadata, file_finfo):
self._path = path
self._public_metadata = public_metadata
self._file_finfo = file_finfo
self._size = None
# ------------------------------------------------------ Size
@property
def size(self):
if self._size is None:
self._size = size_decrypt(self._path, self._public_metadata)
self._update_finfo()
return self._size
@size.setter
def size(self, value):
if self._size == value:
return
self._size = value
self._update_finfo()