simple-skills 1.3.7 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/package.json +1 -1
- package/skills/engineering/README.md +1 -2
- package/skills/engineering/officedocs/SKILL.md +306 -0
- package/skills/engineering/requirement-workflow/SKILL.md +1 -1
- package/skills/engineering/docx/SKILL.md +0 -617
- package/skills/engineering/docx/scripts/office/__pycache__/soffice.cpython-314.pyc +0 -0
- package/skills/engineering/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/engineering/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
- package/skills/engineering/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
- package/skills/engineering/pptx/SKILL.md +0 -221
- package/skills/engineering/pptx/scripts/__init__.py +0 -0
- package/skills/engineering/pptx/scripts/office/helpers/__init__.py +0 -0
- package/skills/engineering/pptx/scripts/office/helpers/merge_runs.py +0 -199
- package/skills/engineering/pptx/scripts/office/helpers/simplify_redlines.py +0 -197
- package/skills/engineering/pptx/scripts/office/pack.py +0 -159
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +0 -1499
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +0 -146
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +0 -1085
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +0 -11
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +0 -3081
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +0 -23
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +0 -185
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +0 -287
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +0 -1676
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +0 -28
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +0 -144
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +0 -174
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +0 -25
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +0 -18
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +0 -59
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +0 -56
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +0 -195
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +0 -582
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +0 -25
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +0 -4439
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +0 -570
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +0 -509
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +0 -12
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +0 -108
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +0 -96
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +0 -3646
- package/skills/engineering/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +0 -116
- package/skills/engineering/pptx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +0 -42
- package/skills/engineering/pptx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +0 -50
- package/skills/engineering/pptx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +0 -49
- package/skills/engineering/pptx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +0 -33
- package/skills/engineering/pptx/scripts/office/schemas/mce/mc.xsd +0 -75
- package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-2010.xsd +0 -560
- package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-2012.xsd +0 -67
- package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-2018.xsd +0 -14
- package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +0 -20
- package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +0 -13
- package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +0 -4
- package/skills/engineering/pptx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +0 -8
- package/skills/engineering/pptx/scripts/office/soffice.py +0 -183
- package/skills/engineering/pptx/scripts/office/unpack.py +0 -132
- package/skills/engineering/pptx/scripts/office/validate.py +0 -111
- package/skills/engineering/pptx/scripts/office/validators/__init__.py +0 -15
- package/skills/engineering/pptx/scripts/office/validators/base.py +0 -847
- package/skills/engineering/pptx/scripts/office/validators/docx.py +0 -446
- package/skills/engineering/pptx/scripts/office/validators/pptx.py +0 -275
- package/skills/engineering/pptx/scripts/office/validators/redlining.py +0 -247
- package/skills/engineering/xlsx/SKILL.md +0 -320
- package/skills/engineering/xlsx/scripts/office/helpers/__init__.py +0 -0
- package/skills/engineering/xlsx/scripts/office/helpers/merge_runs.py +0 -199
- package/skills/engineering/xlsx/scripts/office/helpers/simplify_redlines.py +0 -197
- package/skills/engineering/xlsx/scripts/office/pack.py +0 -159
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +0 -1499
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +0 -146
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +0 -1085
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +0 -11
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +0 -3081
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +0 -23
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +0 -185
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +0 -287
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +0 -1676
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +0 -28
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +0 -144
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +0 -174
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +0 -25
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +0 -18
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +0 -59
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +0 -56
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +0 -195
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +0 -582
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +0 -25
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +0 -4439
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +0 -570
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +0 -509
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +0 -12
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +0 -108
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +0 -96
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +0 -3646
- package/skills/engineering/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +0 -116
- package/skills/engineering/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +0 -42
- package/skills/engineering/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +0 -50
- package/skills/engineering/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +0 -49
- package/skills/engineering/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +0 -33
- package/skills/engineering/xlsx/scripts/office/schemas/mce/mc.xsd +0 -75
- package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-2010.xsd +0 -560
- package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-2012.xsd +0 -67
- package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-2018.xsd +0 -14
- package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +0 -20
- package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +0 -13
- package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +0 -4
- package/skills/engineering/xlsx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +0 -8
- package/skills/engineering/xlsx/scripts/office/soffice.py +0 -183
- package/skills/engineering/xlsx/scripts/office/unpack.py +0 -132
- package/skills/engineering/xlsx/scripts/office/validate.py +0 -111
- package/skills/engineering/xlsx/scripts/office/validators/__init__.py +0 -15
- package/skills/engineering/xlsx/scripts/office/validators/base.py +0 -847
- package/skills/engineering/xlsx/scripts/office/validators/docx.py +0 -446
- package/skills/engineering/xlsx/scripts/office/validators/pptx.py +0 -275
- package/skills/engineering/xlsx/scripts/office/validators/redlining.py +0 -247
- /package/skills/engineering/{pptx → officedocs}/editing.md +0 -0
- /package/skills/engineering/{pptx → officedocs}/pptxgenjs.md +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/__init__.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/accept_changes.py +0 -0
- /package/skills/engineering/{pptx → officedocs}/scripts/add_slide.py +0 -0
- /package/skills/engineering/{pptx → officedocs}/scripts/clean.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/comment.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/helpers/__init__.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/helpers/merge_runs.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/helpers/simplify_redlines.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/pack.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/mce/mc.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-2010.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-2012.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-2018.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-cex-2018.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-cid-2016.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/schemas/microsoft/wml-symex-2015.xsd +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/soffice.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/unpack.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/validate.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/validators/__init__.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/validators/base.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/validators/docx.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/validators/pptx.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/office/validators/redlining.py +0 -0
- /package/skills/engineering/{xlsx → officedocs}/scripts/recalc.py +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/templates/comments.xml +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/templates/commentsExtended.xml +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/templates/commentsExtensible.xml +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/templates/commentsIds.xml +0 -0
- /package/skills/engineering/{docx → officedocs}/scripts/templates/people.xml +0 -0
- /package/skills/engineering/{pptx → officedocs}/scripts/thumbnail.py +0 -0
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
"""Pack a directory into a DOCX, PPTX, or XLSX file.
|
|
2
|
-
|
|
3
|
-
Validates with auto-repair, condenses XML formatting, and creates the Office file.
|
|
4
|
-
|
|
5
|
-
Usage:
|
|
6
|
-
python pack.py <input_directory> <output_file> [--original <file>] [--validate true|false]
|
|
7
|
-
|
|
8
|
-
Examples:
|
|
9
|
-
python pack.py unpacked/ output.docx --original input.docx
|
|
10
|
-
python pack.py unpacked/ output.pptx --validate false
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
import argparse
|
|
14
|
-
import sys
|
|
15
|
-
import shutil
|
|
16
|
-
import tempfile
|
|
17
|
-
import zipfile
|
|
18
|
-
from pathlib import Path
|
|
19
|
-
|
|
20
|
-
import defusedxml.minidom
|
|
21
|
-
|
|
22
|
-
from validators import DOCXSchemaValidator, PPTXSchemaValidator, RedliningValidator
|
|
23
|
-
|
|
24
|
-
def pack(
|
|
25
|
-
input_directory: str,
|
|
26
|
-
output_file: str,
|
|
27
|
-
original_file: str | None = None,
|
|
28
|
-
validate: bool = True,
|
|
29
|
-
infer_author_func=None,
|
|
30
|
-
) -> tuple[None, str]:
|
|
31
|
-
input_dir = Path(input_directory)
|
|
32
|
-
output_path = Path(output_file)
|
|
33
|
-
suffix = output_path.suffix.lower()
|
|
34
|
-
|
|
35
|
-
if not input_dir.is_dir():
|
|
36
|
-
return None, f"Error: {input_dir} is not a directory"
|
|
37
|
-
|
|
38
|
-
if suffix not in {".docx", ".pptx", ".xlsx"}:
|
|
39
|
-
return None, f"Error: {output_file} must be a .docx, .pptx, or .xlsx file"
|
|
40
|
-
|
|
41
|
-
if validate and original_file:
|
|
42
|
-
original_path = Path(original_file)
|
|
43
|
-
if original_path.exists():
|
|
44
|
-
success, output = _run_validation(
|
|
45
|
-
input_dir, original_path, suffix, infer_author_func
|
|
46
|
-
)
|
|
47
|
-
if output:
|
|
48
|
-
print(output)
|
|
49
|
-
if not success:
|
|
50
|
-
return None, f"Error: Validation failed for {input_dir}"
|
|
51
|
-
|
|
52
|
-
with tempfile.TemporaryDirectory() as temp_dir:
|
|
53
|
-
temp_content_dir = Path(temp_dir) / "content"
|
|
54
|
-
shutil.copytree(input_dir, temp_content_dir)
|
|
55
|
-
|
|
56
|
-
for pattern in ["*.xml", "*.rels"]:
|
|
57
|
-
for xml_file in temp_content_dir.rglob(pattern):
|
|
58
|
-
_condense_xml(xml_file)
|
|
59
|
-
|
|
60
|
-
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
61
|
-
with zipfile.ZipFile(output_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
62
|
-
for f in temp_content_dir.rglob("*"):
|
|
63
|
-
if f.is_file():
|
|
64
|
-
zf.write(f, f.relative_to(temp_content_dir))
|
|
65
|
-
|
|
66
|
-
return None, f"Successfully packed {input_dir} to {output_file}"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def _run_validation(
|
|
70
|
-
unpacked_dir: Path,
|
|
71
|
-
original_file: Path,
|
|
72
|
-
suffix: str,
|
|
73
|
-
infer_author_func=None,
|
|
74
|
-
) -> tuple[bool, str | None]:
|
|
75
|
-
output_lines = []
|
|
76
|
-
validators = []
|
|
77
|
-
|
|
78
|
-
if suffix == ".docx":
|
|
79
|
-
author = "Claude"
|
|
80
|
-
if infer_author_func:
|
|
81
|
-
try:
|
|
82
|
-
author = infer_author_func(unpacked_dir, original_file)
|
|
83
|
-
except ValueError as e:
|
|
84
|
-
print(f"Warning: {e} Using default author 'Claude'.", file=sys.stderr)
|
|
85
|
-
|
|
86
|
-
validators = [
|
|
87
|
-
DOCXSchemaValidator(unpacked_dir, original_file),
|
|
88
|
-
RedliningValidator(unpacked_dir, original_file, author=author),
|
|
89
|
-
]
|
|
90
|
-
elif suffix == ".pptx":
|
|
91
|
-
validators = [PPTXSchemaValidator(unpacked_dir, original_file)]
|
|
92
|
-
|
|
93
|
-
if not validators:
|
|
94
|
-
return True, None
|
|
95
|
-
|
|
96
|
-
total_repairs = sum(v.repair() for v in validators)
|
|
97
|
-
if total_repairs:
|
|
98
|
-
output_lines.append(f"Auto-repaired {total_repairs} issue(s)")
|
|
99
|
-
|
|
100
|
-
success = all(v.validate() for v in validators)
|
|
101
|
-
|
|
102
|
-
if success:
|
|
103
|
-
output_lines.append("All validations PASSED!")
|
|
104
|
-
|
|
105
|
-
return success, "\n".join(output_lines) if output_lines else None
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def _condense_xml(xml_file: Path) -> None:
|
|
109
|
-
try:
|
|
110
|
-
with open(xml_file, encoding="utf-8") as f:
|
|
111
|
-
dom = defusedxml.minidom.parse(f)
|
|
112
|
-
|
|
113
|
-
for element in dom.getElementsByTagName("*"):
|
|
114
|
-
if element.tagName.endswith(":t"):
|
|
115
|
-
continue
|
|
116
|
-
|
|
117
|
-
for child in list(element.childNodes):
|
|
118
|
-
if (
|
|
119
|
-
child.nodeType == child.TEXT_NODE
|
|
120
|
-
and child.nodeValue
|
|
121
|
-
and child.nodeValue.strip() == ""
|
|
122
|
-
) or child.nodeType == child.COMMENT_NODE:
|
|
123
|
-
element.removeChild(child)
|
|
124
|
-
|
|
125
|
-
xml_file.write_bytes(dom.toxml(encoding="UTF-8"))
|
|
126
|
-
except Exception as e:
|
|
127
|
-
print(f"ERROR: Failed to parse {xml_file.name}: {e}", file=sys.stderr)
|
|
128
|
-
raise
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if __name__ == "__main__":
|
|
132
|
-
parser = argparse.ArgumentParser(
|
|
133
|
-
description="Pack a directory into a DOCX, PPTX, or XLSX file"
|
|
134
|
-
)
|
|
135
|
-
parser.add_argument("input_directory", help="Unpacked Office document directory")
|
|
136
|
-
parser.add_argument("output_file", help="Output Office file (.docx/.pptx/.xlsx)")
|
|
137
|
-
parser.add_argument(
|
|
138
|
-
"--original",
|
|
139
|
-
help="Original file for validation comparison",
|
|
140
|
-
)
|
|
141
|
-
parser.add_argument(
|
|
142
|
-
"--validate",
|
|
143
|
-
type=lambda x: x.lower() == "true",
|
|
144
|
-
default=True,
|
|
145
|
-
metavar="true|false",
|
|
146
|
-
help="Run validation with auto-repair (default: true)",
|
|
147
|
-
)
|
|
148
|
-
args = parser.parse_args()
|
|
149
|
-
|
|
150
|
-
_, message = pack(
|
|
151
|
-
args.input_directory,
|
|
152
|
-
args.output_file,
|
|
153
|
-
original_file=args.original,
|
|
154
|
-
validate=args.validate,
|
|
155
|
-
)
|
|
156
|
-
print(message)
|
|
157
|
-
|
|
158
|
-
if "Error" in message:
|
|
159
|
-
sys.exit(1)
|