Standardisation des scripts

This commit is contained in:
2026-08-20 13:01:26 +02:00
parent 2f1cd00e32
commit 352d36e38c
10 changed files with 590 additions and 144 deletions
+47 -25
View File
@@ -1,43 +1,65 @@
import sys
import argparse
import shutil
import sys
from collections.abc import Sequence
from pathlib import Path
from config import IMPORT_DIR
from copienator import (
EvaluationWorkspace,
ExitCode,
evaluation_parser,
execute,
workspace_from_args,
)
def sync_annotated(dir_arg, refaire):
if not refaire:
bgnot_dir = Path(dir_arg) / "BGnot"
else:
bgnot_dir = Path(dir_arg) / "BRnot"
annotated_dir = IMPORT_DIR
def sync_annotated(
workspace: EvaluationWorkspace,
*,
refaire: bool = False,
import_dir: Path,
) -> ExitCode:
annotation_name = "BRnot" if refaire else "BGnot"
workspace.require_directories(annotation_name)
annotation_dir = workspace.root / annotation_name
annotated_dir = Path(import_dir).expanduser()
if not annotated_dir.is_dir():
print(f"Error: Directory {annotated_dir} does not exist.")
return
print(f"Error: directory does not exist: {annotated_dir}", file=sys.stderr)
return ExitCode.INVALID_WORKSPACE
# Iterate over all PDF files in the annotated directory
missing_targets = 0
for pdf_file in annotated_dir.glob("*.pdf"):
subdir_name = pdf_file.stem # 'f' from 'f.pdf'
target_subdir = bgnot_dir / subdir_name
target_subdir = annotation_dir / pdf_file.stem
if not target_subdir.is_dir():
print(f"Warning: Directory {target_subdir} not found.")
print(f"Warning: directory not found: {target_subdir}", file=sys.stderr)
missing_targets += 1
else:
dest_file = target_subdir / "Concat_annotated.pdf"
print("copying ", pdf_file, " to ", dest_file)
print(f"Copying {pdf_file} to {dest_file}")
shutil.copy2(pdf_file, dest_file)
return ExitCode.PARTIAL if missing_targets else ExitCode.SUCCESS
import argparse
def build_parser() -> argparse.ArgumentParser:
parser = evaluation_parser("Import handwritten annotations from the tablet directory.")
parser.add_argument("--refaire", action="store_true", help="Process only copies/labels defined in refaire.json")
return parser
def run(workspace: EvaluationWorkspace, *, refaire: bool = False) -> ExitCode:
return sync_annotated(workspace, refaire=refaire, import_dir=Path(IMPORT_DIR))
def main(argv: Sequence[str] | None = None) -> int:
parser = build_parser()
return execute(
parser,
argv,
lambda args: run(workspace_from_args(args), refaire=args.refaire),
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Move to tablette folder.")
parser.add_argument("dir", help="The directory to process")
parser.add_argument("--refaire", action="store_true", help="Process only copies/labels defined in refaire.json")
args = parser.parse_args()
root_dir = args.dir
sync_annotated(root_dir, args.refaire)
raise SystemExit(main())