add overwrite argument to annotating with checks
parent
375305439a
commit
63489c95c7
|
|
@ -100,15 +100,21 @@ def natural_key(text):
|
|||
|
||||
def process_student(args):
|
||||
"""Thread worker: Processes one student."""
|
||||
root_dir, student_id, labels = args
|
||||
print(f"Generating Checkable PDF for: {student_id}")
|
||||
root_dir, student_id, labels, overwrite = args
|
||||
|
||||
output_dir = os.path.join(root_dir, "Bnot", f"Copie{student_id}")
|
||||
|
||||
if os.path.exists(output_dir):
|
||||
if not overwrite:
|
||||
print(f"Skipping {student_id}: Output already exists.")
|
||||
return
|
||||
shutil.rmtree(output_dir)
|
||||
|
||||
print(f"Generating Checkable PDF for: {student_id}")
|
||||
os.makedirs(output_dir)
|
||||
|
||||
label_images = []
|
||||
# ... (rest of the function remains exactly the same)
|
||||
all_checkboxes = []
|
||||
bnote_entries = [] # For bnote.json
|
||||
|
||||
|
|
@ -178,17 +184,6 @@ def process_student(args):
|
|||
with open(os.path.join(output_dir, "checkboxes.json"), "w") as f:
|
||||
json.dump(final_json_map, f, indent=2)
|
||||
|
||||
|
||||
# # Pour éviter du drift, avec img2pdf
|
||||
# # Pb : Xournal can't add annotations
|
||||
# temp_img_path = os.path.join(output_dir, "Reference.jpg")
|
||||
# concat_img.save(temp_img_path, quality=90) # Save as standard image first
|
||||
# with open(os.path.join(output_dir, "Concat.pdf"), "wb") as f:
|
||||
# f.write(img2pdf.convert(temp_img_path))
|
||||
|
||||
|
||||
# Avec reportlab.pdfgen
|
||||
# Au moins, le drift n'empire pas au fil de la copie
|
||||
temp_img_path = os.path.join(output_dir, "Reference.jpg") # Can't use png here
|
||||
concat_img.save(temp_img_path, quality=90)
|
||||
|
||||
|
|
@ -198,21 +193,17 @@ def process_student(args):
|
|||
c.drawImage(temp_img_path, 0, 0, width=w, height=h)
|
||||
c.save()
|
||||
|
||||
# print("Debug : size", w, h)
|
||||
# Ancien code, avec du drift
|
||||
# concat_img.save(os.path.join(output_dir, "Concat.pdf"), "PDF", resolution=DPI)
|
||||
# concat_img.save(os.path.join(output_dir, "Reference.png"))
|
||||
|
||||
# Try to fix the drift with 72 DPI, non essayé
|
||||
# concat_img.save(os.path.join(output_dir, "Concat.pdf"), "PDF", resolution=72.0)
|
||||
# concat_img.save(os.path.join(output_dir, "Reference.jpg"))
|
||||
import argparse # Added
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python annotating_with_checks.py <Dir> or <File>")
|
||||
sys.exit(1)
|
||||
parser = argparse.ArgumentParser(description="Generate annotated PDFs.")
|
||||
parser.add_argument("input_path", help="Directory or specific file path")
|
||||
parser.add_argument("--overwrite", action="store_true", help="Overwrite existing output files")
|
||||
|
||||
input_path = sys.argv[1]
|
||||
args = parser.parse_args()
|
||||
|
||||
input_path = args.input_path
|
||||
overwrite = args.overwrite # Capture flag
|
||||
target_id = None
|
||||
|
||||
# Detect if input is a specific file
|
||||
|
|
@ -238,9 +229,7 @@ if __name__ == "__main__":
|
|||
print(f"Student ID {target_id} not found in directory scan.")
|
||||
results = {}
|
||||
|
||||
tasks = [(root_dir, sid, lbls) for sid, lbls in results.items()]
|
||||
|
||||
# print(tasks)
|
||||
tasks = sorted([(root_dir, sid, lbls, overwrite) for sid, lbls in results.items()])
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
|
||||
results = executor.map(process_student, tasks)
|
||||
|
|
|
|||
Loading…
Reference in New Issue