File size: 2,852 Bytes
ac83dbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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("<text:soft-page-break")

if page_break_pos != -1:
    emit("PAGE_BREAK_AFTER_P1_OK")
else:
    emit("PAGE_BREAK_MISSING")


# =================================================
# 5. Table of Contents checks
# =================================================
toc_pos = xml.find("<text:table-of-content")

# Presence
if toc_pos != -1:
    emit("TOC_PRESENT_OK")
else:
    emit("TOC_MISSING")
    sys.exit(0)  # no point checking further TOC properties

# Placement: must be after page break (proxy for page 2)
if not (page_break_pos != -1 and toc_pos > 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("<draw:image")

if img_pos != -1:
    emit("IMG_PRESENT_OK")
else:
    emit("IMG_MISSING")

# Image must be below TOC
if img_pos != -1 and img_pos > 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")