@ycodium-ai/plugin-office 0.0.0-stage → 0.2.2804
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 +98 -2
- package/assets/check_office.py +279 -0
- package/dist/index.js +1575 -0
- package/locales/en.json +109 -0
- package/locales/zh-CN.json +109 -0
- package/package.json +89 -3
- package/skills/office-docx/SKILL.md +57 -0
- package/skills/office-pptx/SKILL.md +81 -0
- package/skills/office-xlsx/SKILL.md +74 -0
- package/ui/ui.js +1 -0
package/README.md
CHANGED
|
@@ -1,3 +1,99 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ycodium-ai/plugin-office
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lets agents create, check, and render Word, PowerPoint, and Excel files on this
|
|
4
|
+
Ycodium machine, and lets the app preview Office files. Nothing is downloaded
|
|
5
|
+
until you start an install from the plugin's settings card.
|
|
6
|
+
|
|
7
|
+
## What it installs
|
|
8
|
+
|
|
9
|
+
Each install runs from the settings card, downloads only what is pinned in
|
|
10
|
+
`src/lock.ts`, checks every file against its pinned checksum before unpacking
|
|
11
|
+
it, and discards it on a mismatch. Everything lands in the plugin data
|
|
12
|
+
directory under `runtime/`; system files and fonts are not changed.
|
|
13
|
+
|
|
14
|
+
- **Engine**: `@deepseek-ai/libreoffice-kit` 0.1.5 and its platform package from
|
|
15
|
+
npm (a LibreOffice build, MPL-2.0). Windows and macOS run the native engine;
|
|
16
|
+
Linux runs its WebAssembly build, which needs more memory and starts more
|
|
17
|
+
slowly. Windows needs the Microsoft Visual C++ 2015–2022 runtime for the
|
|
18
|
+
machine's architecture.
|
|
19
|
+
- **Python**: Python 3.12 from python-build-standalone with python-docx,
|
|
20
|
+
python-pptx, openpyxl, XlsxWriter, pandas, Pillow, and lxml, installed from
|
|
21
|
+
pinned wheels without contacting an index. Windows on ARM has no build.
|
|
22
|
+
- **Chinese fonts**: Noto Sans CJK SC and Noto Serif CJK SC, regular and bold
|
|
23
|
+
(SIL OFL). Only the engine uses them. Windows and macOS already have Chinese
|
|
24
|
+
fonts; on Linux without them, Chinese text renders as boxes.
|
|
25
|
+
|
|
26
|
+
**Check** reports whether the engine starts, the document libraries load, and
|
|
27
|
+
Chinese fonts are available. **Delete engine** removes all three.
|
|
28
|
+
|
|
29
|
+
Downloads follow the Ycodium server's proxy settings. The settings
|
|
30
|
+
card can point them elsewhere: an npm registry mirror for the engine, a prefix
|
|
31
|
+
put in front of GitHub addresses for Python and fonts, a PyPI files mirror for
|
|
32
|
+
the wheels, and a local folder holding files downloaded ahead of time. Files
|
|
33
|
+
from any source are checked against the same checksums.
|
|
34
|
+
|
|
35
|
+
## Tools and skills
|
|
36
|
+
|
|
37
|
+
The plugin gives agents five MCP tools. They run in the conversation's project
|
|
38
|
+
folder, and paths are relative to it.
|
|
39
|
+
|
|
40
|
+
| Tool | What it does |
|
|
41
|
+
| -------------------- | ---------------------------------------------------------------------------- |
|
|
42
|
+
| `office_python` | Tells the agent where the installed Python is, for its own document scripts. |
|
|
43
|
+
| `office_check` | Checks a document's structure, expected text, and slide or sheet count. |
|
|
44
|
+
| `office_render` | Renders pages, slides, or a sheet range to PNG files. |
|
|
45
|
+
| `office_convert` | Converts between formats, such as DOCX to PDF or XLSX to CSV. |
|
|
46
|
+
| `office_recalculate` | Recalculates a workbook's formulas and saves the values. |
|
|
47
|
+
|
|
48
|
+
The three skills `office-docx`, `office-pptx`, and `office-xlsx` tell agents how
|
|
49
|
+
to write each kind of file with these tools. The result of `office_render`
|
|
50
|
+
shows the rendered pages in the conversation.
|
|
51
|
+
|
|
52
|
+
## Preview
|
|
53
|
+
|
|
54
|
+
The app previews `.doc`, `.docx`, `.odt`, `.ppt`, `.pptx`, `.odp`, `.xls`,
|
|
55
|
+
`.xlsx`, and `.ods` files by asking this plugin to convert them to PDF. The
|
|
56
|
+
converted file is cached in the plugin's cache directory; changing the source
|
|
57
|
+
converts it again. Until the engine is installed, the preview says the plugin
|
|
58
|
+
is not set up yet and links to plugin settings.
|
|
59
|
+
|
|
60
|
+
## Install
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
ycodium plugin add @ycodium-ai/plugin-office
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The plugin ships enabled with Ycodium as `core.office`. Uninstalling it leaves
|
|
67
|
+
its data directory, including anything it downloaded; **Delete engine** first
|
|
68
|
+
if you want that space back.
|
|
69
|
+
|
|
70
|
+
## Requirements
|
|
71
|
+
|
|
72
|
+
A Ycodium server with plugin API version 3, including `process.spawn` for
|
|
73
|
+
`host:node`, `tar`, `fc-list`, and the installed Python (at most six processes
|
|
74
|
+
at once), `process.workspace`, and `workspace.read`. Supported engine
|
|
75
|
+
platforms: Windows x64/arm64, macOS x64/arm64, Linux x64/arm64.
|
|
76
|
+
|
|
77
|
+
## Developing
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
vp run --filter @ycodium-ai/plugin-office build
|
|
81
|
+
vp run --filter @ycodium-ai/plugin-office test
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The package builds its own code into `dist/index.js` and the result view into
|
|
85
|
+
`ui/ui.js`. The host supplies the shared `@ycodium-ai/plugin-api` and React at
|
|
86
|
+
runtime. Language catalogs live in `locales/`.
|
|
87
|
+
|
|
88
|
+
`test/checker.test.ts` runs the checker's Python tests and is skipped when no
|
|
89
|
+
Python 3 is found; point `YCODIUM_OFFICE_TEST_PYTHON` at one to run it.
|
|
90
|
+
|
|
91
|
+
To move to other versions, regenerate the whole of `src/lock.ts`; do not edit
|
|
92
|
+
single entries. Then run `scripts/remote-check.ts` on a real Linux and macOS
|
|
93
|
+
machine: it installs and runs everything outside Ycodium, and its header says how
|
|
94
|
+
to bundle it, which steps exist, and how to simulate a machine without Chinese
|
|
95
|
+
fonts.
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
UNLICENSED.
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Read-only OOXML checks and structural summaries; no rendering or formula evaluation.
|
|
3
|
+
|
|
4
|
+
Run with INPUT.docx, INPUT.pptx, or INPUT.xlsx. Optional --contains assertions
|
|
5
|
+
check extracted text; DOCX excludes comments, glossary text, and unreferenced parts or notes.
|
|
6
|
+
--count checks slides or sheets. JSON escapes non-ASCII
|
|
7
|
+
characters and goes to stdout and optionally --out. Exit 0 means the requested
|
|
8
|
+
structural checks passed, 1 means a document, assertion, or report write failed, and 2 means
|
|
9
|
+
invalid command-line arguments.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import json
|
|
16
|
+
import posixpath
|
|
17
|
+
import sys
|
|
18
|
+
import zipfile
|
|
19
|
+
import zlib
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from urllib.parse import unquote, urlsplit
|
|
22
|
+
from xml.etree import ElementTree as ET
|
|
23
|
+
|
|
24
|
+
W_NAMESPACES = (
|
|
25
|
+
"http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
|
26
|
+
"http://purl.oclc.org/ooxml/wordprocessingml/main",
|
|
27
|
+
)
|
|
28
|
+
A_NAMESPACES = (
|
|
29
|
+
"http://schemas.openxmlformats.org/drawingml/2006/main",
|
|
30
|
+
"http://purl.oclc.org/ooxml/drawingml/main",
|
|
31
|
+
)
|
|
32
|
+
P_NAMESPACES = (
|
|
33
|
+
"http://schemas.openxmlformats.org/presentationml/2006/main",
|
|
34
|
+
"http://purl.oclc.org/ooxml/presentationml/main",
|
|
35
|
+
)
|
|
36
|
+
S_NAMESPACES = (
|
|
37
|
+
"http://schemas.openxmlformats.org/spreadsheetml/2006/main",
|
|
38
|
+
"http://purl.oclc.org/ooxml/spreadsheetml/main",
|
|
39
|
+
)
|
|
40
|
+
R_NAMESPACES = (
|
|
41
|
+
"http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
|
42
|
+
"http://purl.oclc.org/ooxml/officeDocument/relationships",
|
|
43
|
+
)
|
|
44
|
+
MAIN_PARTS = {
|
|
45
|
+
".docx": ("word/document.xml", "wordprocessingml.document.main+xml"),
|
|
46
|
+
".pptx": ("ppt/presentation.xml", "presentationml.presentation.main+xml"),
|
|
47
|
+
".xlsx": ("xl/workbook.xml", "spreadsheetml.sheet.main+xml"),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def namespace(root: ET.Element, supported: tuple[str, ...], part: str) -> str:
|
|
52
|
+
"""Return the main XML namespace after checking its OOXML variant."""
|
|
53
|
+
uri = root.tag[1:].split("}", 1)[0] if root.tag.startswith("{") else ""
|
|
54
|
+
if uri not in supported:
|
|
55
|
+
raise ValueError(f"{part} uses unsupported XML namespace: {uri or '(none)'}")
|
|
56
|
+
return "{" + uri + "}"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def relationship_id(node: ET.Element, part: str) -> str:
|
|
60
|
+
"""Read an office-document relationship id from Transitional or Strict OOXML."""
|
|
61
|
+
for uri in R_NAMESPACES:
|
|
62
|
+
value = node.get("{" + uri + "}id")
|
|
63
|
+
if value is not None:
|
|
64
|
+
return value
|
|
65
|
+
raise ValueError(f"{part} has a reference without a relationship id")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def relationship_types(kind: str) -> set[str]:
|
|
69
|
+
"""Return the Transitional and Strict relationship type names for one role."""
|
|
70
|
+
return {f"{uri}/{kind}" for uri in R_NAMESPACES}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def iter_namespaces(root: ET.Element, namespaces: tuple[str, ...], local_name: str):
|
|
74
|
+
"""Iterate matching elements across Transitional and Strict namespaces."""
|
|
75
|
+
for uri in namespaces:
|
|
76
|
+
yield from root.iter("{" + uri + "}" + local_name)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def relationship_target(part: str, target: str) -> str:
|
|
80
|
+
"""Resolve a package relationship without fetching external resources."""
|
|
81
|
+
path = unquote(urlsplit(target).path)
|
|
82
|
+
return posixpath.normpath(path.lstrip("/") if path.startswith("/") else posixpath.join(posixpath.dirname(part), path))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def relationships(part: str, xml: dict[str, ET.Element], types: set[str] | None = None) -> dict[str, str]:
|
|
86
|
+
path = posixpath.join(posixpath.dirname(part), "_rels", posixpath.basename(part) + ".rels")
|
|
87
|
+
root = xml.get(path)
|
|
88
|
+
if root is None:
|
|
89
|
+
return {}
|
|
90
|
+
return {
|
|
91
|
+
rel.attrib["Id"]: relationship_target(part, rel.attrib["Target"])
|
|
92
|
+
for rel in root if rel.get("TargetMode") != "External" and (types is None or rel.get("Type") in types)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def related_xml(part: str, reference: str, links: dict[str, str], xml: dict[str, ET.Element]) -> ET.Element:
|
|
97
|
+
"""Read a related XML part with diagnostics naming its source and reference."""
|
|
98
|
+
if reference not in links:
|
|
99
|
+
raise ValueError(f"{part} references missing relationship: {reference}")
|
|
100
|
+
target = links[reference]
|
|
101
|
+
if target not in xml:
|
|
102
|
+
raise ValueError(f"{part} relationship {reference} targets a non-XML member: {target}")
|
|
103
|
+
return xml[target]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def inspect_docx(xml: dict[str, ET.Element]) -> tuple[dict, str]:
|
|
107
|
+
part = "word/document.xml"
|
|
108
|
+
root = xml[part]
|
|
109
|
+
w = namespace(root, W_NAMESPACES, part)
|
|
110
|
+
body = root.find(f"{w}body")
|
|
111
|
+
if body is None:
|
|
112
|
+
raise ValueError("word/document.xml has no document body")
|
|
113
|
+
tables = []
|
|
114
|
+
for table in body.iter(f"{w}tbl"):
|
|
115
|
+
grid = table.findall(f"{w}tblGrid/{w}gridCol")
|
|
116
|
+
rows = table.findall(f"{w}tr")
|
|
117
|
+
# Merged cells span logical grid columns; counting physical cells loses them.
|
|
118
|
+
columns = len(grid) if grid else max((sum(
|
|
119
|
+
int(cell.find(f"{w}tcPr/{w}gridSpan").get(f"{w}val", "1"))
|
|
120
|
+
if cell.find(f"{w}tcPr/{w}gridSpan") is not None else 1
|
|
121
|
+
for cell in row.findall(f"{w}tc")
|
|
122
|
+
) for row in rows), default=0)
|
|
123
|
+
tables.append({"rows": len(rows), "columns": columns})
|
|
124
|
+
sections = []
|
|
125
|
+
for section in body.iter(f"{w}sectPr"):
|
|
126
|
+
size = section.find(f"{w}pgSz")
|
|
127
|
+
margins = section.find(f"{w}pgMar")
|
|
128
|
+
sections.append({
|
|
129
|
+
"page_twips": {} if size is None else {key.removeprefix(w): value for key, value in size.attrib.items()},
|
|
130
|
+
"margins_twips": {} if margins is None else {key.removeprefix(w): value for key, value in margins.attrib.items()},
|
|
131
|
+
})
|
|
132
|
+
text_parts = [body]
|
|
133
|
+
for kind in ("header", "footer"):
|
|
134
|
+
links = relationships(part, xml, relationship_types(kind))
|
|
135
|
+
for section in body.iter(f"{w}sectPr"):
|
|
136
|
+
for reference in section.findall(f"{w}{kind}Reference"):
|
|
137
|
+
text_parts.append(related_xml(part, relationship_id(reference, part), links, xml))
|
|
138
|
+
for kind in ("footnote", "endnote"):
|
|
139
|
+
references = {node.attrib[f"{w}id"] for node in body.iter(f"{w}{kind}Reference")}
|
|
140
|
+
if not references:
|
|
141
|
+
continue
|
|
142
|
+
links = relationships(part, xml, relationship_types(f"{kind}s"))
|
|
143
|
+
for reference in links:
|
|
144
|
+
tree = related_xml(part, reference, links, xml)
|
|
145
|
+
text_parts.extend(note for note in tree.findall(f"{w}{kind}") if note.get(f"{w}id") in references)
|
|
146
|
+
text = "\n".join("".join(node.text or "" for node in paragraph.iter(f"{w}t")) for tree in text_parts
|
|
147
|
+
for paragraph in tree.iter(f"{w}p"))
|
|
148
|
+
return {"paragraphs": len(list(body.iter(f"{w}p"))), "tables": tables, "sections": sections}, text
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def inspect_pptx(xml: dict[str, ET.Element]) -> tuple[dict, str]:
|
|
152
|
+
part = "ppt/presentation.xml"
|
|
153
|
+
links = relationships(part, xml)
|
|
154
|
+
root = xml[part]
|
|
155
|
+
p = namespace(root, P_NAMESPACES, part)
|
|
156
|
+
slides = root.findall(f"{p}sldIdLst/{p}sldId")
|
|
157
|
+
texts = []
|
|
158
|
+
for slide in slides:
|
|
159
|
+
reference = relationship_id(slide, part)
|
|
160
|
+
tree = related_xml(part, reference, links, xml)
|
|
161
|
+
texts.append("\n".join("".join(node.text or "" for node in iter_namespaces(paragraph, A_NAMESPACES, "t"))
|
|
162
|
+
for paragraph in iter_namespaces(tree, A_NAMESPACES, "p")))
|
|
163
|
+
return {"slides": len(slides)}, "\n".join(texts)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def inspect_xlsx(xml: dict[str, ET.Element]) -> tuple[dict, str]:
|
|
167
|
+
part = "xl/workbook.xml"
|
|
168
|
+
links = relationships(part, xml)
|
|
169
|
+
root = xml[part]
|
|
170
|
+
s = namespace(root, S_NAMESPACES, part)
|
|
171
|
+
sheets = []
|
|
172
|
+
texts = []
|
|
173
|
+
shared = xml.get("xl/sharedStrings.xml")
|
|
174
|
+
shared_s = s if shared is None else namespace(shared, S_NAMESPACES, "xl/sharedStrings.xml")
|
|
175
|
+
shared_strings = [] if shared is None else [
|
|
176
|
+
"".join(node.text or "" for node in item.iter(f"{shared_s}t")) for item in shared.iter(f"{shared_s}si")
|
|
177
|
+
]
|
|
178
|
+
for sheet in root.findall(f"{s}sheets/{s}sheet"):
|
|
179
|
+
reference = relationship_id(sheet, part)
|
|
180
|
+
tree = related_xml(part, reference, links, xml)
|
|
181
|
+
sheet_s = namespace(tree, S_NAMESPACES, links[reference])
|
|
182
|
+
cells = list(tree.iter(f"{sheet_s}c"))
|
|
183
|
+
formulas = sum(cell.find(f"{sheet_s}f") is not None for cell in cells)
|
|
184
|
+
sheets.append({"name": sheet.attrib["name"], "cells": len(cells), "formulas": formulas})
|
|
185
|
+
for cell in cells:
|
|
186
|
+
if cell.get("t") == "s":
|
|
187
|
+
value = cell.findtext(f"{sheet_s}v", "")
|
|
188
|
+
location = f"{links[reference]} cell {cell.get('r', '(no reference)')}"
|
|
189
|
+
try:
|
|
190
|
+
index = int(value)
|
|
191
|
+
except ValueError as error:
|
|
192
|
+
raise ValueError(f"{location}: invalid shared string index {value!r}") from error
|
|
193
|
+
if not 0 <= index < len(shared_strings):
|
|
194
|
+
raise ValueError(f"{location}: shared string index out of range: {index}")
|
|
195
|
+
texts.append(shared_strings[index])
|
|
196
|
+
texts.extend("".join(node.text or "" for node in cell.iter(f"{sheet_s}t")) for cell in cells)
|
|
197
|
+
texts.extend(cell.findtext(f"{sheet_s}v", "") for cell in cells if cell.get("t") == "str")
|
|
198
|
+
texts.append(sheet.attrib["name"])
|
|
199
|
+
return {"sheets": sheets, "formulas_evaluated": False}, "\n".join(texts)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def inspect(path: Path) -> tuple[dict, str]:
|
|
203
|
+
"""Validate package members and relationships before inspecting the main part."""
|
|
204
|
+
main, content_type = MAIN_PARTS[path.suffix.lower()]
|
|
205
|
+
with zipfile.ZipFile(path) as archive:
|
|
206
|
+
members = archive.namelist()
|
|
207
|
+
if len(members) != len(set(members)):
|
|
208
|
+
raise ValueError("ZIP contains duplicate member names")
|
|
209
|
+
corrupt = archive.testzip()
|
|
210
|
+
if corrupt is not None:
|
|
211
|
+
raise ValueError(f"ZIP member failed its CRC check: {corrupt}")
|
|
212
|
+
xml = {name: ET.fromstring(archive.read(name)) for name in members
|
|
213
|
+
if name.endswith((".xml", ".rels"))}
|
|
214
|
+
if main not in xml:
|
|
215
|
+
raise ValueError(f"missing main part: {main}")
|
|
216
|
+
types = xml.get("[Content_Types].xml")
|
|
217
|
+
if types is None or not any(node.get("PartName") == "/" + main
|
|
218
|
+
and node.get("ContentType", "").endswith(content_type) for node in types):
|
|
219
|
+
raise ValueError(f"[Content_Types].xml does not declare {main} as {path.suffix.lower()}")
|
|
220
|
+
for name, tree in xml.items():
|
|
221
|
+
if not name.endswith(".rels"):
|
|
222
|
+
continue
|
|
223
|
+
source = "" if name == "_rels/.rels" else posixpath.join(posixpath.dirname(posixpath.dirname(name)), posixpath.basename(name)[:-5])
|
|
224
|
+
for rel in tree:
|
|
225
|
+
if rel.get("TargetMode") == "External":
|
|
226
|
+
continue
|
|
227
|
+
target = relationship_target(source, rel.attrib["Target"])
|
|
228
|
+
if target not in members:
|
|
229
|
+
raise ValueError(f"{name} references missing package member: {target}")
|
|
230
|
+
if path.suffix.lower() == ".docx":
|
|
231
|
+
return inspect_docx(xml)
|
|
232
|
+
if path.suffix.lower() == ".pptx":
|
|
233
|
+
return inspect_pptx(xml)
|
|
234
|
+
return inspect_xlsx(xml)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def main() -> int:
|
|
238
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
239
|
+
parser.add_argument("input", type=Path)
|
|
240
|
+
parser.add_argument("--out", type=Path)
|
|
241
|
+
parser.add_argument("--contains", action="append", default=[], metavar="TEXT")
|
|
242
|
+
parser.add_argument("--count", type=int, help="expected slide or sheet count")
|
|
243
|
+
args = parser.parse_args()
|
|
244
|
+
if args.input.suffix.lower() not in MAIN_PARTS:
|
|
245
|
+
parser.error("input must be .docx, .pptx, or .xlsx; converting the filename does not convert its contents")
|
|
246
|
+
if args.count is not None and (args.count < 0 or args.input.suffix.lower() == ".docx"):
|
|
247
|
+
parser.error("--count must be non-negative and applies only to slides or sheets")
|
|
248
|
+
if args.out is not None and args.out.resolve() == args.input.resolve():
|
|
249
|
+
parser.error("--out must differ from the input document")
|
|
250
|
+
checks = []
|
|
251
|
+
summary = {}
|
|
252
|
+
try:
|
|
253
|
+
summary, text = inspect(args.input)
|
|
254
|
+
checks.append({"id": "package", "status": "pass"})
|
|
255
|
+
for required in args.contains:
|
|
256
|
+
checks.append({"id": "contains", "status": "pass" if required in text else "fail", "text": required})
|
|
257
|
+
if args.count is not None:
|
|
258
|
+
actual = summary.get("slides", len(summary.get("sheets", [])))
|
|
259
|
+
checks.append({"id": "count", "status": "pass" if actual == args.count else "fail", "expected": args.count, "actual": actual})
|
|
260
|
+
except (OSError, ValueError, KeyError, RuntimeError, ET.ParseError, zipfile.BadZipFile, zlib.error) as error:
|
|
261
|
+
checks.append({"id": "package", "status": "fail", "detail": str(error)})
|
|
262
|
+
failed = any(check["status"] == "fail" for check in checks)
|
|
263
|
+
report = {"format": args.input.suffix.lower()[1:], "verdict": "fail" if failed else "pass", "checks": checks, "summary": summary}
|
|
264
|
+
output = json.dumps(report, ensure_ascii=True, indent=2) + "\n"
|
|
265
|
+
if args.out is not None:
|
|
266
|
+
try:
|
|
267
|
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
|
268
|
+
args.out.write_text(output, encoding="utf-8")
|
|
269
|
+
except OSError as error:
|
|
270
|
+
failed = True
|
|
271
|
+
report["verdict"] = "fail"
|
|
272
|
+
checks.append({"id": "output", "status": "fail", "detail": str(error)})
|
|
273
|
+
output = json.dumps(report, ensure_ascii=True, indent=2) + "\n"
|
|
274
|
+
sys.stdout.write(output)
|
|
275
|
+
return 1 if failed else 0
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
if __name__ == "__main__":
|
|
279
|
+
sys.exit(main())
|