@hfyjq/crannia 1.0.0 → 1.1.0
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/LICENSE +201 -201
- package/NOTICE +45 -45
- package/THIRD-PARTY-FRONTEND.md +5266 -5266
- package/THIRD-PARTY-PYTHON.md +162 -153
- package/THIRD-PARTY.md +316 -316
- package/apps/desktop/quotes.txt +56 -56
- package/bus/core.py +671 -671
- package/bus/loaders/channel_loader.py +64 -64
- package/bus/loaders/skill_md.py +676 -676
- package/bus/skill_state.py +124 -124
- package/channels/cli_channel/manifest.yaml +5 -5
- package/channels/dingtalk_channel/manifest.yaml +12 -12
- package/channels/feishu_channel/manifest.yaml +12 -12
- package/channels/qq_bot_channel/__init__.py +1 -1
- package/channels/qq_bot_channel/handler.py +881 -881
- package/channels/qq_bot_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/__init__.py +1 -1
- package/channels/telegram_channel/handler.py +813 -813
- package/channels/telegram_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/media.py +231 -231
- package/channels/textfmt.py +58 -58
- package/channels/wechat_channel/__init__.py +1 -1
- package/channels/wechat_channel/auth.py +23 -5
- package/channels/wechat_channel/manifest.yaml +5 -5
- package/channels/wechat_channel/media.py +178 -178
- package/config.yaml +2 -2
- package/core/activity.py +3 -0
- package/core/agent_loop.py +390 -55
- package/core/approval.py +17 -6
- package/core/artifacts.py +7 -0
- package/core/auto_review.py +23 -5
- package/core/channel_configs.py +34 -2
- package/core/channel_turns.py +759 -759
- package/core/child_approval.py +150 -0
- package/core/config_requirements.py +205 -0
- package/core/cron/runner.py +118 -6
- package/core/cron/store.py +14 -5
- package/core/cron/tools.py +17 -5
- package/core/endpoint.py +141 -0
- package/core/events.py +23 -0
- package/core/i18n.py +329 -329
- package/core/ice/store.py +191 -191
- package/core/inbound.py +193 -193
- package/core/jobs.py +19 -3
- package/core/last_good.py +150 -150
- package/core/llm_errors.py +227 -227
- package/core/llm_retry.py +230 -230
- package/core/memory/compressor.py +1214 -1214
- package/core/memory/manager.py +14 -0
- package/core/model_configs.py +80 -0
- package/core/pipeline/scheduler.py +2 -2
- package/core/pipeline/stages/agent_loop.py +24 -4
- package/core/pipeline/stages/pre_process.py +58 -7
- package/core/prompt_assembler.py +680 -680
- package/core/rg.py +255 -255
- package/core/security.py +1544 -1544
- package/core/settings_baseline.py +70 -1
- package/core/shell.py +5 -17
- package/core/skill_settings.py +7 -2
- package/core/state_registry.py +19 -0
- package/core/subagent.py +64 -3
- package/core/task_tool.py +1 -1
- package/core/tasks_notify.py +69 -4
- package/core/tiers.py +9 -3
- package/core/tool_outcome.py +108 -0
- package/core/update_tui.py +158 -0
- package/core/version.py +2 -2
- package/core/web_cache.py +152 -0
- package/crannia_tray.py +278 -278
- package/creators/models.json +4 -4
- package/data/settings.example.json +67 -0
- package/licenses/GPL-3.0.txt +619 -619
- package/licenses/LGPL-2.1.txt +502 -502
- package/licenses/LGPL-3.0.txt +165 -165
- package/licenses/MIT-chat-on-wechat.txt +18 -18
- package/licenses/MIT-deepseek-harness.txt +21 -21
- package/licenses/Molio-LICENSE.txt +44 -44
- package/locales/en.json +9 -4
- package/main.py +154 -154
- package/mcpx/manager.py +522 -522
- package/mcpx/servers/__init__.py +22 -22
- package/mcpx/servers/web_search.py +321 -33
- package/package.json +14 -9
- package/providers/anthropic/client.py +772 -772
- package/providers/cost_table.json +3779 -3779
- package/providers/deepseek/client.py +20 -20
- package/providers/deepseek/manifest.yaml +2 -2
- package/providers/factory.py +136 -136
- package/providers/lmstudio/client.py +2 -2
- package/providers/metadata.py +80 -80
- package/providers/model_capabilities.json +6665 -6665
- package/providers/moonshot/client.py +12 -12
- package/providers/ollama/client.py +2 -2
- package/providers/openai/client.py +13 -13
- package/providers/openrouter/client.py +2 -2
- package/providers/qwen/__init__.py +1 -1
- package/providers/qwen/client.py +2 -2
- package/providers/qwen/manifest.yaml +16 -16
- package/providers/rate_limiter.py +144 -144
- package/providers/siliconflow/client.py +2 -2
- package/providers/validation.py +171 -171
- package/providers/window_table.json +8909 -8909
- package/sbom.json +4413 -4296
- package/skills/entertainment/SKILL.md +35 -35
- package/skills/entertainment/__init__.py +1 -1
- package/skills/entertainment/handler.py +91 -91
- package/skills/entertainment/manifest.yaml +26 -26
- package/skills/file_parser/GUIDANCE.md +10 -10
- package/skills/file_parser/handler.py +177 -4
- package/skills/file_parser/manifest.yaml +22 -1
- package/skills/github/SKILL.md +32 -32
- package/skills/github/__init__.py +1 -1
- package/skills/github/manifest.yaml +5 -0
- package/skills/mail_parser/SKILL.md +68 -68
- package/skills/mail_parser/__init__.py +1 -1
- package/skills/mail_parser/handler.py +806 -806
- package/skills/mail_parser/manifest.yaml +5 -0
- package/skills/media_gen/GUIDANCE.md +19 -19
- package/skills/media_gen/SKILL.md +43 -43
- package/skills/media_gen/__init__.py +1 -1
- package/skills/media_gen/handler.py +430 -430
- package/skills/media_gen/manifest.yaml +93 -88
- package/skills/office_parser/cell_validation.py +127 -127
- package/skills/office_parser/excel_transform.py +936 -936
- package/skills/office_parser/layout_spec.py +243 -243
- package/skills/office_parser/pptx_export/console_encoding.py +27 -27
- package/skills/office_parser/pptx_export/resource_paths.py +88 -88
- package/skills/office_parser/pptx_export/svg_finalize/__init__.py +12 -12
- package/skills/office_parser/pptx_export/svg_finalize/align_embed_images.py +575 -575
- package/skills/office_parser/pptx_export/svg_finalize/crop_images.py +366 -366
- package/skills/office_parser/pptx_export/svg_finalize/embed_icons.py +498 -498
- package/skills/office_parser/pptx_export/svg_finalize/embed_images.py +288 -288
- package/skills/office_parser/pptx_export/svg_finalize/fix_image_aspect.py +388 -388
- package/skills/office_parser/pptx_export/svg_finalize/flatten_tspan.py +818 -818
- package/skills/office_parser/pptx_export/svg_finalize/svg_rect_to_path.py +345 -345
- package/skills/office_parser/pptx_export/svg_to_pptx/__init__.py +14 -14
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/__init__.py +1 -1
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/context.py +186 -186
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/converter.py +781 -781
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/elements.py +2490 -2490
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/paths.py +429 -429
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/styles.py +656 -656
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/__init__.py +1 -1
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/builder.py +1267 -1267
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/dimensions.py +155 -155
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/discovery.py +101 -101
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/media.py +141 -141
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/narration.py +236 -236
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/notes.py +257 -257
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/slide_xml.py +136 -136
- package/skills/office_parser/pptx_export/svg_to_pptx/tspan_flattener.py +44 -44
- package/skills/office_parser/pptx_export/svg_to_pptx/use_expander.py +129 -129
- package/skills/office_parser/references/LICENSE-Office-Word-MCP-Server.txt +20 -20
- package/skills/office_parser/references/LICENSE-excel-mcp-server.txt +21 -21
- package/skills/office_parser/references/layout_library.md +816 -816
- package/skills/office_parser/references/ppt-master/LICENSE +21 -21
- package/skills/office_parser/references/ppt-master/references/executor-base.md +474 -474
- package/skills/office_parser/references/ppt-master/references/shared-standards.md +1002 -1002
- package/skills/office_parser/references/ppt-master/references/strategist.md +880 -880
- package/skills/office_parser/references/ppt-master/references/template-designer.md +402 -402
- package/skills/office_parser/references/ppt-master/references/visual-review.md +240 -240
- package/skills/office_parser/references/ppt-master/references/visual-styles/_index.md +106 -106
- package/skills/office_parser/references/ppt-master/references/visual-styles/blueprint.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/brutalist.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/chalkboard.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/dark-tech.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/data-journalism.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/editorial.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/glassmorphism.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/ink-notes.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/ink-wash.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/memphis.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/paper-cut.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/photo-editorial.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/pixel-art.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/sketch-notes.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/soft-rounded.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/swiss-minimal.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/vintage-poster.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/zine.md +37 -37
- package/skills/office_parser/references/spec_lock.md +235 -235
- package/skills/office_parser/soffice.py +68 -68
- package/skills/office_parser/word_tools.py +2909 -2909
- package/tui/crannia.cmd +134 -0
- package/tui/crannia_tui/__init__.py +1 -0
- package/tui/crannia_tui/__main__.py +223 -0
- package/tui/crannia_tui/app.py +1318 -0
- package/tui/crannia_tui/app.tcss +153 -0
- package/tui/crannia_tui/approval.py +85 -0
- package/tui/crannia_tui/backend.py +279 -0
- package/tui/crannia_tui/channel.py +472 -0
- package/tui/crannia_tui/client.py +125 -0
- package/tui/crannia_tui/clipboard.py +62 -0
- package/tui/crannia_tui/commands.py +65 -0
- package/tui/crannia_tui/doctor.py +304 -0
- package/tui/crannia_tui/events.py +84 -0
- package/tui/crannia_tui/headless.py +152 -0
- package/tui/crannia_tui/i18n.py +164 -0
- package/tui/crannia_tui/locales/en.json +263 -0
- package/tui/crannia_tui/outcome.py +62 -0
- package/tui/crannia_tui/paths.py +181 -0
- package/tui/crannia_tui/probe.py +53 -0
- package/tui/crannia_tui/profile.py +169 -0
- package/tui/crannia_tui/render.py +209 -0
- package/tui/crannia_tui/settings.py +134 -0
- package/tui/crannia_tui/setup.py +380 -0
- package/tui/crannia_tui/term.py +116 -0
- package/tui/crannia_tui/ui.py +1236 -0
- package/tui/crannia_tui/update.py +389 -0
- package/vendor/ripgrep/COPYING.txt +3 -3
- package/vendor/ripgrep/LICENSE-MIT.txt +21 -21
- package/vendor/ripgrep/NOTICE-vscode-ripgrep.txt +13 -13
- package/vendor/ripgrep/README.md +51 -51
- package/vendor/ripgrep/UNLICENSE.txt +24 -24
- package/vendor/ripgrep/package-source.json +19 -19
- package/web/__main__.py +15 -0
- package/web/server.py +168 -19
- package/web/static/img/channel-telegram.svg +1 -1
- package/web/static/img/channel-wechat.svg +1 -1
- package/web/templates/logs.html +49 -49
- package/web/templates/models.html +46 -46
|
@@ -1,88 +1,93 @@
|
|
|
1
|
-
kind: skill
|
|
2
|
-
name: media_gen
|
|
3
|
-
version: "0.1.0"
|
|
4
|
-
draft: false
|
|
5
|
-
load_strategy: on_demand
|
|
6
|
-
description: "生图 —— 厂商直连(OpenAI 兼容 /images/generations),产出直接进聊天区"
|
|
7
|
-
# 技能页卡片上那句短简介,与 `description` 分开。
|
|
8
|
-
summary: "图视频拓展"
|
|
9
|
-
|
|
10
|
-
# 契约声明。
|
|
11
|
-
# · `api` 只在破坏性变更时 +1(加能力不算);
|
|
12
|
-
# · `requires` 里的每个名字都是 `core/capabilities.py` 的 `CAPABILITIES` 里的一项,
|
|
13
|
-
# 缺一项就不装载,并说清缺什么(不半残)。
|
|
14
|
-
api: 1
|
|
15
|
-
requires:
|
|
16
|
-
- artifacts
|
|
17
|
-
- artifacts.inline # 产物记录带 `inline`:大图给下载行而不是硬塞 <img>
|
|
18
|
-
- workspace # 落点走 primary_output_dir(本 skill 唯一的写路径口径)
|
|
19
|
-
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
1
|
+
kind: skill
|
|
2
|
+
name: media_gen
|
|
3
|
+
version: "0.1.0"
|
|
4
|
+
draft: false
|
|
5
|
+
load_strategy: on_demand
|
|
6
|
+
description: "生图 —— 厂商直连(OpenAI 兼容 /images/generations),产出直接进聊天区"
|
|
7
|
+
# 技能页卡片上那句短简介,与 `description` 分开。
|
|
8
|
+
summary: "图视频拓展"
|
|
9
|
+
|
|
10
|
+
# 契约声明。
|
|
11
|
+
# · `api` 只在破坏性变更时 +1(加能力不算);
|
|
12
|
+
# · `requires` 里的每个名字都是 `core/capabilities.py` 的 `CAPABILITIES` 里的一项,
|
|
13
|
+
# 缺一项就不装载,并说清缺什么(不半残)。
|
|
14
|
+
api: 1
|
|
15
|
+
requires:
|
|
16
|
+
- artifacts
|
|
17
|
+
- artifacts.inline # 产物记录带 `inline`:大图给下载行而不是硬塞 <img>
|
|
18
|
+
- workspace # 落点走 primary_output_dir(本 skill 唯一的写路径口径)
|
|
19
|
+
|
|
20
|
+
# 配置需求(与上面那根轴不同:`requires` 缺了不装载,这个缺了照样装,
|
|
21
|
+
# 只是医生报 WARN、工具失败带 `/config media_gen` 路线)。
|
|
22
|
+
requires_config:
|
|
23
|
+
- media_gen
|
|
24
|
+
|
|
25
|
+
# 本技能的工具不需要自动模式再判一遍:
|
|
26
|
+
# · 它写的文件在工作区里、可逆、一次一个;
|
|
27
|
+
# · 花费是用户自己的事,弹窗拦不住任何真风险,只会让"画张图"每次都停一下。
|
|
28
|
+
# 没有这一行的话,每调一次都过分类器(要花钱的 token),而且会被
|
|
29
|
+
# `test_auto_review` 当场点名(它要求每个走到第 ④ 层的工具做过决定)。
|
|
30
|
+
review_input: none
|
|
31
|
+
|
|
32
|
+
# 配置不在这里:凭据在 `data/media_gen_credentials.json`(不进 settings.json,
|
|
33
|
+
# 也不进导出包)。这里只声明"有哪些条目、字段长什么样"给界面用。
|
|
34
|
+
settings:
|
|
35
|
+
# 整份配置住在这个文件里,所以凭据天然不进 `settings.json`(导出也不带走)。
|
|
36
|
+
# 路径相对仓库根;`core/skill_settings.py` 是读写它的唯一入口(校验 + 打码 + 原子写)。
|
|
37
|
+
storage: data/media_gen_credentials.json
|
|
38
|
+
type: object
|
|
39
|
+
properties:
|
|
40
|
+
default:
|
|
41
|
+
type: string
|
|
42
|
+
title: 默认条目
|
|
43
|
+
description: 不指定 entry 时用哪一条。
|
|
44
|
+
entries:
|
|
45
|
+
type: object
|
|
46
|
+
title: 配置条目
|
|
47
|
+
description: 键是条目名;值见下面三个字段。
|
|
48
|
+
additionalProperties:
|
|
49
|
+
type: object
|
|
50
|
+
properties:
|
|
51
|
+
type:
|
|
52
|
+
type: string
|
|
53
|
+
title: 类型
|
|
54
|
+
enum: [vendor, local]
|
|
55
|
+
default: vendor
|
|
56
|
+
description: "vendor = 厂商直连(走 /images/generations);local = 本机 SD WebUI(走 /sdapi/v1/txt2img,只允许回环地址)"
|
|
57
|
+
base_url:
|
|
58
|
+
type: string
|
|
59
|
+
title: 请求地址
|
|
60
|
+
description: 请填写至API根
|
|
61
|
+
model:
|
|
62
|
+
type: string
|
|
63
|
+
title: 模型名
|
|
64
|
+
api_key:
|
|
65
|
+
type: string
|
|
66
|
+
title: API Key
|
|
67
|
+
format: password
|
|
68
|
+
x-secret: true # 声明为敏感:界面打码、不进 settings.json
|
|
69
|
+
|
|
70
|
+
tools:
|
|
71
|
+
- name: generate_image
|
|
72
|
+
permission: write
|
|
73
|
+
destructive: false
|
|
74
|
+
output_kind: structured
|
|
75
|
+
description: >
|
|
76
|
+
生成一张图片并保存到工作区(产出的图会直接显示在聊天里)。
|
|
77
|
+
需要先在生图配置里建一条(地址 + 模型名 + API Key)。
|
|
78
|
+
一次只生一张;要几张就调几次。提示词写清楚画面内容,
|
|
79
|
+
英文通常更稳。只用它来"从无到有画一张"——读图、改图、识别不走这里。
|
|
80
|
+
inputSchema:
|
|
81
|
+
$schema: "https://json-schema.org/draft/2020-12/schema"
|
|
82
|
+
type: object
|
|
83
|
+
properties:
|
|
84
|
+
prompt:
|
|
85
|
+
type: string
|
|
86
|
+
description: "画面描述(要画什么、风格、构图)"
|
|
87
|
+
size:
|
|
88
|
+
type: string
|
|
89
|
+
description: "尺寸,如 1024x1024 或 2K;不填用服务默认"
|
|
90
|
+
entry:
|
|
91
|
+
type: string
|
|
92
|
+
description: "用哪一条配置;不填用默认那条"
|
|
93
|
+
required: [prompt]
|
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
"""Excel 数据验证(下拉列表 / 数值区间 / 日期 …)的读取侧。
|
|
2
|
-
|
|
3
|
-
## 这个文件补的是一个静默空转
|
|
4
|
-
|
|
5
|
-
`read_excel_data(include_validation=True)` 里逐格 import 的就是本模块的
|
|
6
|
-
`get_data_validation_for_cell`。若这个模块缺失、异常又被一句裸
|
|
7
|
-
`except Exception` 吞掉:
|
|
8
|
-
|
|
9
|
-
cell_data["validation"] = {"has_validation": False}
|
|
10
|
-
|
|
11
|
-
`include_validation=True` 不会返回任何真规则,而且
|
|
12
|
-
没有任何东西会告诉你 —— 它给的是一个看起来像结论的 `False`。
|
|
13
|
-
|
|
14
|
-
这与写入侧的 `add_excel_data_validation` 是一对:那边能写、这边必须读得回来。
|
|
15
|
-
|
|
16
|
-
## 两条判据(别改)
|
|
17
|
-
|
|
18
|
-
1. 读不到 ≠ 没有。「这个格子没有验证规则」与
|
|
19
|
-
「我没查出来」是两件事,前者回 `None`,后者抛出去让调用方记成
|
|
20
|
-
`has_validation=None` + `error`。不许静默塌成 `False`。
|
|
21
|
-
2. 本模块只读,不碰 `wb.save` / 任何写标记(`read` 档的实现不许含写标记,
|
|
22
|
-
`tests/test_permission_tiers.py` 有 AST 读者)。
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
from __future__ import annotations
|
|
26
|
-
|
|
27
|
-
from typing import Any, Dict, List, Optional
|
|
28
|
-
|
|
29
|
-
from openpyxl.utils.cell import column_index_from_string, coordinate_from_string
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def get_data_validation_for_cell(
|
|
33
|
-
worksheet, cell_address: str
|
|
34
|
-
) -> Optional[Dict[str, Any]]:
|
|
35
|
-
"""`cell_address`(如 `"C2"`)上的验证规则。
|
|
36
|
-
|
|
37
|
-
* 有,返回规则字典(`has_validation: True` + 类型 / 取值 / 提示语)
|
|
38
|
-
* 没有,返回 `None`
|
|
39
|
-
* 查不出来,抛异常(调用方记成未知,不许塌成 False)
|
|
40
|
-
"""
|
|
41
|
-
col_letter, row = coordinate_from_string(cell_address)
|
|
42
|
-
col_idx = column_index_from_string(col_letter)
|
|
43
|
-
|
|
44
|
-
for dv in worksheet.data_validations.dataValidation:
|
|
45
|
-
if _covers(row, col_idx, dv):
|
|
46
|
-
return _extract(dv, cell_address, worksheet)
|
|
47
|
-
return None
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def _covers(row: int, col: int, dv) -> bool:
|
|
51
|
-
"""这个格子在不在这条规则的 `sqref` 覆盖范围里。"""
|
|
52
|
-
for rng in dv.sqref.ranges:
|
|
53
|
-
if rng.min_row <= row <= rng.max_row and rng.min_col <= col <= rng.max_col:
|
|
54
|
-
return True
|
|
55
|
-
return False
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def _extract(dv, cell_address: str, worksheet) -> Dict[str, Any]:
|
|
59
|
-
"""把一条 `DataValidation` 摊成给模型看的字典。
|
|
60
|
-
|
|
61
|
-
取不到的字段不写,而不是写一个空串 —— 空串看起来像"这条规则就是空的"。
|
|
62
|
-
"""
|
|
63
|
-
info: Dict[str, Any] = {
|
|
64
|
-
"cell": cell_address,
|
|
65
|
-
"has_validation": True,
|
|
66
|
-
"validation_type": dv.type,
|
|
67
|
-
"allow_blank": bool(dv.allowBlank),
|
|
68
|
-
}
|
|
69
|
-
if dv.operator:
|
|
70
|
-
info["operator"] = dv.operator
|
|
71
|
-
if dv.prompt:
|
|
72
|
-
info["prompt"] = dv.prompt
|
|
73
|
-
if dv.promptTitle:
|
|
74
|
-
info["prompt_title"] = dv.promptTitle
|
|
75
|
-
if dv.error:
|
|
76
|
-
info["error_message"] = dv.error
|
|
77
|
-
if dv.errorTitle:
|
|
78
|
-
info["error_title"] = dv.errorTitle
|
|
79
|
-
|
|
80
|
-
if dv.type == "list" and dv.formula1:
|
|
81
|
-
info["allowed_values"] = _list_values(dv.formula1, worksheet)
|
|
82
|
-
elif dv.formula1:
|
|
83
|
-
info["formula1"] = dv.formula1
|
|
84
|
-
if dv.formula2:
|
|
85
|
-
info["formula2"] = dv.formula2
|
|
86
|
-
|
|
87
|
-
return info
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def _list_values(formula: str, worksheet) -> List[str]:
|
|
91
|
-
"""把 `list` 类型的 `formula1` 摊成候选值。
|
|
92
|
-
|
|
93
|
-
两种写法都认(与 `add_excel_data_validation` 写出去的形状一致):
|
|
94
|
-
* 字面选项 "合格,不合格" —— 逗号分隔
|
|
95
|
-
* 区域引用 `=$E$1:$E$5` —— 去表里把值读出来
|
|
96
|
-
"""
|
|
97
|
-
raw = str(formula).strip()
|
|
98
|
-
# 去掉包裹的双引号;openpyxl 存字面选项时要求带引号
|
|
99
|
-
if len(raw) >= 2 and raw[0] == raw[-1] == '"':
|
|
100
|
-
raw = raw[1:-1]
|
|
101
|
-
|
|
102
|
-
# 字面选项:逗号分隔
|
|
103
|
-
if ":" not in raw and not raw.startswith("$") and not raw.startswith("="):
|
|
104
|
-
return [v.strip() for v in raw.split(",") if v.strip()]
|
|
105
|
-
|
|
106
|
-
# 区域引用:去表里读
|
|
107
|
-
ref = raw[1:] if raw.startswith("=") else raw
|
|
108
|
-
try:
|
|
109
|
-
cells = worksheet[ref]
|
|
110
|
-
except Exception:
|
|
111
|
-
# 区域解不开时不假装空:把引用原样回给模型,让它自己判断
|
|
112
|
-
return [f"范围: {ref}(解析不了,请自行查看)"]
|
|
113
|
-
|
|
114
|
-
flat = []
|
|
115
|
-
if hasattr(cells, "value"): # 单个格子
|
|
116
|
-
if cells.value is not None:
|
|
117
|
-
flat.append(str(cells.value))
|
|
118
|
-
else:
|
|
119
|
-
for item in cells:
|
|
120
|
-
if hasattr(item, "value"): # 一维
|
|
121
|
-
if item.value is not None:
|
|
122
|
-
flat.append(str(item.value))
|
|
123
|
-
else: # 二维
|
|
124
|
-
for c in item:
|
|
125
|
-
if c.value is not None:
|
|
126
|
-
flat.append(str(c.value))
|
|
127
|
-
return flat if flat else [f"范围: {ref}(里头没有值)"]
|
|
1
|
+
"""Excel 数据验证(下拉列表 / 数值区间 / 日期 …)的读取侧。
|
|
2
|
+
|
|
3
|
+
## 这个文件补的是一个静默空转
|
|
4
|
+
|
|
5
|
+
`read_excel_data(include_validation=True)` 里逐格 import 的就是本模块的
|
|
6
|
+
`get_data_validation_for_cell`。若这个模块缺失、异常又被一句裸
|
|
7
|
+
`except Exception` 吞掉:
|
|
8
|
+
|
|
9
|
+
cell_data["validation"] = {"has_validation": False}
|
|
10
|
+
|
|
11
|
+
`include_validation=True` 不会返回任何真规则,而且
|
|
12
|
+
没有任何东西会告诉你 —— 它给的是一个看起来像结论的 `False`。
|
|
13
|
+
|
|
14
|
+
这与写入侧的 `add_excel_data_validation` 是一对:那边能写、这边必须读得回来。
|
|
15
|
+
|
|
16
|
+
## 两条判据(别改)
|
|
17
|
+
|
|
18
|
+
1. 读不到 ≠ 没有。「这个格子没有验证规则」与
|
|
19
|
+
「我没查出来」是两件事,前者回 `None`,后者抛出去让调用方记成
|
|
20
|
+
`has_validation=None` + `error`。不许静默塌成 `False`。
|
|
21
|
+
2. 本模块只读,不碰 `wb.save` / 任何写标记(`read` 档的实现不许含写标记,
|
|
22
|
+
`tests/test_permission_tiers.py` 有 AST 读者)。
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from typing import Any, Dict, List, Optional
|
|
28
|
+
|
|
29
|
+
from openpyxl.utils.cell import column_index_from_string, coordinate_from_string
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_data_validation_for_cell(
|
|
33
|
+
worksheet, cell_address: str
|
|
34
|
+
) -> Optional[Dict[str, Any]]:
|
|
35
|
+
"""`cell_address`(如 `"C2"`)上的验证规则。
|
|
36
|
+
|
|
37
|
+
* 有,返回规则字典(`has_validation: True` + 类型 / 取值 / 提示语)
|
|
38
|
+
* 没有,返回 `None`
|
|
39
|
+
* 查不出来,抛异常(调用方记成未知,不许塌成 False)
|
|
40
|
+
"""
|
|
41
|
+
col_letter, row = coordinate_from_string(cell_address)
|
|
42
|
+
col_idx = column_index_from_string(col_letter)
|
|
43
|
+
|
|
44
|
+
for dv in worksheet.data_validations.dataValidation:
|
|
45
|
+
if _covers(row, col_idx, dv):
|
|
46
|
+
return _extract(dv, cell_address, worksheet)
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _covers(row: int, col: int, dv) -> bool:
|
|
51
|
+
"""这个格子在不在这条规则的 `sqref` 覆盖范围里。"""
|
|
52
|
+
for rng in dv.sqref.ranges:
|
|
53
|
+
if rng.min_row <= row <= rng.max_row and rng.min_col <= col <= rng.max_col:
|
|
54
|
+
return True
|
|
55
|
+
return False
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _extract(dv, cell_address: str, worksheet) -> Dict[str, Any]:
|
|
59
|
+
"""把一条 `DataValidation` 摊成给模型看的字典。
|
|
60
|
+
|
|
61
|
+
取不到的字段不写,而不是写一个空串 —— 空串看起来像"这条规则就是空的"。
|
|
62
|
+
"""
|
|
63
|
+
info: Dict[str, Any] = {
|
|
64
|
+
"cell": cell_address,
|
|
65
|
+
"has_validation": True,
|
|
66
|
+
"validation_type": dv.type,
|
|
67
|
+
"allow_blank": bool(dv.allowBlank),
|
|
68
|
+
}
|
|
69
|
+
if dv.operator:
|
|
70
|
+
info["operator"] = dv.operator
|
|
71
|
+
if dv.prompt:
|
|
72
|
+
info["prompt"] = dv.prompt
|
|
73
|
+
if dv.promptTitle:
|
|
74
|
+
info["prompt_title"] = dv.promptTitle
|
|
75
|
+
if dv.error:
|
|
76
|
+
info["error_message"] = dv.error
|
|
77
|
+
if dv.errorTitle:
|
|
78
|
+
info["error_title"] = dv.errorTitle
|
|
79
|
+
|
|
80
|
+
if dv.type == "list" and dv.formula1:
|
|
81
|
+
info["allowed_values"] = _list_values(dv.formula1, worksheet)
|
|
82
|
+
elif dv.formula1:
|
|
83
|
+
info["formula1"] = dv.formula1
|
|
84
|
+
if dv.formula2:
|
|
85
|
+
info["formula2"] = dv.formula2
|
|
86
|
+
|
|
87
|
+
return info
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _list_values(formula: str, worksheet) -> List[str]:
|
|
91
|
+
"""把 `list` 类型的 `formula1` 摊成候选值。
|
|
92
|
+
|
|
93
|
+
两种写法都认(与 `add_excel_data_validation` 写出去的形状一致):
|
|
94
|
+
* 字面选项 "合格,不合格" —— 逗号分隔
|
|
95
|
+
* 区域引用 `=$E$1:$E$5` —— 去表里把值读出来
|
|
96
|
+
"""
|
|
97
|
+
raw = str(formula).strip()
|
|
98
|
+
# 去掉包裹的双引号;openpyxl 存字面选项时要求带引号
|
|
99
|
+
if len(raw) >= 2 and raw[0] == raw[-1] == '"':
|
|
100
|
+
raw = raw[1:-1]
|
|
101
|
+
|
|
102
|
+
# 字面选项:逗号分隔
|
|
103
|
+
if ":" not in raw and not raw.startswith("$") and not raw.startswith("="):
|
|
104
|
+
return [v.strip() for v in raw.split(",") if v.strip()]
|
|
105
|
+
|
|
106
|
+
# 区域引用:去表里读
|
|
107
|
+
ref = raw[1:] if raw.startswith("=") else raw
|
|
108
|
+
try:
|
|
109
|
+
cells = worksheet[ref]
|
|
110
|
+
except Exception:
|
|
111
|
+
# 区域解不开时不假装空:把引用原样回给模型,让它自己判断
|
|
112
|
+
return [f"范围: {ref}(解析不了,请自行查看)"]
|
|
113
|
+
|
|
114
|
+
flat = []
|
|
115
|
+
if hasattr(cells, "value"): # 单个格子
|
|
116
|
+
if cells.value is not None:
|
|
117
|
+
flat.append(str(cells.value))
|
|
118
|
+
else:
|
|
119
|
+
for item in cells:
|
|
120
|
+
if hasattr(item, "value"): # 一维
|
|
121
|
+
if item.value is not None:
|
|
122
|
+
flat.append(str(item.value))
|
|
123
|
+
else: # 二维
|
|
124
|
+
for c in item:
|
|
125
|
+
if c.value is not None:
|
|
126
|
+
flat.append(str(c.value))
|
|
127
|
+
return flat if flat else [f"范围: {ref}(里头没有值)"]
|