"""Restore reviewed DOCX layout and media without exposing excluded source data. Run with python3 -I and explicit --source / --project paths. Source files are never modified. --check only validates the generated packages and references. Old .doc files remain the existing clearly-labelled text conversions: this tool never invokes an unapproved Office converter. No new third-party dependency is needed beyond lxml (already installed alongside python-docx). """ import argparse import copy import hashlib import io import json import posixpath import re import tempfile import zipfile from pathlib import Path from lxml import etree as ET W = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main' R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships' PKG = 'http://schemas.openxmlformats.org/package/2006/relationships' NS = {'w': W, 'r': R} # Explicitly reviewed media allowlists: unknown new images stop the import. MEDIA = { 'yy-e8aba6fc581d': {'image1.jpeg'}, 'yy-d1ac14d56e79': {'image1.jpeg', 'image2.jpeg', 'image3.jpeg', 'image4.jpeg'}, 'yy-1be8039474b0': {'image1.jpeg'}, 'yy-46cd9da9d1c7': {'image1.jpeg'}, 'yy-e44ee7185d30': {'image1.jpeg'}, 'yy-c018fd1d6577': {f'image{i}.jpeg' for i in range(1, 6)}, 'yy-4a9181c97fae': {'image1.png', 'image2.jpeg', 'image3.jpeg'}, 'yy-4beac9bea263': {f'image{i}.jpeg' for i in range(1, 10)}, } EXCLUDE = { 'yy-1be8039474b0': {'image1.jpeg': '专家手写签名,展示副本移除'}, 'yy-46cd9da9d1c7': {'image1.jpeg': '专家手写签名,展示副本移除'}, 'yy-4beac9bea263': { f'image{i}.jpeg': '颁奖投屏可读学生姓名和班级,待提供脱敏图片' for i in (4, 5, 6) }, } # These events lacked any standalone photographs. Other restored photographs # stay in their original document context rather than duplicating existing galleries. GALLERY = { 'yy-e44ee7185d30': {'image1.jpeg': '智慧康养人才培养改革方案教研现场'}, 'yy-4beac9bea263': { 'image1.jpeg': '护士节主题活动致辞', 'image2.jpeg': '护士节主题活动舞台展示', 'image3.jpeg': '护理服饰演绎与集体展示', 'image7.jpeg': '护理学子宣誓仪式', 'image8.jpeg': '护理传光授帽仪式', 'image9.jpeg': '护士节主题活动集体合影', }, } PATTERNS = [ (re.compile(r'1982\s*年生[,,]?'), ''), (re.compile(r'1999\.10[,,]?'), ''), (re.compile(r'(?