original-label-> information

This commit is contained in:
sebastien committed 2026-09-22 12:20:23 +02:00
1 parent 5009831c7c
commit 96c00fa941
5 files changed
+81

No files matched your search

+16
View File
@@ -10,6 +10,7 @@ from typing import Any
from pypdf import PdfWriter
from copienator.pdf_cut import split_pdf
from copienator.answer_origins import origins_for, save_origins
from copienator import (
CliError,
@@ -204,6 +205,8 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
_validate_pdf_inputs(instructions, initial_paths)
files_to_old: set[Path] = set()
origins = {key: origins_for(workspace.root, *key, path)
for key, path in initial_paths.items()}
temp_files: list[Path] = []
try:
for instruction in instructions:
@@ -212,6 +215,8 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
source = initial_paths[key_old]
destination = current_paths[key_new]
if instruction.cut:
origins[key_old] = []
origins[key_new] = []
percent, keep = instruction.cut
first = source.parent / f"temp_{len(temp_files)}.pdf"
second = source.parent / f"temp_{len(temp_files) + 1}.pdf"
@@ -232,6 +237,9 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
files_to_old.add(initial_paths[key_new])
if instruction.should_merge:
if not instruction.cut and instruction.operator == "->":
origins[key_new] = list(dict.fromkeys([
*origins[key_new], instruction.old_label]))
writer = PdfWriter()
try:
if instruction.pipe_first:
@@ -252,6 +260,10 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
temp_files.append(temp_output)
files_to_old.add(initial_paths[key_new])
elif instruction.should_copy:
origins[key_new] = (
[instruction.old_label] if instruction.operator == "-x"
and not instruction.cut else []
)
shutil.copy(source, temp_output)
current_paths[key_new] = temp_output
temp_files.append(temp_output)
@@ -287,6 +299,10 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
final_name = workspace.copies_dir / f"Copie{copy_id}" / f"{label}_new.pdf"
final_name.unlink(missing_ok=True)
shutil.move(str(current_path), str(final_name))
retained_origins = [origin for origin in origins[(copy_id, label)]
if (copy_id, origin) not in initial_paths
or initial_paths[(copy_id, origin)] not in files_to_old]
save_origins(workspace.root, copy_id, label, final_name, retained_origins)
set_suffix_and_clean_error(results, copy_id, label, "_new")
labels = refaire_by_copy.setdefault(f"Copie{copy_id}", [])
if label not in labels: