import os import subprocess import sys ODT = "/home/user/Proposals/Project_Alpha_final.odt" TMP_XML = "/tmp/content.xml" def emit(msg: str): print(msg) # ================================================= # 1. File existence # ================================================= if not os.path.isfile(ODT): emit("FILE_MISSING") sys.exit(0) emit("FILE_OK") # ================================================= # 2. Extract content.xml # ================================================= try: with open(TMP_XML, "w", encoding="utf-8") as out: subprocess.run( ["unzip", "-p", ODT, "content.xml"], stdout=out, stderr=subprocess.DEVNULL, check=True ) except Exception: emit("CONTENT_MISSING") sys.exit(0) emit("CONTENT_OK") # ================================================= # 3. Load XML safely # ================================================= with open(TMP_XML, "r", encoding="utf-8", errors="ignore") as f: xml = f.read() # Anti-reward-hacking: ensure document is not empty if len(xml.strip()) < 800: emit("CONTENT_MISSING") sys.exit(0) # ================================================= # 4. Manual page break (page-2 proxy) # ================================================= page_break_pos = xml.find(" page_break_pos): emit("TOC_NOT_ON_PAGE2") # TOC title if "Proposal Outline" in xml: emit("TOC_TITLE_OK") else: emit("TOC_TITLE_BAD") # TOC level restriction if 'text:outline-level="1"' in xml: emit("TOC_LEVEL_OK") else: emit("TOC_LEVEL_BAD") # ================================================= # 6. Image checks # ================================================= img_pos = xml.find(" toc_pos: emit("IMG_BELOW_TOC_OK") else: emit("IMG_ABOVE_TOC") # Anchor type if 'text:anchor-type="as-char"' in xml: emit("ANCHOR_OK") else: emit("ANCHOR_BAD") # Width exactly 15 cm if 'svg:width="15cm"' in xml or 'svg:width="150mm"' in xml: emit("WIDTH_OK") else: emit("WIDTH_BAD")