When no margin detected, reserve a bit more space for comments

This commit is contained in:
sebastien committed 2026-10-13 21:23:48 +02:00
1 parent e7094d850e
commit 78a7b7679c
17 files changed
+357 -28

No files matched your search

+12 -4
View File
@@ -2,7 +2,6 @@ from __future__ import annotations
import argparse
import re
import shutil
from collections.abc import Sequence
from dataclasses import dataclass
from pathlib import Path
@@ -10,6 +9,8 @@ from typing import Any
from pypdf import PdfWriter
from copienator.pdf_cut import split_pdf
from copienator.annotation_layout import (copy_answer_pdf, move_answer_pdf,
page_parts, save_parts, metadata_path)
from copienator.answer_origins import origins_for, save_origins
from copienator import (
@@ -240,6 +241,8 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
if not instruction.cut and instruction.operator == "->":
origins[key_new] = list(dict.fromkeys([
*origins[key_new], instruction.old_label]))
source_parts = page_parts(source)
destination_parts = page_parts(destination)
writer = PdfWriter()
try:
if instruction.pipe_first:
@@ -251,8 +254,11 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
writer.append(destination)
writer.append(source)
writer.write(temp_output)
save_parts(temp_output, (source_parts + destination_parts
if instruction.pipe_first else destination_parts + source_parts))
except Exception:
temp_output.unlink(missing_ok=True)
metadata_path(temp_output).unlink(missing_ok=True)
raise
finally:
writer.close()
@@ -264,12 +270,13 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
[instruction.old_label] if instruction.operator == "-x"
and not instruction.cut else []
)
shutil.copy(source, temp_output)
copy_answer_pdf(source, temp_output)
current_paths[key_new] = temp_output
temp_files.append(temp_output)
except Exception:
for temporary in temp_files:
temporary.unlink(missing_ok=True)
metadata_path(temporary).unlink(missing_ok=True)
raise
for pdf in files_to_old:
@@ -280,7 +287,7 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
old_name = pdf.with_name(f"{label}_old.pdf")
if pdf != old_name:
old_name.unlink(missing_ok=True)
shutil.move(str(pdf), str(old_name))
move_answer_pdf(pdf, old_name)
set_suffix_and_clean_error(results, copy_id, label, "_old")
for instruction in instructions:
@@ -298,7 +305,7 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
continue
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))
move_answer_pdf(current_path, 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]
@@ -312,6 +319,7 @@ def resolve_manual(workspace: EvaluationWorkspace) -> ExitCode:
for temporary in temp_files:
if temporary not in used_temps:
temporary.unlink(missing_ok=True)
metadata_path(temporary).unlink(missing_ok=True)
for copy_id, label, target in dismissed_conflicts:
# A removed instruction acknowledges the conflict without touching PDFs.