-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
74 lines (57 loc) · 1.33 KB
/
utils.py
File metadata and controls
74 lines (57 loc) · 1.33 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import hashlib
import yaml
from dataclasses import dataclass
def file_md5sum(path):
BUF_SIZE = 65536
md5 = hashlib.md5()
# try:
with open(path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
md5.update(data)
return md5.hexdigest()
def get_yaml():
with open("config.yaml") as f:
config_dict = yaml.safe_load(f.read())
return config_dict
@dataclass
class Settings:
purge_ok: bool = False
mirror_ok: bool = False
@dataclass
class Local:
gphoto_upload_queue: str
mirror_root: str
image_filetypes: list
log_file_base: str
mongod_path: str
database: str
@dataclass
class Gphotos:
host: str
database: str
collection: str
gphoto_db_alias: str
@dataclass
class PathHistory:
host: str
database: str
collection: str
@dataclass
class Cfg:
settings: Settings
local: Local
gphotos: Gphotos
path_history: PathHistory
def config():
with open("config.yaml") as f:
config_dict = yaml.safe_load(f.read())
cfg = Cfg(
settings=Settings(**config_dict["settings"]),
local=Local(**config_dict["local"]),
gphotos=Gphotos(**config_dict["gphotos"]),
path_history=PathHistory(**config_dict["path_history"]),
)
return cfg