-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstatus.py
More file actions
34 lines (31 loc) · 1.26 KB
/
Copy pathstatus.py
File metadata and controls
34 lines (31 loc) · 1.26 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
import os
import logging
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, Undefined, config
from datetime import datetime, timezone
from repoinfo import RepoInfo
@dataclass_json(undefined=Undefined.EXCLUDE)
@dataclass
class Status:
repos:dict[str, RepoInfo] = field(default_factory=lambda: dict())
last_run:datetime = datetime.min.replace(tzinfo=timezone.utc)
# last_snapshot_verify:datetime = datetime.min.replace(tzinfo=timezone.utc)
# last_snapshot_verify_errors:int = 0
# last_content_verify:datetime = datetime.min.replace(tzinfo=timezone.utc)
# last_content_verify_errors:int = 0
@classmethod
def load(cls):
if os.path.exists("status.json"):
with open("status.json", 'r', encoding="utf-8") as file:
try:
#j = json.load(file)
raw_json = file.read()
s = Status.from_json(raw_json)
return s
except Exception as exc:
logging.error("Exception when loading status file - report this only if it repeats", exc_info=exc)
return Status()
def save(self):
j = self.to_json(indent=2)
with open("status.json", 'w') as file:
file.write(j)