MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / _apply_left_logo

Function _apply_left_logo

demo/app.py:416–479  ·  view source on GitHub ↗

Use the first institutional logo uploaded by the user: - Copy it into output/poster_latex_proj/logos/ as left_logo. - Replace 'logos/left_logo.png' in poster_output.tex with the proper file extension Does NOT convert formats. Simply renames and rewrites the tex reference.

(OUTPUT_DIR: Path, logo_files, logs)

Source from the content-addressed store, hash-verified

414
415
416def _apply_left_logo(OUTPUT_DIR: Path, logo_files, logs):
417 """
418 Use the first institutional logo uploaded by the user:
419 - Copy it into output/poster_latex_proj/logos/ as left_logo.<ext>
420 - Replace 'logos/left_logo.png' in poster_output.tex with the proper file extension
421 Does NOT convert formats. Simply renames and rewrites the tex reference.
422 """
423 if not logo_files:
424 logs.append("ℹ️ No institutional logo uploaded.")
425 return False
426
427 if isinstance(logo_files, (list, tuple)) and len(logo_files) > 1:
428 logs.append("Multiple institutional logos uploaded.")
429 return False
430
431 # Single file case
432 f = logo_files[0] if isinstance(logo_files, (list, tuple)) else logo_files
433 if not f:
434 logs.append("ℹ️ No institutional logo uploaded.")
435 return False
436
437 ext = Path(f.name).suffix or ".png" # fallback to .png if no extension
438 logos_dir = OUTPUT_DIR / "poster_latex_proj" / "logos"
439 tex_path = OUTPUT_DIR / "poster_latex_proj" / "poster_output.tex"
440
441 try:
442 logos_dir.mkdir(parents=True, exist_ok=True)
443 dst = logos_dir / f"left_logo{ext}"
444 shutil.copy(f.name, dst)
445 logs.append(f"🏷️ Institutional logo copied to: {dst.relative_to(OUTPUT_DIR)}")
446 except Exception as e:
447 logs.append(f"⚠️ Failed to copy institutional logo: {e}")
448 return False
449
450 if not tex_path.exists():
451 logs.append("⚠️ poster_output.tex not found, cannot replace left_logo path.")
452 return False
453
454 try:
455 text = tex_path.read_text(encoding="utf-8")
456 old = "logos/left_logo.png"
457 new = f"logos/left_logo{ext}"
458
459 if old in text:
460 tex_path.write_text(text.replace(old, new), encoding="utf-8")
461 logs.append(f"🛠️ Replaced left_logo.png → left_logo{ext} in poster_output.tex")
462 return True
463
464 # Fallback (covers weird spacing or macro variations)
465 import re
466 pattern = r"(logos/left_logo)\.png"
467 new_text, n = re.subn(pattern, r"\1" + ext, text)
468
469 if n > 0:
470 tex_path.write_text(new_text, encoding="utf-8")
471 logs.append(f"🛠️ Replaced left_logo.png → left_logo{ext} (regex fallback)")
472 return True
473

Callers 1

run_pipelineFunction · 0.85

Calls 1

copyMethod · 0.45

Tested by

no test coverage detected