text stringlengths 0 115 |
|---|
锘縫ython3 - << 'EOF' |
import os, re, hashlib, zipfile |
from pathlib import Path |
import xml.etree.ElementTree as ET |
SRC = Path('/home/user/Desktop/QuarterlyBudgetSource.ods') |
BASE = Path('/home/user/.cache/osworld_task/QuarterlyBudgetSource_original.ods') |
BAD_DESKTOP_OTS = Path('/home/user/Desktop/QuarterlyBudgetSource.ots') |
TEMPLATE_DIR = Path('/home/user/.config/libreoffice/4/user/template') |
TOKEN_RE = re.compile(r'quarterlybudgettasktemplate', re.I) |
print("START_CHECK_1") |
os.system('pkill -f soffice.bin >/dev/null 2>&1 || true') |
def sha256(p): |
h = hashlib.sha256() |
with open(p, 'rb') as f: |
for c in iter(lambda: f.read(1024 * 1024), b''): |
h.update(c) |
return h.hexdigest() |
print("SRC_EXISTS_OK" if SRC.exists() else "SRC_EXISTS_BAD") |
print("NO_DESKTOP_OTS_OK" if not BAD_DESKTOP_OTS.exists() else "NO_DESKTOP_OTS_BAD") |
if BASE.exists() and SRC.exists(): |
print("SRC_UNCHANGED_OK" if sha256(SRC) == sha256(BASE) else "SRC_CHANGED_BAD") |
else: |
print("BASELINE_MISSING_BAD") |
with zipfile.ZipFile(SRC) as z: |
mt = z.read("mimetype").decode().lower() |
print("SRC_MIMETYPE_OK" if "spreadsheet" in mt and "template" not in mt else "SRC_MIMETYPE_BAD") |
matches = [p for p in TEMPLATE_DIR.glob("*.ots") if TOKEN_RE.search(p.name)] |
print("TEMPLATE_ONE_MATCH_OK" if len(matches) == 1 else "TEMPLATE_ONE_MATCH_BAD") |
ots = matches[0] |
with zipfile.ZipFile(ots) as z: |
ET.fromstring(z.read("content.xml")) |
print("TEMPLATE_CONTENT_XML_OK") |
print("TEMPLATE_MIMETYPE_OK" if "template" in z.read("mimetype").decode().lower() else "TEMPLATE_MIMETYPE_BAD") |
print("END_CHECK_1") |
EOF |
README.md exists but content is empty.
- Downloads last month
- 27