Manual conflict : utilities
This commit is contained in:
1 parent
f43b713590
commit
c155e3eebc
3 files changed
+100
-3
No files matched your search
@@ -11,6 +11,10 @@ def _path(root):
|
||||
|
||||
def origins_for(root, copy_id, label, pdf):
|
||||
entry = read_json(_path(root), default={}).get(str(copy_id), {}).get(label, {})
|
||||
return _valid_origins(entry, pdf)
|
||||
|
||||
|
||||
def _valid_origins(entry, pdf):
|
||||
if not entry or not Path(pdf).is_file():
|
||||
return []
|
||||
if entry.get("sha256") != sha256(Path(pdf).read_bytes()).hexdigest():
|
||||
@@ -18,6 +22,22 @@ def origins_for(root, copy_id, label, pdf):
|
||||
return entry.get("labels", [])
|
||||
|
||||
|
||||
def populated_labels(root, copy_id, source_label):
|
||||
"""Find current answer PDFs populated from this source's recorded content."""
|
||||
entries = read_json(_path(root), default={}).get(str(copy_id), {})
|
||||
copies = Path(root) / "Copies" / f"Copie{copy_id}"
|
||||
populated = []
|
||||
for label, entry in entries.items():
|
||||
if label == source_label or source_label not in entry.get("labels", []):
|
||||
continue
|
||||
pdf = copies / f"{label}.pdf"
|
||||
if not pdf.is_file():
|
||||
pdf = copies / f"{label}_new.pdf"
|
||||
if source_label in _valid_origins(entry, pdf):
|
||||
populated.append(label)
|
||||
return sorted(populated)
|
||||
|
||||
|
||||
def save_origins(root, copy_id, label, pdf, origins):
|
||||
entry = {"labels": list(dict.fromkeys(origins)),
|
||||
"sha256": sha256(Path(pdf).read_bytes()).hexdigest()}
|
||||
|
||||
Reference in new issue
Block a user