Skip to content
Back to search

SoftwareCopyright-Skill

中国软件著作权申请材料 生成器 Skills,本 Skills 通过阅读本地项目,自动生成全套 .docx 软著申请材料,全开源,无须再付费购买任何软著申请服务

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/fokkyp--softwarecopyright-skill/badge.svg)](/listings/fokkyp--softwarecopyright-skill)

HTML

<a href="/listings/fokkyp--softwarecopyright-skill"><img src="/api/listings/fokkyp--softwarecopyright-skill/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/plugin.json · Manifest · 13 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. {
  2. "name": "software-copyright-materials",
  3. "description": "从真实项目生成中国软件著作权申请资料(Word/TXT)。支持项目分析、代码材料抽取、申请表信息生成和操作手册撰写,输出符合软著申报要求的正式材料。",
  4. "version": "2.2.0",
  5. "author": {
  6. "name": "Fokkyp",
  7. "url": "https://github.com/Fokkyp"
  8. },
  9. "homepage": "https://github.com/Fokkyp/SoftwareCopyright-Skill",
  10. "repository": "https://github.com/Fokkyp/SoftwareCopyright-Skill",
  11. "license": "MIT",
  12. "keywords": ["software-copyright", "chinese-copyright", "docx", "软著", "著作权"]
  13. }
README.md · README · 261 lines · 2 findings marked

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Software Copyright Materials Skill
  2. 这是一个用于生成中文软件著作权申请资料的通用 Skill 仓库,适用于支持本地 Skill 目录机制的 coding agent 软件。
  3. 项目地址:https://github.com/Fokkyp/SoftwareCopyright-Skill
  4. 真正的 Skill 位于:
  5. ```text
  6. software-copyright-materials/
  7. ```
  8. 安装时不要把仓库根目录当作普通单个 skill 复制。只需将 `software-copyright-materials/` 这个实际 skill 目录放置到你的 coding agent 软件要求的 skill 目录下,即可加载使用。
  9. ## 功能概览
  10. > **本项目完全免费。请不要相信任何使用本项目包装出来的付费服务。**
  11. 软件著作权申请本身不神秘,真正麻烦的是整理材料:申请表字段要写对,操作手册要像样,代码材料要按规则截取,软件名称、版本号、页数还要保持一致。很多开发者最后会把这件事交给付费代办或资料整理服务,花钱买的往往也只是这些文档整理工作。
  12. 这个 skill 的目标很直接:让开发者不用再为整理软著材料额外付费,也不用把项目代码和产品细节交给外部商家来回沟通。把真实项目交给支持该 skill 的代码助手,它会按流程引导你确认关键信息,并在本地生成一整套可检查、可修改、可提交前再导出的软著申请资料。
  13. - **自己生成整套资料**:从项目分析、业务理解、申请表信息、操作手册到代码材料,一套流程跑完,不再依赖外部代办整理文档。
  14. - **从真实源码抽取代码**:代码材料只来自开发者已有项目,禁止 AI 编造源码,适合对材料真实性敏感的开发者。
  15. - **自动处理前 30 页 / 后 30 页规则**:源码足够时按常见鉴别材料要求生成前 30 页和后 30 页;不足 60 页时按规则生成全部代码材料。
  16. - **操作手册不套模板**:先理解项目业务、页面和功能,再写面向审核员的操作说明,避免只有空泛功能列表。
  17. - **申请表字段集中整理**:软件名称、版本号、著作权人、开发环境、运行环境、源程序量、功能说明等字段统一生成到 `申请表信息.txt`,官网填报时可以对照复制。
  18. - **关键节点都让你确认**:业务口径、申请表字段、代码选择、截图方式、最终 Markdown 草稿都会停下来让开发者确认,减少材料写偏的风险。
  19. - **Word/TXT 一键输出**:确认后生成操作手册 DOCX、代码材料 DOCX 和申请表 TXT,文件统一放在 `软件著作权申请资料/正式资料/`。
  20. - **本地生成,资料可控**:默认在当前项目目录生成材料,代码、文档和草稿都留在本地,方便开发者自行审阅、修改和归档。
  21. - **提供完整 demo**:仓库内提供 [`生成demo/软件著作权申请资料/`](生成demo/软件著作权申请资料/),可以直接点击查看生成后的草稿、正式资料和填报辅助文件。
  22. ## 演示截图
  23. | 生成流程 | 生成流程 |
  24. |---------|---------|
  25. | ![软著材料生成演示 1](docs/screenshots/demo-1.png) | ![软著材料生成演示 2](docs/screenshots/demo-2.png) |
  26. | ![软著材料生成演示 3](docs/screenshots/demo-3.png) | ![软著材料生成演示 4](docs/screenshots/demo-4.png) |
  27. | ![软著材料生成演示 5](docs/screenshots/demo-5.png) | ![软著材料生成演示 6](docs/screenshots/demo-6.png) |
  28. ## 目录结构
  29. ```text
  30. .
  31. ├── docs/
  32. │ └── screenshots/
  33. │ ├── demo-1.png
  34. │ ├── demo-2.png
  35. │ ├── demo-3.png
  36. │ ├── demo-4.png
  37. │ ├── demo-5.png
  38. │ ├── demo-6.png
  39. │ └── 著作权申请表.png
  40. ├── software-copyright-materials/
  41. │ ├── SKILL.md
  42. │ ├── agents/
  43. │ ├── references/
  44. │ └── scripts/
  45. └── 生成demo/
  46. └── 软件著作权申请资料/
  47. ├── 草稿/
  48. └── 正式资料/
  49. ├── 申请表信息.txt
  50. ├── 软件名称_操作手册.docx
  51. ├── 软件名称-代码(前30页).docx
  52. └── 软件名称-代码(后30页).docx
  53. ```
  54. ## 下载并安装
  55. 先获取本仓库。会用 Git 的用户执行:
  56. ```bash
  57. git clone https://github.com/Fokkyp/SoftwareCopyright-Skill.git
  58. cd SoftwareCopyright-Skill
  59. ```
  60. 不会用 Git 的用户可以在 GitHub 页面点击 `Code` -> `Download ZIP`,解压后进入仓库目录。目录中应能看到实际 skill 目录:
  61. ```text
  62. software-copyright-materials/
  63. ```
  64. 按照你的 coding agent 软件文档,找到它要求的 skill 目录,然后复制实际 skill 目录即可:
  65. ```bash
  66. AGENT_SKILLS_DIR="<你的 coding agent 软件要求的 skill 目录>"
  67. mkdir -p "$AGENT_SKILLS_DIR"
  68. cp -R software-copyright-materials "$AGENT_SKILLS_DIR/"
  69. ```
  70. 如果你的 coding agent 支持项目级 skill,也可以把 `software-copyright-materials/` 放到该项目要求的本地 skill 目录中:
  71. ```bash
  72. PROJECT_SKILLS_DIR="<你的项目级 skill 目录>"
  73. mkdir -p "$PROJECT_SKILLS_DIR"
  74. cp -R software-copyright-materials "$PROJECT_SKILLS_DIR/"
  75. ```
  76. 复制完成后,按你的 coding agent 软件要求重启会话、刷新 skill 列表或重新加载配置。
  77. ## 运行要求和环境校验
  78. ### 必需环境
  79. - **支持 Skill 的 coding agent 软件**:能够从本地 skill 目录加载 `software-copyright-materials/`。
  80. - **Python 3.10+**:用于项目分析、草稿生成、代码抽取、门禁和 OfficeCLI 命令编排。可以使用 coding agent 自带的 Python 运行时,无需另外安装 `python-docx`。
  81. - **全局安装的 OfficeCLI 1.0.151**:正式 Word 统一由 OfficeCLI 生成、校验和预览。仓库不复制 OfficeCLI 二进制,也不再使用 LibreOffice、Pandoc、内置 DOCX skill、.NET 工具包或项目内便携版兜底。
  82. - 生成完成后会继续通过 OfficeCLI 统一 DOCX 主题字体为宋体和 Times New Roman,并重新读取主题校验,避免 WPS 因默认的等线、Calibri、Calibri Light 提示缺失字体。
  83. - **可读取的项目源码**:代码材料必须从真实项目中抽取,所以需要在代码助手中打开或指定你的项目目录。
  84. Windows PowerShell 使用 OfficeCLI 官方全局安装命令:
  85. ```powershell
  86. irm https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.ps1 | iex
  87. ```
  88. macOS / Linux 使用官方安装命令:
  89. ```bash
  90. curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
    • Note: Pipes a downloaded script directly into a shell (curl | sh / wget | bash)
    • Line 121 on GitHub
  91. ```
  92. 安装脚本会把 OfficeCLI 放入全局命令目录并更新 PATH。安装后重新启动 coding agent,让新进程读取更新后的 PATH,然后确认固定版本:
  93. ```bash
  94. officecli --version
  95. # 预期输出:1.0.151
  96. ```
  97. 当前 skill 固定验证 [OfficeCLI v1.0.151](https://github.com/iOfficeAI/OfficeCLI/releases/tag/v1.0.151)。运行时只使用 PATH 中的全局 `officecli`,不使用 `OFFICECLI_PATH`、`--officecli` 或项目内 `工具/officecli.exe`。生成脚本会禁用 OfficeCLI 自动更新,以避免同一份材料因工具版本漂移产生不同结果。
  98. ### 可选能力
  99. - **Microsoft Word(Windows)**:代码段落连续写入 DOCX,由 Word 像普通文档一样根据页面空间自动换页;OfficeCLI 可调用 Word 取得最终真实页数。没有 Word 时仍可生成、做 OpenXML 校验和 OfficeCLI HTML 预览,但提交前必须在 Word 或 WPS 中人工复核分页。本项目统一使用 OfficeCLI。
  100. - **Node.js 18+、npm 和 `@playwright/cli@0.1.20`**:仅在选择 Playwright CLI 自动截图时需要。用户确认后可执行 `npm install -g @playwright/cli@0.1.20`;不会写入被分析项目的 `package.json`。
  101. - **Chrome**:Playwright CLI 自动截图优先使用本机已安装的 Chrome。只有 Chrome 不可用且用户同意时,才安装额外浏览器运行时。
  102. - **用户自行截图**:不使用自动截图时,可以把 PNG/JPG/JPEG/WebP 图片放到 `软件著作权申请资料/用户截图/`;也可以明确选择暂不截图,操作手册会保留可见的截图预留位置。
  103. 自动截图不依赖 Chrome DevTools MCP、桌面控制工具或项目内 Playwright 依赖。Skill 会先从系统 PATH 查找 `playwright-cli`;找不到时再读取 `npm prefix -g` 的标准全局可执行目录,并直接调用解析出的绝对路径。因此 npm 全局安装成功后无需为了 Playwright CLI 重启 coding agent,也无需手动修改 PATH。
  104. ### 使用过程中会自动检查吗?
  105. 会,并且分为启动检查和截图检查两部分。
  106. 每次开始生成资料时,skill 会先运行启动环境检查,并在当前目录生成:
  107. ```text
  108. 软件著作权申请资料/环境检查.md
  109. 软件著作权申请资料/环境检查.json
  110. ```
  111. 环境检查会告诉你:
  112. - 当前 Python 是否满足 3.10+。
  113. - Markdown 草稿、TXT、OfficeCLI DOCX、OpenXML 校验和预览是否可用。
  114. - 当前 OfficeCLI 路径和版本是否为固定验证版本 `1.0.151`。
  115. - OfficeCLI 是已就绪、尚未全局安装,还是安装后需要重启 coding agent 才能刷新 PATH。
  116. - 当前平台是否可能使用 Word 原生页数校验。
  117. - 当前会把材料生成到哪里。
  118. 如果 OfficeCLI 缺失或版本不匹配,代码助手会停下来让你选择:
  119. 1. 使用官方安装脚本全局安装,安装后重启 coding agent 并重新检查。
  120. 2. 切换到固定验证版本 `1.0.151`。
  121. 3. 明确承担兼容性风险并使用其他版本(生成时必须显式传入 `--allow-untested-officecli`)。
  122. 没有可用 OfficeCLI 时不会伪装生成 DOCX,也不会自动回退到另一套写入实现。它不会在你不确认的情况下静默安装依赖。
  123. 进入截图阶段后,skill 只提供 Playwright CLI 自动截图和用户自行截图两种正常方式;用户也可以明确选择暂不截图。选择自动截图时会运行:
  124. ```bash
  125. <PYTHON> "<SKILL_DIR>/scripts/check_playwright_cli.py" \
  126. --out 软件著作权申请资料/截图工具检查.json
  127. ```
  128. 这一步会同时检查 PATH 与 npm 全局可执行目录,并实际执行 `--version`。只有确认版本为 `0.1.20` 后才会启动项目开发服务和浏览器;开发服务在后台运行并读取真实监听地址,不会以前台长期命令阻塞任务。所有截图必须实际保存到 `软件著作权申请资料/截图原始/`,随后生成 `截图/截图清单.json` 供 OfficeCLI 插入操作手册。
  129. ## 基本使用
  130. 安装或加载完成后,在代码助手中打开需要生成软著资料的项目,然后直接说:
  131. ```text
  132. 使用 software-copyright-materials 生成当前项目的软件著作权申请资料
  133. ```
  134. 如果你的 coding agent 软件支持手动调用 skill,请按该软件的调用格式选择 `software-copyright-materials`。
  135. 代码助手会按流程引导填写信息、确认草稿,并在当前项目目录下生成 `软件著作权申请资料/`。
  136. ## 开源协议
  137. Copyright (c) 2026 Software Copyright Materials contributors
  138. 本项目采用 [GNU Affero General Public License v3.0(AGPL-3.0-only)](LICENSE) 开源。
  139. 商业使用须遵守 AGPLv3 的全部适用条款。对于违反本协议的商业使用行为,本人保留依法追究法律责任、要求停止侵权及主张损害赔偿的权利。本声明不限制 AGPLv3 授予的合法商业使用权利。
  140. 本项目允许依照 AGPLv3 进行商业使用。如需获得不受 AGPLv3 开源义务约束的商业授权,请邮件联系本人。
  141. 使用者仍需自行核对生成材料是否符合实际项目和官网当前要求。
  142. ## 代码材料说明
  143. 依据软件著作权申请材料要求,代码鉴别材料应来自申请软件本身。本 skill 不通过 AI 生成项目代码,也不编造不存在的源码内容。
  144. 本 skill 的作用是帮助开发者从已有项目中理解业务、选择代码文件、提取前后代码材料,并整理为便于编辑和提交的文档格式。开发者应在提交前自行核对代码材料是否来自真实项目、软件名称和版本号是否与申请表保持一致。
  145. 源码候选不依赖固定的语言扩展名列表。脚本会通过文件内容识别可读源码并排除明确的文档、配置、二进制和生成文件,因此 Godot、GameMaker、C/C++、Dart 以及后续出现的新脚本扩展名无需逐个加入白名单。项目中的 Markdown、TXT、DOCX、PDF、ODT、DOC、WPS 及带有设计/需求/架构线索的文档也会进入业务证据;无法自动提取正文的二进制文档仍会登记路径,供模型进一步读取。
  146. ## 官网填报和提交
  147. 官方入口:
  148. - 中国版权保护中心:https://www.ccopyright.com.cn/
  149. - 著作权登记系统:https://register.ccopyright.com.cn/login.html
  150. - 法规依据:《计算机软件著作权登记办法》:https://www.gov.cn/zhengce/2002-02/20/content_5724627.htm
  151. 官方页面可能会调整,实际填报时以官网当前页面为准。
  152. ### 著作权申请表填写示例
  153. 著作权申请表按照以下图片填写。
  154. ![著作权申请表填写示例](docs/screenshots/著作权申请表.png)
  155. ### 申请流程
  156. 1. 打开中国版权保护中心官网,进入著作权登记系统。
  157. 2. 注册或登录账号,并按页面提示完成实名认证。
  158. 3. 进入软件著作权相关业务,选择计算机软件著作权登记申请。
  159. 4. 在线填写申请表。可以打开本工具生成的 `正式资料/申请表信息.txt`,把软件名称、版本号、开发完成日期、开发环境、运行环境、功能说明等内容复制到官网对应字段。
  160. 5. 上传申请材料。根据官网要求上传 PDF 格式文件和其他证明材料。
  161. 6. 核对信息无误后提交申请,并按官网提示查看受理、补正或登记结果。
  162. ### 生成文件怎么用
  163. `申请表信息.txt` 是填报辅助文件,用来帮助开发者在官网填写申请表,不是直接上传的申请材料。
  164. `docx` 文件是本地编辑稿,方便开发者在 Word、WPS 或 Pages 中继续修改。提交官网前,请将需要上传的 `docx` 文件导出或另存为 PDF,再按官网要求上传。
  165. 实际文件名会包含软件名称。通常需要转换为 PDF 的文件包括:
  166. - `操作手册.docx`
  167. - `代码(前30页).docx`
  168. - `代码(后30页).docx`
  169. - 不足 60 页时生成的全部代码材料
  170. 申请人身份证明、权属证明、委托材料等其他文件,请按官网页面要求另行准备并上传。
  171. ## Star History
  172. <a href="https://www.star-history.com/?repos=fokkyp%2Fsoftwarecopyright-skill&type=date&legend=bottom-right">
  173. <picture>
  174. <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=fokkyp/softwarecopyright-skill&type=date&theme=dark&legend=bottom-right" />
  175. <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=fokkyp/softwarecopyright-skill&type=date&legend=bottom-right" />
  176. <img alt="Star History Chart" src="https://api.star-history.com/chart?repos=fokkyp/softwarecopyright-skill&type=date&legend=bottom-right" />
  177. </picture>
  178. </a>
  179. <p align="left"><sub>友情连接:<a href="https://linux.do/">Linux Do 社区</a> · <a href="https://www.v2ex.com/">V2EX</a></sub></p>
software-copyright-materials/scripts/officecli_backend.py · Bundled script · 249 lines · 1 finding marked
  1. #!/usr/bin/env python3
  2. """Deterministic OfficeCLI adapter used by the final DOCX builder."""
  3. from __future__ import annotations
  4. import json
  5. import os
  6. import re
  7. import shutil
  8. import subprocess
  9. import tempfile
  10. import time
  11. from pathlib import Path
  12. from typing import Any
  13. TESTED_OFFICECLI_VERSION = "1.0.151"
  14. OFFICECLI_DOWNLOAD_URL = "https://github.com/iOfficeAI/OfficeCLI/releases/tag/v1.0.151"
  15. OFFICECLI_INSTALL_URL = "https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.ps1"
  16. OFFICECLI_INSTALL_COMMAND = f"irm {OFFICECLI_INSTALL_URL} | iex"
  17. class OfficeCliError(RuntimeError):
  18. """Raised when OfficeCLI is missing or reports a failed operation."""
  19. def resolve_officecli() -> Path | None:
  20. """Resolve a globally installed OfficeCLI from the current process PATH."""
  21. for name in ("officecli", "officecli.exe"):
  22. found = shutil.which(name)
  23. if found:
  24. path = Path(found)
  25. if path.is_file():
  26. return path.resolve()
  27. return None
  28. def pending_windows_officecli_install() -> Path | None:
  29. """Return the official Windows install path when PATH has not refreshed yet."""
  30. local_app_data = os.environ.get("LOCALAPPDATA")
  31. if os.name != "nt" or not local_app_data:
  32. return None
  33. path = Path(local_app_data) / "OfficeCLI" / "officecli.exe"
  34. return path.resolve() if path.is_file() else None
  35. def officecli_environment() -> dict[str, str]:
  36. """Return a deterministic environment for non-interactive CLI execution."""
  37. env = os.environ.copy()
  38. env["OFFICECLI_SKIP_UPDATE"] = "1"
  39. # Background residents can retain file handles and stdout pipes on Windows.
  40. # A one-shot process is slower but predictable for document generation.
  41. env["OFFICECLI_NO_AUTO_RESIDENT"] = "1"
  42. return env
  43. def _parse_json_output(output: str) -> dict[str, Any]:
  44. text = output.strip()
  45. if not text:
  46. return {}
  47. decoder = json.JSONDecoder()
  48. for match in re.finditer(r"\{", text):
  49. try:
  50. value, _ = decoder.raw_decode(text[match.start() :])
  51. except json.JSONDecodeError:
  52. continue
  53. if isinstance(value, dict):
  54. return value
  55. return {"raw": text}
  56. class OfficeCli:
  57. def __init__(self, require_tested_version: bool = True) -> None:
  58. resolved = resolve_officecli()
  59. if resolved is None:
  60. raise OfficeCliError(
  61. "当前 Codex 进程无法调用全局 officecli。请按官方方式全局安装 OfficeCLI,"
  62. "然后重启 Codex 再继续:"
  63. f"{OFFICECLI_INSTALL_COMMAND}"
  64. )
  65. self.executable = resolved
  66. self.version = self._read_version()
  67. if require_tested_version and self.version != TESTED_OFFICECLI_VERSION:
  68. raise OfficeCliError(
  69. f"OfficeCLI 版本不匹配:检测到 {self.version},当前 skill 只验证过 "
  70. f"{TESTED_OFFICECLI_VERSION}。请安装固定版本,或显式使用 --allow-untested-officecli。"
  71. )
  72. def _run(
  73. self,
  74. args: list[str],
  75. *,
  76. timeout: int = 120,
  77. expect_json: bool = True,
  78. check: bool = True,
  79. ) -> dict[str, Any]:
  80. command = [str(self.executable), *args]
  81. completed = subprocess.run(
  82. command,
  83. text=True,
  84. encoding="utf-8",
  85. errors="replace",
  86. capture_output=True,
  87. timeout=timeout,
  88. env=officecli_environment(),
  89. )
  90. combined = "\n".join(part for part in (completed.stdout, completed.stderr) if part).strip()
  91. payload = _parse_json_output(combined) if expect_json else {"raw": combined}
  92. failed_payload = isinstance(payload, dict) and payload.get("success") is False
  93. if check and (completed.returncode != 0 or failed_payload):
  94. detail = payload.get("error") if isinstance(payload, dict) else None
  95. raise OfficeCliError(f"OfficeCLI 命令失败:{' '.join(args[:3])}\n{detail or combined}")
  96. payload.setdefault("returncode", completed.returncode)
  97. return payload
  98. def _read_version(self) -> str:
  99. result = self._run(["--version"], expect_json=False)
  100. raw = str(result.get("raw", "")).strip()
  101. match = re.search(r"\d+\.\d+\.\d+", raw)
  102. return match.group(0) if match else raw or "unknown"
  103. def _run_batch_file(self, output: Path, batch_path: Path, command_count: int) -> dict[str, Any]:
  104. args = ["batch", str(output), "--input", str(batch_path), "--stop-on-error", "--json"]
  105. timeout = max(120, min(900, 60 + command_count // 8))
  106. last_error: OfficeCliError | None = None
  107. for delay in (0.0, 0.3, 1.0):
  108. if delay:
  109. time.sleep(delay)
  110. try:
  111. return self._run(args, timeout=timeout)
  112. except OfficeCliError as exc:
  113. last_error = exc
  114. if "io_error" not in str(exc):
  115. raise
  116. assert last_error is not None
  117. raise last_error
  118. def create(self, output: Path, commands: list[dict[str, Any]], *, locale: str = "zh-CN") -> dict[str, Any]:
  119. output = output.resolve()
  120. output.parent.mkdir(parents=True, exist_ok=True)
  121. self._run(["create", str(output), "--force", "--locale", locale, "--json"])
  122. batch_path: Path | None = None
  123. try:
  124. with tempfile.NamedTemporaryFile(
  125. mode="w",
  126. suffix=".officecli-batch.json",
  127. prefix=f".{output.stem}-",
  128. dir=output.parent,
  129. encoding="utf-8",
  130. delete=False,
  131. ) as handle:
  132. json.dump(commands, handle, ensure_ascii=False, indent=2)
  133. batch_path = Path(handle.name)
  134. return self._run_batch_file(output, batch_path, len(commands))
  135. finally:
  136. if batch_path:
  137. batch_path.unlink(missing_ok=True)
  138. def run_batch(self, output: Path, commands: list[dict[str, Any]]) -> dict[str, Any]:
  139. if not commands:
  140. return {"success": True, "data": {"summary": {"total": 0, "failed": 0}}}
  141. batch_path: Path | None = None
  142. try:
  143. with tempfile.NamedTemporaryFile(
  144. mode="w",
  145. suffix=".officecli-batch.json",
  146. prefix=f".{output.stem}-",
  147. dir=output.parent,
  148. encoding="utf-8",
  149. delete=False,
  150. ) as handle:
  151. json.dump(commands, handle, ensure_ascii=False, indent=2)
  152. batch_path = Path(handle.name)
  153. return self._run_batch_file(output.resolve(), batch_path, len(commands))
  154. finally:
  155. if batch_path:
  156. batch_path.unlink(missing_ok=True)
  157. def get(self, output: Path, path: str) -> dict[str, Any]:
  158. return self._run(["get", str(output.resolve()), path, "--json"])
  159. def validate(self, output: Path) -> dict[str, Any]:
  160. return self._run(["validate", str(output.resolve()), "--json"], timeout=180)
  161. def raw(self, output: Path, part: str) -> dict[str, Any]:
  162. return self._run(["raw", str(output.resolve()), part, "--json"], timeout=180)
  163. def raw_set(self, output: Path, part: str, xpath: str, action: str, xml: str) -> dict[str, Any]:
  164. return self._run(
  165. [
  166. "raw-set", str(output.resolve()), part,
  167. "--xpath", xpath, "--action", action, "--xml", xml, "--json",
  168. ],
  169. timeout=180,
  170. )
  171. def issues(self, output: Path) -> dict[str, Any]:
  172. return self._run(["view", str(output.resolve()), "issues", "--json"], timeout=180)
  173. def stats(self, output: Path, *, native_page_count: bool = False) -> dict[str, Any]:
  174. # OfficeCLI only repaginates through Word on Windows; elsewhere --page-count
  175. # silently returns its own estimate, which must not be treated as Word's count.
  176. native_page_count = native_page_count and os.name == "nt"
  177. args = ["view", str(output.resolve()), "stats"]
  178. if native_page_count:
  179. args.append("--page-count")
  180. args.append("--json")
  181. return self._run(args, timeout=300, check=not native_page_count)
  182. def screenshot(self, output: Path, target: Path, *, render: str = "auto") -> dict[str, Any]:
  183. target.parent.mkdir(parents=True, exist_ok=True)
  184. return self._run(
  185. [
  186. "view",
  187. str(output.resolve()),
  188. "screenshot",
  189. "--grid",
  190. "auto",
  191. "--render",
  192. render,
  193. "--out",
  194. str(target.resolve()),
  195. "--json",
  196. ],
  197. timeout=300,
  198. expect_json=False,
  199. )
  200. def json_data(payload: dict[str, Any]) -> dict[str, Any]:
  201. value = payload.get("data") if isinstance(payload, dict) else None
  202. return value if isinstance(value, dict) else {}
  203. def structural_error_count(payload: dict[str, Any]) -> int:
  204. value = json_data(payload).get("count", 0)
  205. try:
  206. return int(value)
  207. except (TypeError, ValueError):
  208. return 0
  209. def issue_count(payload: dict[str, Any]) -> int:
  210. value = json_data(payload).get("count", 0)
  211. try:
  212. return int(value)
  213. except (TypeError, ValueError):
  214. return 0

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.