51 lines
946 B
Python
51 lines
946 B
Python
from pathlib import Path
|
|
import pickledb
|
|
import subprocess
|
|
import sys
|
|
|
|
PATH = Path("/data/backup/Photos")
|
|
PAR2_DB = PATH.joinpath(".par2.db")
|
|
|
|
db = pickledb.load(PAR2_DB, False)
|
|
|
|
extensions = {
|
|
".gif",
|
|
".jpg",
|
|
".jpeg",
|
|
".dng",
|
|
".cr2",
|
|
".orf",
|
|
".nef",
|
|
".psd",
|
|
".png",
|
|
".heic",
|
|
".heif",
|
|
".hevc",
|
|
".mp4",
|
|
}
|
|
|
|
stored_exception = None
|
|
|
|
try:
|
|
files = list(PATH.rglob("*"))
|
|
|
|
for file in files:
|
|
if file.suffix.lower() in extensions:
|
|
rel = str(file.relative_to(PATH))
|
|
if not db.exists(rel):
|
|
result = subprocess.call(["lib/par2", "create", str(file)])
|
|
if result == 0:
|
|
db.set(rel, "done")
|
|
else:
|
|
continue
|
|
if stored_exception:
|
|
break
|
|
except KeyboardInterrupt:
|
|
stored_exception = sys.exc_info()
|
|
print("Rescued!")
|
|
|
|
print("Saving DB...")
|
|
|
|
db.dump()
|
|
|
|
print("Done.")
|