@lark-apaas/coding-steering 0.1.31 → 0.1.32-beta.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/package.json +1 -1
- package/steering/design-html/skills/pptx-style-extract/SKILL.md +112 -0
- package/steering/design-html/skills/pptx-style-extract/font-fallback.yaml +129 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/census.py +955 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/check_v2.py +907 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/draft.py +945 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/export_consumer_md.py +75 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/export_consumer_zip.py +175 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/extract.py +765 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/ooxml.py +699 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/package.py +1120 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/parts.py +461 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/query.py +562 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/render_pages.py +679 -0
- package/steering/design-html/skills/pptx-style-extract/scripts/verify_font.py +68 -0
- package/steering/design-html/skills/pptx-style-extract/v2-format-spec.md +193 -0
|
@@ -0,0 +1,1120 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""S11 打包器:把「阶段一抽取产物 + L 层判断单」机械组装成风格包 v2。
|
|
3
|
+
|
|
4
|
+
python3 package.py <stage1-outdir> <l-out-dir> <pack-out-dir> [选项]
|
|
5
|
+
|
|
6
|
+
--check-v1 <path> 顺带跑 v1 门禁(需要外部 check_v1.py 路径)
|
|
7
|
+
--style-name <name> 覆盖 manifest 里的 name(包目录名仍取 pack-out-dir)
|
|
8
|
+
--force pack-out-dir 已存在且非空时照样写
|
|
9
|
+
|
|
10
|
+
本脚本零判断:所有语义来自 <l-out-dir>,所有数值来自 <stage1-outdir>/extract.json。
|
|
11
|
+
它只做四件机械事——排键序、拷资产、算审计数据、跑门禁。
|
|
12
|
+
|
|
13
|
+
================================================================================
|
|
14
|
+
L 层判断单 schema(<l-out-dir> 四个文件,这段就是填写说明书)
|
|
15
|
+
================================================================================
|
|
16
|
+
|
|
17
|
+
本脚本自带极简 YAML 读取器,只认下面这些写法,**不要用锚点/别名/复杂嵌套流**:
|
|
18
|
+
key: 标量 标量可加引号(会原样保留到产物里)
|
|
19
|
+
key: [a, b, c] 流式列表
|
|
20
|
+
key: | 或 key: > 块标量(`|` 保留换行,`>` 折成一行)
|
|
21
|
+
key: 后跟缩进块 —— 对 frontmatter.yaml / layouts.yaml
|
|
22
|
+
... 这类「原样透传」的键,块内文本**逐字节照搬**进产物,
|
|
23
|
+
所以缩进/引号/注释请按最终想要的样子写
|
|
24
|
+
|
|
25
|
+
--------------------------------------------------------------------------------
|
|
26
|
+
1) manifest.yaml —— 包身份 + 资产映射(唯一需要本脚本解析结构的文件)
|
|
27
|
+
--------------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
version: alpha # 可选,默认 alpha
|
|
30
|
+
name: azure-mist-deck # 必填,包名(英文 kebab)
|
|
31
|
+
name_zh: 碧空雾面 # 可选
|
|
32
|
+
description: > # 可选,一段话,会折成单行进 frontmatter
|
|
33
|
+
整幅铺满带颗粒感的淡蓝雾面底图……
|
|
34
|
+
themes: [dark, light] # 可选;单主题包不写
|
|
35
|
+
default-theme: dark # themes 长度 >1 时必填(V2-13)
|
|
36
|
+
theme-mechanism: "……" # 可选,进 ref/audit.yaml(不进 design.md)
|
|
37
|
+
color-confidence: {level: medium, note: "……"} # 可选,进 ref/audit.yaml
|
|
38
|
+
assets: # 可选;无资产包可整段省略
|
|
39
|
+
- id: bg-cover # 必填。命名规则 <kind 前缀>-<语义名>,
|
|
40
|
+
# logo- / slogan- / bg- / texture- / icon-
|
|
41
|
+
source_media: image-1-1.jpeg # media-out/ 里的**原图**文件名(不是压缩版)
|
|
42
|
+
kind: background # logo|slogan|background|texture|icon
|
|
43
|
+
role: cover # background/icon 用;封闭枚举见规范 §2
|
|
44
|
+
theme: dark # 双主题包按需
|
|
45
|
+
on-bg: light # logo/slogan 用
|
|
46
|
+
mark: lockup # logo/slogan 用;**自动进 audit.yaml**
|
|
47
|
+
use_full: true # true = 同时落原图为 <name>@full.<ext>
|
|
48
|
+
recipe: "linear-gradient(…)" # 可选,CSS 重绘配方
|
|
49
|
+
confidence: high # 可选,默认 high;**自动进 audit.yaml**
|
|
50
|
+
- id: bg-surface # 纯色背景:不给 source_media,给 color
|
|
51
|
+
kind: background
|
|
52
|
+
role: content
|
|
53
|
+
color: "{colors.surface}"
|
|
54
|
+
|
|
55
|
+
说明:`boxes` / `aspect` / `canvas-source` **不要填**——脚本按 source_media 从
|
|
56
|
+
extract.json 的 images[] 直接取,写进 ref/audit.yaml。
|
|
57
|
+
|
|
58
|
+
derived: # 可选:推导值豁免声明(数值可追溯机检用)
|
|
59
|
+
- value: "1.05" # 按字面值豁免:产物里出现的该值放行
|
|
60
|
+
reason: "CJK 行高转译"
|
|
61
|
+
- value: "#5A5A5A"
|
|
62
|
+
reason: "白字 70% 不透明度的等效实色"
|
|
63
|
+
- token: light-surface # 按键名豁免:该 token(或其祖先键)下所有值放行
|
|
64
|
+
reason: "材质推导,gaps 已注明"
|
|
65
|
+
rebase_factor: 1.6 # 可选:字号等比上抬倍率;命中「普查值 × 它 ±1px」即放行
|
|
66
|
+
|
|
67
|
+
打包最后一步会校验产物里每个 hex / fontSize / slots.box 是否可追溯:
|
|
68
|
+
hex 命中 color_freq ∪ 形状与背景的填充/描边/渐变 stop 色 ∪ images[].dominant_colors
|
|
69
|
+
(每通道 ±8,采样色有量化误差);fontSize 命中 text_scale;box 命中 ref/shapes.json
|
|
70
|
+
某形状框 ±2px。命不中又没在 derived 里声明 → FAIL 并给出最近候选。
|
|
71
|
+
|
|
72
|
+
--------------------------------------------------------------------------------
|
|
73
|
+
2) frontmatter.yaml —— L 层判断产物,原样进 design.md frontmatter
|
|
74
|
+
--------------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
顶层键只允许这些(缺哪个就不写哪个,脚本按规范 §1 键序重排):
|
|
77
|
+
colors / typography / spacing / rounded / components / omitted
|
|
78
|
+
anchors / gaps / exceptions / safe-area
|
|
79
|
+
写法就是最终 frontmatter 的样子,例如:
|
|
80
|
+
|
|
81
|
+
colors:
|
|
82
|
+
surface: "#FFFFFF"
|
|
83
|
+
primary: "#2D5A8E"
|
|
84
|
+
safe-area:
|
|
85
|
+
content: {top: 60, right: 90, bottom: 113, left: 90, applies-to: [content]}
|
|
86
|
+
confidence: medium
|
|
87
|
+
|
|
88
|
+
--------------------------------------------------------------------------------
|
|
89
|
+
3) layouts.yaml —— archetype 数据,渲染成 layouts.md
|
|
90
|
+
--------------------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
只需一个顶层键 `layouts:`,内容原样透传。**不要写 canvas**——脚本从
|
|
93
|
+
extract.json 取并放成 layouts.md frontmatter 首键(V2-10 / V2-R6)。
|
|
94
|
+
|
|
95
|
+
layouts:
|
|
96
|
+
cover:
|
|
97
|
+
name: "封面"
|
|
98
|
+
role: cover
|
|
99
|
+
background: bg-cover
|
|
100
|
+
slots:
|
|
101
|
+
- {role: title, box: [257, 313, 1406, 130], type: title}
|
|
102
|
+
confidence: high
|
|
103
|
+
|
|
104
|
+
可选 `body:` 块标量 —— 追加到 layouts.md frontmatter 之后作为说明正文。
|
|
105
|
+
|
|
106
|
+
--------------------------------------------------------------------------------
|
|
107
|
+
4) body.md —— design.md 正文全文
|
|
108
|
+
--------------------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
从 `## Overview` 开始的全部正文(Usage / Colors / Typography / Hard Rules /
|
|
111
|
+
Exceptions……)。脚本原样拼在 frontmatter 之后,不改一个字。
|
|
112
|
+
"""
|
|
113
|
+
import argparse
|
|
114
|
+
from collections import Counter
|
|
115
|
+
import hashlib
|
|
116
|
+
import json
|
|
117
|
+
import os
|
|
118
|
+
import re
|
|
119
|
+
import shutil
|
|
120
|
+
import subprocess
|
|
121
|
+
import sys
|
|
122
|
+
|
|
123
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
124
|
+
|
|
125
|
+
# 规范 §1 键序:官方白名单 → v1 自造 → v2 自造。审计键(canvas-source /
|
|
126
|
+
# theme-mechanism / color-confidence)按 V2-R6 不进 design.md,故不在此列。
|
|
127
|
+
FRONTMATTER_ORDER = [
|
|
128
|
+
'version', 'name', 'name_zh', 'description',
|
|
129
|
+
'colors', 'typography', 'spacing', 'rounded', 'components', 'omitted',
|
|
130
|
+
'anchors', 'gaps', 'exceptions',
|
|
131
|
+
'themes', 'default-theme', 'assets', 'layouts', 'safe-area',
|
|
132
|
+
]
|
|
133
|
+
# frontmatter.yaml 允许 L 层提供的键(其余由 manifest / 脚本产出)
|
|
134
|
+
L_FRONTMATTER_KEYS = {'colors', 'typography', 'spacing', 'rounded', 'components',
|
|
135
|
+
'omitted', 'anchors', 'gaps', 'exceptions', 'safe-area'}
|
|
136
|
+
# design.md 资产条目只留消费字段,顺序固定(check_v2 V2-R6 把其余判成审计字段)
|
|
137
|
+
ASSET_CONSUMER_FIELDS = ['path', 'url', 'color', 'full', 'kind', 'role',
|
|
138
|
+
'theme', 'on-bg', 'recipe']
|
|
139
|
+
ASSET_AUDIT_FIELDS = ['boxes', 'aspect', 'mark', 'confidence']
|
|
140
|
+
KIND_PREFIX = {'background': 'bg', 'logo': 'logo', 'slogan': 'slogan',
|
|
141
|
+
'texture': 'texture', 'icon': 'icon'}
|
|
142
|
+
# stage1 ref/ 里随包分发的审计件(其余如 shapes.json 体量大、不进包)
|
|
143
|
+
REF_CARRY = ('color-freq-raw.json', 'font-clusters.json', 's5-acceptance.json',
|
|
144
|
+
'content-clusters.json', 'notes.md')
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class Fail(SystemExit):
|
|
148
|
+
def __init__(self, msg):
|
|
149
|
+
super().__init__('package.py: %s' % msg)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# ------------------------------------------------------------ 极简 YAML 读取
|
|
153
|
+
def split_top_blocks(text):
|
|
154
|
+
"""顶层 `key:` 切块。返回 [(key, inline_value, block_lines)],块内逐字节保留。"""
|
|
155
|
+
out, cur = [], None
|
|
156
|
+
for raw in text.splitlines():
|
|
157
|
+
if not raw.strip() or raw.lstrip().startswith('#'):
|
|
158
|
+
if cur:
|
|
159
|
+
cur[2].append(raw)
|
|
160
|
+
continue
|
|
161
|
+
m = re.match(r'([A-Za-z_][\w-]*):(.*)$', raw)
|
|
162
|
+
if m and not raw[0].isspace():
|
|
163
|
+
cur = [m.group(1), m.group(2).strip(), []]
|
|
164
|
+
out.append(cur)
|
|
165
|
+
elif cur:
|
|
166
|
+
cur[2].append(raw)
|
|
167
|
+
else:
|
|
168
|
+
raise Fail('顶层出现无键行: %r' % raw[:60])
|
|
169
|
+
# 去掉每块尾部空行,避免透传时带出多余空白
|
|
170
|
+
for entry in out:
|
|
171
|
+
while entry[2] and not entry[2][-1].strip():
|
|
172
|
+
entry[2].pop()
|
|
173
|
+
return out
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def unquote(s):
|
|
177
|
+
s = s.strip()
|
|
178
|
+
if len(s) >= 2 and s[0] == s[-1] and s[0] in '"\'':
|
|
179
|
+
return s[1:-1]
|
|
180
|
+
# 未加引号的标量后面跟行内注释:按 YAML 规矩剥掉(前面必须有空白)
|
|
181
|
+
s = re.split(r'\s+#', s, maxsplit=1)[0].strip()
|
|
182
|
+
return s
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def scalar_of(inline, lines):
|
|
186
|
+
"""标量取值:支持 `key: v`、`key: |`、`key: >`。
|
|
187
|
+
|
|
188
|
+
`|` 按公共缩进整体 dedent,**不逐行 strip** —— 正文里的嵌套列表/缩进代码块
|
|
189
|
+
靠相对缩进表意,逐行 strip 会把它们拍平。
|
|
190
|
+
"""
|
|
191
|
+
if inline in ('|', '>', '|-', '>-'):
|
|
192
|
+
if inline.startswith('>'):
|
|
193
|
+
return ' '.join(ln.strip() for ln in lines if ln.strip()).strip()
|
|
194
|
+
indents = [len(ln) - len(ln.lstrip()) for ln in lines if ln.strip()]
|
|
195
|
+
pad = min(indents) if indents else 0
|
|
196
|
+
return '\n'.join(ln[pad:] if len(ln) >= pad else ln.lstrip()
|
|
197
|
+
for ln in lines).strip('\n')
|
|
198
|
+
return unquote(inline)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def parse_flow_list(s):
|
|
202
|
+
s = s.strip()
|
|
203
|
+
if not (s.startswith('[') and s.endswith(']')):
|
|
204
|
+
return None
|
|
205
|
+
inner = s[1:-1].strip()
|
|
206
|
+
return [unquote(x) for x in inner.split(',') if x.strip()] if inner else []
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def parse_item_list(lines):
|
|
210
|
+
"""`- key: v` 形式的对象列表。"""
|
|
211
|
+
items, cur = [], None
|
|
212
|
+
for raw in lines:
|
|
213
|
+
if not raw.strip() or raw.lstrip().startswith('#'):
|
|
214
|
+
continue
|
|
215
|
+
stripped = raw.strip()
|
|
216
|
+
if stripped.startswith('- '):
|
|
217
|
+
cur = {}
|
|
218
|
+
items.append(cur)
|
|
219
|
+
stripped = stripped[2:].strip()
|
|
220
|
+
if not stripped:
|
|
221
|
+
continue
|
|
222
|
+
if cur is None:
|
|
223
|
+
raise Fail('资产列表里出现不属于任何 `- ` 项的行: %r' % raw[:60])
|
|
224
|
+
m = re.match(r'([A-Za-z_][\w-]*):(.*)$', stripped)
|
|
225
|
+
if not m:
|
|
226
|
+
raise Fail('资产列表行无法解析: %r' % raw[:60])
|
|
227
|
+
# 值原样保留(含作者的引号):recipe / color / url 这些是直接透传进
|
|
228
|
+
# design.md 的文本,重新决定要不要加引号会改掉作者的写法。
|
|
229
|
+
cur[m.group(1)] = m.group(2).strip()
|
|
230
|
+
return items
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def read_manifest(path):
|
|
234
|
+
blocks = split_top_blocks(open(path, encoding='utf-8').read())
|
|
235
|
+
man, assets, raw = {}, [], {}
|
|
236
|
+
derived = []
|
|
237
|
+
for key, inline, lines in blocks:
|
|
238
|
+
if key == 'assets':
|
|
239
|
+
assets = parse_item_list(lines)
|
|
240
|
+
elif key == 'derived':
|
|
241
|
+
derived = parse_item_list(lines)
|
|
242
|
+
elif inline.startswith('['):
|
|
243
|
+
man[key] = parse_flow_list(inline)
|
|
244
|
+
elif inline.startswith('{'):
|
|
245
|
+
man[key] = inline # 流映射原样透传
|
|
246
|
+
else:
|
|
247
|
+
man[key] = scalar_of(inline, lines)
|
|
248
|
+
if lines:
|
|
249
|
+
# 记住原始块形态(如 `description: >` 多行),回写时逐字节照搬,
|
|
250
|
+
# 不把作者的折行改成一条长行。
|
|
251
|
+
raw[key] = (inline, lines)
|
|
252
|
+
man['assets'] = assets
|
|
253
|
+
man['derived'] = derived
|
|
254
|
+
man['_raw'] = raw
|
|
255
|
+
return man
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
# ------------------------------------------------------------------- 组装
|
|
259
|
+
def yaml_scalar(v):
|
|
260
|
+
"""标量回写。已带引号 / 流式结构原样;含 YAML 危险序列才补引号。"""
|
|
261
|
+
s = str(v)
|
|
262
|
+
if not s:
|
|
263
|
+
return "''"
|
|
264
|
+
if s[0] in '"\'[{' or s[-1] in '"\']}':
|
|
265
|
+
return s
|
|
266
|
+
if re.search(r':\s|\s#|^[-?*&!|>%@`]', s) or s.strip() != s:
|
|
267
|
+
return '"%s"' % s.replace('"', '\\"')
|
|
268
|
+
return s
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def truthy(v):
|
|
272
|
+
return str(v).strip().lower() in ('1', 'true', 'yes', 'on')
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def asset_ext(name):
|
|
276
|
+
return name.rsplit('.', 1)[-1].lower() if '.' in name else ''
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def strip_kind_prefix(aid, kind):
|
|
280
|
+
"""`bg-cover` + background -> `cover`;前缀对不上就整名照用。"""
|
|
281
|
+
for pref in (KIND_PREFIX.get(kind), kind):
|
|
282
|
+
if pref and aid.startswith(pref + '-'):
|
|
283
|
+
return aid[len(pref) + 1:]
|
|
284
|
+
return aid
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def media_row_of(extract, source_media):
|
|
288
|
+
for m in extract.get('media') or []:
|
|
289
|
+
if m.get('out') and os.path.basename(m['out']) == source_media:
|
|
290
|
+
return m
|
|
291
|
+
for m in extract.get('media') or []:
|
|
292
|
+
if os.path.basename(m['media']) == source_media:
|
|
293
|
+
return m
|
|
294
|
+
return None
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def image_row_of(extract, source_media):
|
|
298
|
+
for i in extract.get('images') or []:
|
|
299
|
+
if os.path.basename(i['media']) == source_media:
|
|
300
|
+
return i
|
|
301
|
+
# An svg that ships as a raster's vector companion has no images[] row of its
|
|
302
|
+
# own — the placement is recorded on the raster (a:blip embeds the png, the svg
|
|
303
|
+
# rides in a:extLst/svgBlip). Its boxes therefore come from the companion.
|
|
304
|
+
for i in extract.get('images') or []:
|
|
305
|
+
comp = i.get('svg_companion')
|
|
306
|
+
if comp and os.path.basename(comp) == source_media:
|
|
307
|
+
return i
|
|
308
|
+
return None
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def place_assets(manifest, extract, stage1, pack):
|
|
312
|
+
"""拷贝资产 + 生成 design.md 的 assets 段 + audit.yaml 的 assets 段。"""
|
|
313
|
+
consumer, audit, copied = {}, {}, []
|
|
314
|
+
for a in manifest['assets']:
|
|
315
|
+
a = dict(a)
|
|
316
|
+
for f in ('id', 'kind', 'source_media', 'use_full', 'mark', 'confidence'):
|
|
317
|
+
if f in a:
|
|
318
|
+
a[f] = unquote(a[f])
|
|
319
|
+
aid = a.get('id')
|
|
320
|
+
if not aid:
|
|
321
|
+
raise Fail('assets 里有条目缺 id')
|
|
322
|
+
kind = a.get('kind')
|
|
323
|
+
if kind not in KIND_PREFIX:
|
|
324
|
+
raise Fail('%s: kind=%r 不在 %s 内' % (aid, kind, sorted(KIND_PREFIX)))
|
|
325
|
+
entry = {'kind': kind}
|
|
326
|
+
for f in ('role', 'theme', 'on-bg', 'recipe'):
|
|
327
|
+
if a.get(f):
|
|
328
|
+
entry[f] = a[f]
|
|
329
|
+
|
|
330
|
+
if a.get('color'):
|
|
331
|
+
entry['color'] = a['color'] # 纯色背景,不落文件
|
|
332
|
+
elif a.get('url'):
|
|
333
|
+
entry['url'] = a['url']
|
|
334
|
+
elif a.get('source_media'):
|
|
335
|
+
src = a['source_media']
|
|
336
|
+
row = media_row_of(extract, src)
|
|
337
|
+
if row is None or not row.get('out'):
|
|
338
|
+
raise Fail('%s: media-out 里找不到 %s(extract.json media 无该导出行;'
|
|
339
|
+
'非候选图需先用 extract.py --export-all-media 补导)' % (aid, src))
|
|
340
|
+
base = strip_kind_prefix(aid, kind)
|
|
341
|
+
sub = os.path.join(pack, 'assets', kind + 's')
|
|
342
|
+
os.makedirs(sub, exist_ok=True)
|
|
343
|
+
comp = row.get('compressed_out')
|
|
344
|
+
orig_path = os.path.join(stage1, row['out'])
|
|
345
|
+
if comp:
|
|
346
|
+
comp_path = os.path.join(stage1, comp)
|
|
347
|
+
cext = asset_ext(comp)
|
|
348
|
+
dst = os.path.join(sub, '%s.%s' % (base, cext))
|
|
349
|
+
shutil.copy2(comp_path, dst)
|
|
350
|
+
copied.append(dst)
|
|
351
|
+
entry['path'] = 'assets/%ss/%s.%s' % (kind, base, cext)
|
|
352
|
+
if truthy(a.get('use_full')):
|
|
353
|
+
oext = asset_ext(row['out'])
|
|
354
|
+
fdst = os.path.join(sub, '%s@full.%s' % (base, oext))
|
|
355
|
+
shutil.copy2(orig_path, fdst)
|
|
356
|
+
copied.append(fdst)
|
|
357
|
+
entry['full'] = 'assets/%ss/%s@full.%s' % (kind, base, oext)
|
|
358
|
+
else:
|
|
359
|
+
oext = asset_ext(row['out'])
|
|
360
|
+
dst = os.path.join(sub, '%s.%s' % (base, oext))
|
|
361
|
+
shutil.copy2(orig_path, dst)
|
|
362
|
+
copied.append(dst)
|
|
363
|
+
entry['path'] = 'assets/%ss/%s.%s' % (kind, base, oext)
|
|
364
|
+
if truthy(a.get('use_full')):
|
|
365
|
+
raise Fail('%s: use_full=true 但 %s 没有压缩版产物,'
|
|
366
|
+
'path/full 会指向同一文件' % (aid, src))
|
|
367
|
+
else:
|
|
368
|
+
raise Fail('%s: 必须给 source_media / color / url 之一' % aid)
|
|
369
|
+
|
|
370
|
+
consumer[aid] = entry
|
|
371
|
+
# ---- 审计数据全部机器算,L 层不碰
|
|
372
|
+
au = {}
|
|
373
|
+
if a.get('source_media'):
|
|
374
|
+
img = image_row_of(extract, a['source_media'])
|
|
375
|
+
if img:
|
|
376
|
+
# 首项为主位 = 出现次数最多者;次数打平时按阅读顺序(上→下、左→右)
|
|
377
|
+
# 定序,避免同频簇的先后取决于字典插入顺序。
|
|
378
|
+
clusters = sorted(img.get('boxes') or [],
|
|
379
|
+
key=lambda c: (-c['count'], c['box']['y'], c['box']['x']))
|
|
380
|
+
boxes = [[int(round(c['box'][k])) for k in ('x', 'y', 'w', 'h')]
|
|
381
|
+
for c in clusters]
|
|
382
|
+
if boxes:
|
|
383
|
+
au['boxes'] = boxes
|
|
384
|
+
# aspect 取**未取整**的 box —— 从取整后的整数反算会明显偏
|
|
385
|
+
# (volcano logo 224.1/47.8=4.688,用 224/48 算成 4.667)。
|
|
386
|
+
raw = clusters[0]['box']
|
|
387
|
+
if raw.get('h'):
|
|
388
|
+
au['aspect'] = round(raw['w'] / float(raw['h']), 3)
|
|
389
|
+
if a.get('mark'):
|
|
390
|
+
au['mark'] = a['mark']
|
|
391
|
+
au['confidence'] = a.get('confidence') or 'high'
|
|
392
|
+
audit[aid] = au
|
|
393
|
+
return consumer, audit, copied
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def _pages_of(extract, source_media):
|
|
397
|
+
img = image_row_of(extract, source_media) if source_media else None
|
|
398
|
+
if not img:
|
|
399
|
+
return []
|
|
400
|
+
pages = set()
|
|
401
|
+
for c in img.get('boxes') or []:
|
|
402
|
+
for p in c.get('parts') or []:
|
|
403
|
+
m = re.search(r'slide(\d+)\.xml$', p)
|
|
404
|
+
if m and '/slides/' in p:
|
|
405
|
+
pages.add(int(m.group(1)))
|
|
406
|
+
return sorted(pages)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def expand_placeholders(body, manifest, consumer, audit, extract, layouts_text):
|
|
410
|
+
"""body.md 里的 `{{ASSET_TABLE}}` / `{{LAYOUT_LIST}}` 由本脚本按落盘真值渲染——
|
|
411
|
+
路径与页型清单是打包期才确定的事实,不该由 L 层手抄(抄错就是死链)。"""
|
|
412
|
+
if '{{ASSET_TABLE}}' in body:
|
|
413
|
+
rows = ['| 资产 | 文件 | 什么时候用 |', '|---|---|---|']
|
|
414
|
+
src_of = {unquote(a.get('id', '')): a.get('source_media') for a in manifest['assets']}
|
|
415
|
+
for aid, e in consumer.items():
|
|
416
|
+
pages = _pages_of(extract, src_of.get(aid))
|
|
417
|
+
box = (audit.get(aid) or {}).get('boxes') or []
|
|
418
|
+
if e['kind'] == 'background' and e.get('role') == 'cover':
|
|
419
|
+
when = '封面页整幅铺满,必用'
|
|
420
|
+
elif e['kind'] == 'background':
|
|
421
|
+
when = '内容页整幅铺满——哪个页型用哪张见 `layouts.md` 的 `background`'
|
|
422
|
+
elif box:
|
|
423
|
+
b = box[0]
|
|
424
|
+
when = '固定位 (%d, %d),尺寸 %dx%d px' % tuple(b)
|
|
425
|
+
when += (',全 %d 页里只出现在第 %s 页' % (extract['counts']['slides'],
|
|
426
|
+
'、'.join(map(str, pages)))
|
|
427
|
+
if pages and len(pages) <= 4 else ',每页固定放一次')
|
|
428
|
+
else:
|
|
429
|
+
when = '按 `%s` 的语义使用' % e['kind']
|
|
430
|
+
f = '`%s`' % e['path'] if e.get('path') else (
|
|
431
|
+
'`%s`' % e['url'] if e.get('url') else '纯色 `%s`' % e.get('color'))
|
|
432
|
+
if e.get('full'):
|
|
433
|
+
f += '(原图 `%s`)' % e['full']
|
|
434
|
+
rows.append('| `%s` | %s | %s |' % (aid, f, when))
|
|
435
|
+
body = body.replace('{{ASSET_TABLE}}', '\n'.join(rows))
|
|
436
|
+
if '{{LAYOUT_LIST}}' in body:
|
|
437
|
+
rows, sect, names = [], None, {}
|
|
438
|
+
for line in (layouts_text or '').split('\n'):
|
|
439
|
+
if re.match(r'^\w[\w-]*:\s*$', line):
|
|
440
|
+
sect = line.split(':')[0]
|
|
441
|
+
continue
|
|
442
|
+
m = re.match(r'^ ([\w-]+):\s*(.*)$', line)
|
|
443
|
+
if not m:
|
|
444
|
+
m2 = re.match(r'^ name:\s*(.+?)\s*$', line)
|
|
445
|
+
if m2 and rows and rows[-1][1] is None:
|
|
446
|
+
rows[-1][1] = unquote(m2.group(1))
|
|
447
|
+
continue
|
|
448
|
+
if sect == 'names' and m.group(2).strip():
|
|
449
|
+
names[m.group(1)] = unquote(m.group(2))
|
|
450
|
+
elif sect == 'layouts' and not m.group(2).strip():
|
|
451
|
+
rows.append(['- `%s`' % m.group(1), names.get(m.group(1))])
|
|
452
|
+
rows = ['%s —— %s' % (k, n) if n else k for k, n in rows]
|
|
453
|
+
body = body.replace('{{LAYOUT_LIST}}', '\n'.join(rows) or '(无 archetype)')
|
|
454
|
+
return body
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def render_assets_block(consumer):
|
|
458
|
+
out = ['assets:']
|
|
459
|
+
for aid, entry in consumer.items():
|
|
460
|
+
out.append(' %s:' % aid)
|
|
461
|
+
for f in ASSET_CONSUMER_FIELDS:
|
|
462
|
+
if f in entry:
|
|
463
|
+
out.append(' %s: %s' % (f, yaml_scalar(entry[f])))
|
|
464
|
+
return out
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
# ------------------------------------------------- 数值可追溯机检(抄错即 FAIL)
|
|
468
|
+
HEX_RE = re.compile(r'#([0-9A-Fa-f]{6})\b')
|
|
469
|
+
FONTSIZE_RE = re.compile(r'\bfontSize:\s*([\d.]+)px')
|
|
470
|
+
BOX_RE = re.compile(r'\bbox:\s*\[\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*,'
|
|
471
|
+
r'\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\]')
|
|
472
|
+
KEYLINE_RE = re.compile(r'^(\s*)-?\s*([A-Za-z_][\w-]*):\s*(.*)$')
|
|
473
|
+
DOMINANT_TOL = 8 # 采样主色的每通道容差(量化误差天然存在)
|
|
474
|
+
BOX_TOL = 2.0 # slot 坐标逐维容差
|
|
475
|
+
SIZE_TOL = 0.51 # 字号容差(px 取整误差)
|
|
476
|
+
REBASE_TOL = 1.0 # 等比上抬后的字号容差
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def _hex2rgb(h):
|
|
480
|
+
h = h.lstrip('#')
|
|
481
|
+
return int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16)
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
def frontmatter_of(path):
|
|
485
|
+
if not os.path.exists(path):
|
|
486
|
+
return ''
|
|
487
|
+
t = open(path, encoding='utf-8').read()
|
|
488
|
+
parts = t.split('---\n')
|
|
489
|
+
return parts[1] if len(parts) >= 3 else ''
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
def _scan_keyed(text):
|
|
493
|
+
"""逐行产出 (行号, 该行祖先键路径, 行内容),供 token 级豁免定位。"""
|
|
494
|
+
stack = []
|
|
495
|
+
for i, raw in enumerate(text.splitlines(), 1):
|
|
496
|
+
m = KEYLINE_RE.match(raw)
|
|
497
|
+
if m:
|
|
498
|
+
indent = len(m.group(1))
|
|
499
|
+
while stack and stack[-1][0] >= indent:
|
|
500
|
+
stack.pop()
|
|
501
|
+
path = [k for _, k in stack] + [m.group(2)]
|
|
502
|
+
stack.append((indent, m.group(2)))
|
|
503
|
+
yield i, path, raw
|
|
504
|
+
else:
|
|
505
|
+
yield i, [k for _, k in stack], raw
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def build_trace_index(extract, shapes):
|
|
509
|
+
"""可命中集合:色 / 字号 / 形状框。"""
|
|
510
|
+
hexes, dominant = set(), []
|
|
511
|
+
for c in extract.get('color_freq') or []:
|
|
512
|
+
for k in ('resolved', 'hex'):
|
|
513
|
+
v = c.get(k)
|
|
514
|
+
if isinstance(v, str) and v.startswith('#') and len(v) == 7:
|
|
515
|
+
hexes.add(v.upper())
|
|
516
|
+
# 主题 clrScheme 也是普查值:出厂色常被「排除色」条款正面引用(页面频次为 0
|
|
517
|
+
# 恰恰是它要论证的事),不收进来会把这类正确引用误判成抄错。
|
|
518
|
+
for t in extract.get('themes') or []:
|
|
519
|
+
for v in (t.get('clrScheme') or {}).values():
|
|
520
|
+
if isinstance(v, str) and v.startswith('#') and len(v) == 7:
|
|
521
|
+
hexes.add(v.upper())
|
|
522
|
+
|
|
523
|
+
def eat_fill(f):
|
|
524
|
+
if not isinstance(f, dict):
|
|
525
|
+
return
|
|
526
|
+
col = f.get('color') or {}
|
|
527
|
+
for k in ('resolved', 'hex'):
|
|
528
|
+
v = col.get(k) if isinstance(col, dict) else None
|
|
529
|
+
if isinstance(v, str) and v.startswith('#') and len(v) == 7:
|
|
530
|
+
hexes.add(v.upper())
|
|
531
|
+
for st in f.get('stops') or []: # 渐变 stop 色
|
|
532
|
+
eat_fill(st if 'color' in st else {'color': st})
|
|
533
|
+
|
|
534
|
+
for grp in ('slides', 'layouts'):
|
|
535
|
+
for row in extract.get(grp) or []:
|
|
536
|
+
eat_fill(row.get('background'))
|
|
537
|
+
for s in shapes:
|
|
538
|
+
eat_fill(s.get('fill'))
|
|
539
|
+
ln = s.get('line') or {}
|
|
540
|
+
eat_fill(ln)
|
|
541
|
+
eat_fill(ln.get('gradient'))
|
|
542
|
+
for i in extract.get('images') or []:
|
|
543
|
+
for dc in i.get('dominant_colors') or []:
|
|
544
|
+
if dc.get('hex'):
|
|
545
|
+
dominant.append((_hex2rgb(dc['hex']), dc['hex'].upper()))
|
|
546
|
+
|
|
547
|
+
sizes = sorted({e['sz_px'] for e in extract.get('text_scale') or []
|
|
548
|
+
if e.get('sz_px')})
|
|
549
|
+
boxes = []
|
|
550
|
+
for s in shapes:
|
|
551
|
+
b = s.get('box')
|
|
552
|
+
if b and b.get('w') is not None:
|
|
553
|
+
boxes.append((b['x'], b['y'], b['w'], b['h'],
|
|
554
|
+
'%s %s' % (os.path.basename(s['part']), s.get('name') or s['kind'])))
|
|
555
|
+
return {'hexes': hexes, 'dominant': dominant, 'sizes': sizes, 'boxes': boxes}
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
def _hex_hit(value, idx):
|
|
559
|
+
v = value.upper()
|
|
560
|
+
if v in idx['hexes']:
|
|
561
|
+
return True, None
|
|
562
|
+
rgb = _hex2rgb(v)
|
|
563
|
+
best, bestd = None, None
|
|
564
|
+
for drgb, dhex in idx['dominant']:
|
|
565
|
+
d = max(abs(a - b) for a, b in zip(rgb, drgb))
|
|
566
|
+
if d <= DOMINANT_TOL:
|
|
567
|
+
return True, None
|
|
568
|
+
if bestd is None or d < bestd:
|
|
569
|
+
best, bestd = dhex, d
|
|
570
|
+
for h in idx['hexes']:
|
|
571
|
+
d = max(abs(a - b) for a, b in zip(rgb, _hex2rgb(h)))
|
|
572
|
+
if bestd is None or d < bestd:
|
|
573
|
+
best, bestd = h, d
|
|
574
|
+
return False, ('最近 %s(每通道差 %d)' % (best, bestd) if best else '普查里无任何色值')
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
def _size_hit(v, idx, factor):
|
|
578
|
+
for s in idx['sizes']:
|
|
579
|
+
if abs(s - v) <= SIZE_TOL:
|
|
580
|
+
return True, None
|
|
581
|
+
if factor and abs(s * factor - v) <= REBASE_TOL:
|
|
582
|
+
return True, None
|
|
583
|
+
if not idx['sizes']:
|
|
584
|
+
return False, '普查里无字号'
|
|
585
|
+
near = min(idx['sizes'], key=lambda s: abs(s - v))
|
|
586
|
+
tip = '最近 %gpx' % near
|
|
587
|
+
if factor:
|
|
588
|
+
nf = min(idx['sizes'], key=lambda s: abs(s * factor - v))
|
|
589
|
+
tip += ';×%g 后最近 %gpx→%.1f' % (factor, nf, nf * factor)
|
|
590
|
+
return False, tip
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
def _box_hit(box, idx):
|
|
594
|
+
best, bestd = None, None
|
|
595
|
+
for x, y, w, h, tag in idx['boxes']:
|
|
596
|
+
d = max(abs(box[0] - x), abs(box[1] - y), abs(box[2] - w), abs(box[3] - h))
|
|
597
|
+
if d <= BOX_TOL:
|
|
598
|
+
return True, None
|
|
599
|
+
if bestd is None or d < bestd:
|
|
600
|
+
best, bestd = (x, y, w, h, tag), d
|
|
601
|
+
if best is None:
|
|
602
|
+
return False, 'shapes.json 无形状'
|
|
603
|
+
return False, ('最近 [%g, %g, %g, %g](%s,最大维差 %.1fpx)'
|
|
604
|
+
% (best[0], best[1], best[2], best[3], best[4], bestd))
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
def trace_check(pack, extract, shapes, derived_values, derived_tokens, factor):
|
|
608
|
+
"""产物里每个 hex / 字号 / slot 坐标都必须可追溯到普查值或 derived 声明。"""
|
|
609
|
+
idx = build_trace_index(extract, shapes)
|
|
610
|
+
problems, checked = [], Counter()
|
|
611
|
+
targets = [('design.md', frontmatter_of(os.path.join(pack, 'design.md'))),
|
|
612
|
+
('layouts.md', frontmatter_of(os.path.join(pack, 'layouts.md')))]
|
|
613
|
+
for fname, text in targets:
|
|
614
|
+
if not text:
|
|
615
|
+
continue
|
|
616
|
+
for lineno, path, raw in _scan_keyed(text):
|
|
617
|
+
exempt_token = any(k in derived_tokens for k in path)
|
|
618
|
+
for m in HEX_RE.finditer(raw):
|
|
619
|
+
val = '#' + m.group(1).upper()
|
|
620
|
+
checked['hex'] += 1
|
|
621
|
+
if exempt_token or val in derived_values:
|
|
622
|
+
checked['exempt'] += 1
|
|
623
|
+
continue
|
|
624
|
+
ok, tip = _hex_hit(val, idx)
|
|
625
|
+
if not ok:
|
|
626
|
+
problems.append(('hex', fname, lineno, val, tip, '.'.join(path)))
|
|
627
|
+
for m in FONTSIZE_RE.finditer(raw):
|
|
628
|
+
val = float(m.group(1))
|
|
629
|
+
checked['size'] += 1
|
|
630
|
+
if exempt_token or m.group(1) in derived_values:
|
|
631
|
+
checked['exempt'] += 1
|
|
632
|
+
continue
|
|
633
|
+
ok, tip = _size_hit(val, idx, factor)
|
|
634
|
+
if not ok:
|
|
635
|
+
problems.append(('fontSize', fname, lineno, '%gpx' % val, tip,
|
|
636
|
+
'.'.join(path)))
|
|
637
|
+
for m in BOX_RE.finditer(raw):
|
|
638
|
+
box = [float(x) for x in m.groups()]
|
|
639
|
+
checked['box'] += 1
|
|
640
|
+
key = '[%s]' % ', '.join(m.groups())
|
|
641
|
+
if exempt_token or key in derived_values:
|
|
642
|
+
checked['exempt'] += 1
|
|
643
|
+
continue
|
|
644
|
+
ok, tip = _box_hit(box, idx)
|
|
645
|
+
if not ok:
|
|
646
|
+
problems.append(('slot box', fname, lineno,
|
|
647
|
+
'[%g, %g, %g, %g]' % tuple(box), tip, '.'.join(path)))
|
|
648
|
+
return problems, checked
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
def render_audit(manifest, extract, audit):
|
|
652
|
+
L = ['# 审计元数据(从 design.md 剥离,消费模型不需要;机检与人工复核用)']
|
|
653
|
+
src = extract['canvas']['source']
|
|
654
|
+
L.append('canvas-source: {cx: %d, cy: %d, unit: %s}'
|
|
655
|
+
% (src['cx'], src['cy'], src.get('unit', 'EMU')))
|
|
656
|
+
for k in ('theme-mechanism', 'color-confidence'):
|
|
657
|
+
if manifest.get(k):
|
|
658
|
+
L.append('%s: %s' % (k, yaml_scalar(manifest[k])))
|
|
659
|
+
if audit:
|
|
660
|
+
L.append('assets:')
|
|
661
|
+
for aid, au in audit.items():
|
|
662
|
+
L.append(' %s:' % aid)
|
|
663
|
+
if au.get('boxes'):
|
|
664
|
+
L.append(' boxes:')
|
|
665
|
+
for b in au['boxes']:
|
|
666
|
+
L.append(' - [%d, %d, %d, %d]' % tuple(b))
|
|
667
|
+
for f in ('aspect', 'mark', 'confidence'):
|
|
668
|
+
if f in au:
|
|
669
|
+
L.append(' %s: %s' % (f, yaml_scalar(au[f])))
|
|
670
|
+
return '\n'.join(L) + '\n'
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
def _sha256(path):
|
|
674
|
+
h = hashlib.sha256()
|
|
675
|
+
with open(path, 'rb') as f:
|
|
676
|
+
for chunk in iter(lambda: f.read(1024 * 1024), b''):
|
|
677
|
+
h.update(chunk)
|
|
678
|
+
return h.hexdigest()
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
def _rel_files(root):
|
|
682
|
+
files = []
|
|
683
|
+
for dirpath, dirnames, filenames in os.walk(root):
|
|
684
|
+
dirnames.sort()
|
|
685
|
+
for name in sorted(filenames):
|
|
686
|
+
path = os.path.join(dirpath, name)
|
|
687
|
+
files.append(os.path.relpath(path, root))
|
|
688
|
+
return files
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
def build_package_manifest(manifest, consumer, audit, extract, pack):
|
|
692
|
+
"""Machine index for the style package.
|
|
693
|
+
|
|
694
|
+
design.md remains the consumer entry. manifest.json is for storage/control
|
|
695
|
+
planes: stable identity plus file and asset checksums.
|
|
696
|
+
"""
|
|
697
|
+
files = []
|
|
698
|
+
for rel in _rel_files(pack):
|
|
699
|
+
if rel == 'manifest.json':
|
|
700
|
+
continue
|
|
701
|
+
path = os.path.join(pack, rel)
|
|
702
|
+
files.append({
|
|
703
|
+
'path': rel,
|
|
704
|
+
'bytes': os.path.getsize(path),
|
|
705
|
+
'sha256': _sha256(path),
|
|
706
|
+
})
|
|
707
|
+
|
|
708
|
+
assets = []
|
|
709
|
+
for aid, entry in consumer.items():
|
|
710
|
+
item = {'id': aid, 'kind': entry.get('kind')}
|
|
711
|
+
for key in ('role', 'theme', 'on-bg', 'path', 'full', 'url', 'color'):
|
|
712
|
+
if entry.get(key):
|
|
713
|
+
item[key] = entry[key]
|
|
714
|
+
for key in ('path', 'full'):
|
|
715
|
+
rel = entry.get(key)
|
|
716
|
+
if rel:
|
|
717
|
+
path = os.path.join(pack, rel)
|
|
718
|
+
if os.path.exists(path):
|
|
719
|
+
item[key + '_bytes'] = os.path.getsize(path)
|
|
720
|
+
item[key + '_sha256'] = _sha256(path)
|
|
721
|
+
au = audit.get(aid) or {}
|
|
722
|
+
if au.get('confidence'):
|
|
723
|
+
item['confidence'] = au['confidence']
|
|
724
|
+
assets.append(item)
|
|
725
|
+
|
|
726
|
+
files_digest = hashlib.sha256()
|
|
727
|
+
for item in files:
|
|
728
|
+
files_digest.update(item['path'].encode('utf-8'))
|
|
729
|
+
files_digest.update(b'\0')
|
|
730
|
+
files_digest.update(item['sha256'].encode('ascii'))
|
|
731
|
+
files_digest.update(b'\0')
|
|
732
|
+
files_digest.update(str(item['bytes']).encode('ascii'))
|
|
733
|
+
files_digest.update(b'\n')
|
|
734
|
+
|
|
735
|
+
pkg = {
|
|
736
|
+
'schemaVersion': 'pptx-style-package/v2',
|
|
737
|
+
'id': manifest.get('name'),
|
|
738
|
+
'name': manifest.get('name'),
|
|
739
|
+
'name_zh': manifest.get('name_zh'),
|
|
740
|
+
'version': manifest.get('version') or 'alpha',
|
|
741
|
+
'description': manifest.get('description'),
|
|
742
|
+
'entry': 'design.md',
|
|
743
|
+
'layouts': 'layouts.md' if os.path.exists(os.path.join(pack, 'layouts.md')) else None,
|
|
744
|
+
'canvas': '%dx%d' % tuple(extract['canvas']['px']),
|
|
745
|
+
'source': {
|
|
746
|
+
'filename': (extract.get('source') or {}).get('filename'),
|
|
747
|
+
'content_type_kind': (extract.get('source') or {}).get('content_type_kind'),
|
|
748
|
+
'is_template': (extract.get('source') or {}).get('is_template'),
|
|
749
|
+
'bytes': (extract.get('source') or {}).get('bytes'),
|
|
750
|
+
},
|
|
751
|
+
'themes': manifest.get('themes') or ['single'],
|
|
752
|
+
'default_theme': manifest.get('default-theme'),
|
|
753
|
+
'files': files,
|
|
754
|
+
'assets': assets,
|
|
755
|
+
'totals': {
|
|
756
|
+
'file_count': len(files),
|
|
757
|
+
'bytes': sum(f['bytes'] for f in files),
|
|
758
|
+
'sha256': files_digest.hexdigest(),
|
|
759
|
+
'asset_count': len(assets),
|
|
760
|
+
},
|
|
761
|
+
}
|
|
762
|
+
return {k: v for k, v in pkg.items() if v is not None}
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
def layout_fast_index(layouts_blocks, max_slots=4):
|
|
766
|
+
if not layouts_blocks:
|
|
767
|
+
return []
|
|
768
|
+
blocks = {k: (inline, lines) for k, inline, lines in layouts_blocks}
|
|
769
|
+
if 'layouts' not in blocks:
|
|
770
|
+
return []
|
|
771
|
+
items = []
|
|
772
|
+
cur = None
|
|
773
|
+
for line in blocks['layouts'][1]:
|
|
774
|
+
m = re.match(r'^ ([\w-]+):\s*$', line)
|
|
775
|
+
if m:
|
|
776
|
+
cur = {'id': m.group(1), 'name': '', 'role': '', 'background': '', 'slots': []}
|
|
777
|
+
items.append(cur)
|
|
778
|
+
continue
|
|
779
|
+
if not cur:
|
|
780
|
+
continue
|
|
781
|
+
m = re.match(r'^ (name|role|background):\s*(.+?)\s*$', line)
|
|
782
|
+
if m:
|
|
783
|
+
cur[m.group(1)] = unquote(m.group(2))
|
|
784
|
+
continue
|
|
785
|
+
m = re.match(r'^\s{6}-\s*\{(.+)\}\s*$', line)
|
|
786
|
+
if m and len(cur['slots']) < max_slots:
|
|
787
|
+
raw = m.group(1)
|
|
788
|
+
role = re.search(r'role:\s*([^,}]+)', raw)
|
|
789
|
+
box = re.search(r'box:\s*\[([^\]]+)\]', raw)
|
|
790
|
+
typ = re.search(r'type:\s*([^,}]+)', raw)
|
|
791
|
+
if role and box:
|
|
792
|
+
label = unquote(role.group(1).strip())
|
|
793
|
+
if typ:
|
|
794
|
+
label += '/' + unquote(typ.group(1).strip())
|
|
795
|
+
cur['slots'].append('%s [%s]' % (label, box.group(1).strip()))
|
|
796
|
+
out = []
|
|
797
|
+
for item in items:
|
|
798
|
+
parts = ['`%s`' % item['id']]
|
|
799
|
+
if item.get('name'):
|
|
800
|
+
parts.append(item['name'])
|
|
801
|
+
if item.get('role'):
|
|
802
|
+
parts.append(item['role'])
|
|
803
|
+
if item.get('background'):
|
|
804
|
+
parts.append('背景 `%s`' % item['background'])
|
|
805
|
+
slots = ';'.join(item['slots'])
|
|
806
|
+
out.append('%s:%s' % (' / '.join(parts), slots or '按最接近用途套用'))
|
|
807
|
+
return out
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
def render_fast_path(manifest, consumer, has_sidecar, canvas, layouts_index=None):
|
|
811
|
+
"""Render the small consumer-first block that keeps runtime agents out of ref/."""
|
|
812
|
+
cover = next((aid for aid, a in consumer.items()
|
|
813
|
+
if a.get('kind') == 'background' and a.get('role') == 'cover'), None)
|
|
814
|
+
content_bgs = [aid for aid, a in consumer.items()
|
|
815
|
+
if a.get('kind') == 'background' and a.get('role') == 'content']
|
|
816
|
+
logos = [aid for aid, a in consumer.items() if a.get('kind') in ('logo', 'slogan')]
|
|
817
|
+
assets = []
|
|
818
|
+
for aid, a in consumer.items():
|
|
819
|
+
path = a.get('path') or a.get('color') or a.get('url')
|
|
820
|
+
role = a.get('role') or a.get('kind')
|
|
821
|
+
if path:
|
|
822
|
+
assets.append('`%s` -> `%s` (%s)' % (aid, path, role))
|
|
823
|
+
if len(assets) > 8:
|
|
824
|
+
assets = assets[:8] + ['其余资产见 frontmatter `assets`,不要去 `ref/` 里临时挑图。']
|
|
825
|
+
|
|
826
|
+
lines = [
|
|
827
|
+
'## Agent Fast Path',
|
|
828
|
+
'',
|
|
829
|
+
'消费本风格时先读这一节;它是给生成 Agent 的短路径,目标是把风格理解控制在 1 分钟内,避免把审计材料重新理解一遍。',
|
|
830
|
+
'',
|
|
831
|
+
'- **时间预算**:风格导入最多做 1 次 `read_file design.md`。本节已经内联常用坐标,读完后必须直接开始生成,不要再探索风格包。',
|
|
832
|
+
'- **只读入口**:常规生成只需要 `design.md`。只有本节的版式索引无法覆盖目标页时,才打开 %s。'
|
|
833
|
+
% ('`layouts.md`' if has_sidecar else '`design.md` 里的 `layouts`'),
|
|
834
|
+
'- **附件/zip 兜底**:如果当前内容来自 zip 附件的文本摘要,直接使用摘要中 `design.md` / `layouts.md` 的文本;不要尝试修复 zip、解析二进制、搜索附件目录或重建压缩包。',
|
|
835
|
+
'- **禁止动作**:不要读取 `ref/color-freq-raw.json`、`ref/font-clusters.json`、`ref/extract.json`、`ref/rebuild/`、`ref/rebuild/png/*`;不要 summarize / view 参考页;不要重新统计颜色、字体或版式。',
|
|
836
|
+
'- **信息来源优先级**:本节 > `## Usage` > frontmatter `assets` / `colors` / `typography` > `layouts.md`。除此之外的文件只用于人工审计,不用于生成。',
|
|
837
|
+
'- **缺信息时降级**:如果某个细节本节没有写,用 frontmatter token 和最接近的 `layouts.md` archetype 推断;不要打开审计文件补证。',
|
|
838
|
+
]
|
|
839
|
+
if canvas:
|
|
840
|
+
lines.append('- **画布**:所有坐标按 `%dx%d` 绝对像素理解。' % tuple(canvas))
|
|
841
|
+
if cover:
|
|
842
|
+
lines.append('- **封面背景**:优先使用 `%s`;整幅铺满画布,禁止自造渐变替代。' % cover)
|
|
843
|
+
if content_bgs:
|
|
844
|
+
lines.append('- **内容页背景**:按 `layouts.md` 中 archetype 的 `background` 字段取;常用内容背景为 %s。'
|
|
845
|
+
% '、'.join('`%s`' % x for x in content_bgs[:4]))
|
|
846
|
+
if cover or content_bgs:
|
|
847
|
+
lines.append('- **背景安全区**:背景图和版式必须配对。按 archetype 的 `background`、`text_safe`、`avoid` 一起放文字和卡片;标题、正文、关键数字、图表、卡片、时间线及其容器的外接矩形都不得压到背景视觉主体、强光斑、深色透明区上,透明容器也不能跨进禁放区。')
|
|
848
|
+
if logos:
|
|
849
|
+
lines.append('- **标识资产**:只使用 %s;不得重画、不得改比例。'
|
|
850
|
+
% '、'.join('`%s`' % x for x in logos))
|
|
851
|
+
lines += [
|
|
852
|
+
'- **配色与字体**:颜色只取 frontmatter `colors`;字体/字号只取 frontmatter `typography`;内容主题不得引入新色相。',
|
|
853
|
+
'- **版式**:优先使用下面内联版式索引;需要更多 slot 时才读 `layouts.md`;不要用 `ref/rebuild/png` 反推坐标。',
|
|
854
|
+
]
|
|
855
|
+
if layouts_index:
|
|
856
|
+
lines += ['', '内联版式索引(先用这里,不要为了选页型再读文件):']
|
|
857
|
+
lines += ['- ' + x for x in layouts_index]
|
|
858
|
+
if assets:
|
|
859
|
+
lines += ['', '关键资产:']
|
|
860
|
+
lines += ['- ' + a for a in assets]
|
|
861
|
+
lines.append('')
|
|
862
|
+
return '\n'.join(lines) + '\n'
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
def strip_agent_fast_path(body):
|
|
866
|
+
if '## Agent Fast Path' not in body:
|
|
867
|
+
return body
|
|
868
|
+
return re.sub(r'\n?## Agent Fast Path\n.*?(?=\n## |\Z)', '\n', body,
|
|
869
|
+
count=1, flags=re.S).lstrip('\n')
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
def build_design(manifest, l_frontmatter, consumer, body, has_sidecar, canvas,
|
|
873
|
+
layouts_index=None):
|
|
874
|
+
blocks = {k: (inline, lines) for k, inline, lines in l_frontmatter}
|
|
875
|
+
bad = set(blocks) - L_FRONTMATTER_KEYS
|
|
876
|
+
if bad:
|
|
877
|
+
raise Fail('frontmatter.yaml 出现不该由 L 层提供的顶层键: %s'
|
|
878
|
+
'(身份键写 manifest.yaml,assets/layouts 由脚本生成)'
|
|
879
|
+
% ', '.join(sorted(bad)))
|
|
880
|
+
out = ['---']
|
|
881
|
+
for key in FRONTMATTER_ORDER:
|
|
882
|
+
if key in ('version', 'name', 'name_zh', 'description'):
|
|
883
|
+
block = (manifest.get('_raw') or {}).get(key)
|
|
884
|
+
if block:
|
|
885
|
+
out.append('%s:%s' % (key, (' ' + block[0]) if block[0] else ''))
|
|
886
|
+
out += block[1]
|
|
887
|
+
continue
|
|
888
|
+
v = manifest.get(key) or ('alpha' if key == 'version' else None)
|
|
889
|
+
if v:
|
|
890
|
+
out.append('%s: %s' % (key, yaml_scalar(v)))
|
|
891
|
+
elif key in ('themes', 'default-theme'):
|
|
892
|
+
v = manifest.get(key)
|
|
893
|
+
if isinstance(v, list):
|
|
894
|
+
out.append('%s: [%s]' % (key, ', '.join(v)))
|
|
895
|
+
elif v:
|
|
896
|
+
out.append('%s: %s' % (key, yaml_scalar(v)))
|
|
897
|
+
elif key == 'assets':
|
|
898
|
+
if consumer:
|
|
899
|
+
out += render_assets_block(consumer)
|
|
900
|
+
elif key == 'layouts':
|
|
901
|
+
if has_sidecar:
|
|
902
|
+
out.append('layouts: layouts.md')
|
|
903
|
+
elif key in blocks:
|
|
904
|
+
inline, lines = blocks[key]
|
|
905
|
+
out.append('%s:%s' % (key, (' ' + inline) if inline else ''))
|
|
906
|
+
out += lines
|
|
907
|
+
if key == 'exceptions' and not has_sidecar and canvas:
|
|
908
|
+
out.append('canvas: %dx%d' % tuple(canvas))
|
|
909
|
+
out.append('---')
|
|
910
|
+
text = '\n'.join(out) + '\n'
|
|
911
|
+
body = strip_agent_fast_path(body)
|
|
912
|
+
text += '\n' + render_fast_path(manifest, consumer, has_sidecar, canvas,
|
|
913
|
+
layouts_index=layouts_index)
|
|
914
|
+
if body:
|
|
915
|
+
text += body if body.startswith('\n') else '\n' + body
|
|
916
|
+
if not text.endswith('\n'):
|
|
917
|
+
text += '\n'
|
|
918
|
+
return text
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
def build_layouts_md(layouts_blocks, canvas):
|
|
922
|
+
blocks = {k: (inline, lines) for k, inline, lines in layouts_blocks}
|
|
923
|
+
if 'canvas' in blocks:
|
|
924
|
+
raise Fail('layouts.yaml 不要写 canvas —— 脚本从 extract.json 取')
|
|
925
|
+
if 'layouts' not in blocks:
|
|
926
|
+
raise Fail('layouts.yaml 缺顶层键 `layouts:`')
|
|
927
|
+
# `names:` 是给 L 层集中改中文页型名的一块——在这里并回各 archetype,不进产物
|
|
928
|
+
names = {}
|
|
929
|
+
for line in blocks.get('names', ('', []))[1]:
|
|
930
|
+
m = re.match(r'^\s{2}([\w-]+):\s*(.+?)\s*$', line)
|
|
931
|
+
if m:
|
|
932
|
+
names[m.group(1)] = unquote(m.group(2))
|
|
933
|
+
out = ['---', 'canvas: %dx%d' % tuple(canvas), 'layouts:']
|
|
934
|
+
for line in blocks['layouts'][1]:
|
|
935
|
+
out.append(line)
|
|
936
|
+
m = re.match(r'^ ([\w-]+):\s*$', line)
|
|
937
|
+
if m and m.group(1) in names:
|
|
938
|
+
out.append(' name: "%s"' % names.pop(m.group(1)))
|
|
939
|
+
if names:
|
|
940
|
+
raise Fail('names 里这些页型在 layouts 下找不到:%s' % ', '.join(sorted(names)))
|
|
941
|
+
out.append('---')
|
|
942
|
+
text = '\n'.join(out) + '\n'
|
|
943
|
+
if 'body' in blocks:
|
|
944
|
+
body = scalar_of(blocks['body'][0], blocks['body'][1])
|
|
945
|
+
if body:
|
|
946
|
+
text += '\n' + body.rstrip('\n') + '\n'
|
|
947
|
+
return text
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
# --------------------------------------------------------------------- 主流程
|
|
951
|
+
|
|
952
|
+
def _autodetect_check_v1():
|
|
953
|
+
skill_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
954
|
+
for cand in (os.environ.get('DSM_V1_DIR'),
|
|
955
|
+
os.path.join(os.path.dirname(skill_root), 'miaoda-design-system-extract'),
|
|
956
|
+
os.path.expanduser('~/dev/gitlab/miaoda_workspace/.agents/skills/miaoda-design-system-extract')):
|
|
957
|
+
if cand and os.path.isfile(os.path.join(cand, 'scripts', 'check_v1.py')):
|
|
958
|
+
return os.path.join(cand, 'scripts', 'check_v1.py')
|
|
959
|
+
return None
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
def main(argv=None):
|
|
963
|
+
ap = argparse.ArgumentParser(add_help=True)
|
|
964
|
+
ap.add_argument('stage1')
|
|
965
|
+
ap.add_argument('lout')
|
|
966
|
+
ap.add_argument('pack')
|
|
967
|
+
ap.add_argument('--check-v1', default=None, help='check_v1.py 路径;缺省自动探测($DSM_V1_DIR → 同级 skill → 开发机路径)')
|
|
968
|
+
ap.add_argument('--style-name', default=None)
|
|
969
|
+
ap.add_argument('--force', action='store_true')
|
|
970
|
+
args = ap.parse_args(argv)
|
|
971
|
+
|
|
972
|
+
stage1, lout, pack = (os.path.abspath(p) for p in (args.stage1, args.lout, args.pack))
|
|
973
|
+
ex_path = os.path.join(stage1, 'extract.json')
|
|
974
|
+
if not os.path.exists(ex_path):
|
|
975
|
+
raise Fail('找不到 %s' % ex_path)
|
|
976
|
+
extract = json.load(open(ex_path, encoding='utf-8'))
|
|
977
|
+
|
|
978
|
+
need = ['manifest.yaml', 'frontmatter.yaml', 'body.md']
|
|
979
|
+
for f in need:
|
|
980
|
+
if not os.path.exists(os.path.join(lout, f)):
|
|
981
|
+
raise Fail('判断单缺 %s(schema 见本脚本 docstring)' % f)
|
|
982
|
+
if os.path.isdir(pack) and os.listdir(pack) and not args.force:
|
|
983
|
+
raise Fail('%s 非空;加 --force 覆盖' % pack)
|
|
984
|
+
|
|
985
|
+
left = []
|
|
986
|
+
for f in ('manifest.yaml', 'frontmatter.yaml', 'layouts.yaml', 'body.md'):
|
|
987
|
+
p = os.path.join(lout, f)
|
|
988
|
+
if not os.path.exists(p):
|
|
989
|
+
continue
|
|
990
|
+
for i, line in enumerate(open(p, encoding='utf-8'), 1):
|
|
991
|
+
if 'TODO' in line:
|
|
992
|
+
left.append('%s:%d %s' % (f, i, line.strip()[:90]))
|
|
993
|
+
if left:
|
|
994
|
+
raise Fail('判断单还有 %d 处草案占位没改(TODO 是 draft.py 留给 L 层的判断点):\n %s'
|
|
995
|
+
% (len(left), '\n '.join(left)))
|
|
996
|
+
|
|
997
|
+
manifest = read_manifest(os.path.join(lout, 'manifest.yaml'))
|
|
998
|
+
if args.style_name:
|
|
999
|
+
manifest['name'] = args.style_name
|
|
1000
|
+
if not manifest.get('name'):
|
|
1001
|
+
raise Fail('manifest.yaml 缺 name')
|
|
1002
|
+
themes = manifest.get('themes')
|
|
1003
|
+
if isinstance(themes, list) and len(themes) > 1 and not manifest.get('default-theme'):
|
|
1004
|
+
raise Fail('themes 有 %d 个主题,必须给 default-theme(V2-13)' % len(themes))
|
|
1005
|
+
|
|
1006
|
+
l_fm = split_top_blocks(open(os.path.join(lout, 'frontmatter.yaml'),
|
|
1007
|
+
encoding='utf-8').read())
|
|
1008
|
+
body = open(os.path.join(lout, 'body.md'), encoding='utf-8').read()
|
|
1009
|
+
lay_path = os.path.join(lout, 'layouts.yaml')
|
|
1010
|
+
layouts_blocks = (split_top_blocks(open(lay_path, encoding='utf-8').read())
|
|
1011
|
+
if os.path.exists(lay_path) else None)
|
|
1012
|
+
canvas = extract['canvas']['px']
|
|
1013
|
+
|
|
1014
|
+
os.makedirs(pack, exist_ok=True)
|
|
1015
|
+
consumer, audit, copied = place_assets(manifest, extract, stage1, pack)
|
|
1016
|
+
|
|
1017
|
+
lay_text = open(lay_path, encoding='utf-8').read() if os.path.exists(lay_path) else ''
|
|
1018
|
+
body = expand_placeholders(body, manifest, consumer, audit, extract, lay_text)
|
|
1019
|
+
layouts_index = layout_fast_index(layouts_blocks)
|
|
1020
|
+
design = build_design(manifest, l_fm, consumer, body,
|
|
1021
|
+
has_sidecar=layouts_blocks is not None, canvas=canvas,
|
|
1022
|
+
layouts_index=layouts_index)
|
|
1023
|
+
with open(os.path.join(pack, 'design.md'), 'w', encoding='utf-8') as f:
|
|
1024
|
+
f.write(design)
|
|
1025
|
+
if layouts_blocks is not None:
|
|
1026
|
+
with open(os.path.join(pack, 'layouts.md'), 'w', encoding='utf-8') as f:
|
|
1027
|
+
f.write(build_layouts_md(layouts_blocks, canvas))
|
|
1028
|
+
|
|
1029
|
+
ref = os.path.join(pack, 'ref')
|
|
1030
|
+
os.makedirs(ref, exist_ok=True)
|
|
1031
|
+
with open(os.path.join(ref, 'audit.yaml'), 'w', encoding='utf-8') as f:
|
|
1032
|
+
f.write(render_audit(manifest, extract, audit))
|
|
1033
|
+
carried = []
|
|
1034
|
+
for name in REF_CARRY:
|
|
1035
|
+
srcf = os.path.join(stage1, 'ref', name)
|
|
1036
|
+
if os.path.exists(srcf):
|
|
1037
|
+
shutil.copy2(srcf, os.path.join(ref, name))
|
|
1038
|
+
carried.append(name)
|
|
1039
|
+
shutil.copy2(ex_path, os.path.join(ref, 'extract.json'))
|
|
1040
|
+
carried.append('extract.json')
|
|
1041
|
+
for sub in ('rebuild', 'logo-candidates'):
|
|
1042
|
+
s = os.path.join(stage1, 'ref', sub)
|
|
1043
|
+
if os.path.isdir(s):
|
|
1044
|
+
shutil.copytree(s, os.path.join(ref, sub), dirs_exist_ok=True)
|
|
1045
|
+
carried.append(sub + '/')
|
|
1046
|
+
# L 层自备的 ref 补充件(判断理由、版式溯源等)原样带入
|
|
1047
|
+
l_ref = os.path.join(lout, 'ref')
|
|
1048
|
+
if os.path.isdir(l_ref):
|
|
1049
|
+
shutil.copytree(l_ref, ref, dirs_exist_ok=True)
|
|
1050
|
+
carried.append('(L 层 ref/)')
|
|
1051
|
+
|
|
1052
|
+
with open(os.path.join(pack, 'manifest.json'), 'w', encoding='utf-8') as f:
|
|
1053
|
+
json.dump(build_package_manifest(manifest, consumer, audit, extract, pack),
|
|
1054
|
+
f, ensure_ascii=False, indent=2, sort_keys=True)
|
|
1055
|
+
f.write('\n')
|
|
1056
|
+
|
|
1057
|
+
print('pack → %s' % pack)
|
|
1058
|
+
print(' design.md %d 行 / %.1f KB%s'
|
|
1059
|
+
% (len(design.splitlines()), len(design.encode()) / 1024.0,
|
|
1060
|
+
' layouts.md sidecar' if layouts_blocks is not None else ' (layouts 内联/缺省)'))
|
|
1061
|
+
print(' assets %d 条目 / %d 文件落盘' % (len(consumer), len(copied)))
|
|
1062
|
+
for d in copied:
|
|
1063
|
+
print(' %-52s %8d B' % (os.path.relpath(d, pack), os.path.getsize(d)))
|
|
1064
|
+
print(' ref/ %s' % ', '.join(carried))
|
|
1065
|
+
|
|
1066
|
+
# ---- 数值可追溯机检:产物里每个色值/字号/坐标都得能指回普查值
|
|
1067
|
+
derived_values, derived_tokens = set(), set()
|
|
1068
|
+
for d in manifest.get('derived') or []:
|
|
1069
|
+
if d.get('value'):
|
|
1070
|
+
v = unquote(d['value'])
|
|
1071
|
+
derived_values.add(v.upper() if v.startswith('#') else v)
|
|
1072
|
+
if d.get('token'):
|
|
1073
|
+
derived_tokens.add(unquote(d['token']))
|
|
1074
|
+
try:
|
|
1075
|
+
factor = float(manifest.get('rebase_factor') or 0) or None
|
|
1076
|
+
except ValueError:
|
|
1077
|
+
raise Fail('rebase_factor 不是数字: %r' % manifest.get('rebase_factor'))
|
|
1078
|
+
sp = os.path.join(stage1, 'ref', 'shapes.json')
|
|
1079
|
+
shapes = json.load(open(sp, encoding='utf-8'))['shapes'] if os.path.exists(sp) else []
|
|
1080
|
+
problems, checked = trace_check(pack, extract, shapes,
|
|
1081
|
+
derived_values, derived_tokens, factor)
|
|
1082
|
+
print('\n--- 数值可追溯机检 ---')
|
|
1083
|
+
print(' 受检 hex %d / fontSize %d / slot box %d;derived 豁免 %d%s'
|
|
1084
|
+
% (checked['hex'], checked['size'], checked['box'], checked['exempt'],
|
|
1085
|
+
';rebase_factor=%g' % factor if factor else ''))
|
|
1086
|
+
if not shapes:
|
|
1087
|
+
print(' ⚠ 未找到 %s,slot 坐标一项无法校验' % sp)
|
|
1088
|
+
trace_rc = 0
|
|
1089
|
+
if problems:
|
|
1090
|
+
trace_rc = 1
|
|
1091
|
+
print(' FAIL %d 处数值无法追溯(既不命中普查值,也没在 manifest 的 derived 里声明):'
|
|
1092
|
+
% len(problems))
|
|
1093
|
+
for kind, fname, lineno, val, tip, path in problems:
|
|
1094
|
+
print(' %s:%d %s %s ← %s' % (fname, lineno, kind, val, path))
|
|
1095
|
+
print(' %s' % (tip or ''))
|
|
1096
|
+
print(' 修法二选一:改成命中的值,或在 manifest.yaml 的 derived: 段声明推导理由。')
|
|
1097
|
+
else:
|
|
1098
|
+
print(' PASS 全部可追溯')
|
|
1099
|
+
|
|
1100
|
+
rc = trace_rc
|
|
1101
|
+
print('\n--- check_v2 ---')
|
|
1102
|
+
sys.stdout.flush() # 子进程直写 fd,不 flush 会让本脚本的输出排在其后
|
|
1103
|
+
r = subprocess.run([sys.executable, os.path.join(HERE, 'check_v2.py'), pack])
|
|
1104
|
+
rc = rc or r.returncode
|
|
1105
|
+
if not args.check_v1:
|
|
1106
|
+
args.check_v1 = _autodetect_check_v1()
|
|
1107
|
+
if not args.check_v1:
|
|
1108
|
+
print('check_v1: 未探测到($DSM_V1_DIR / 同级 skill / 开发机路径均无)—— v1 门禁未跑,交付前必须补跑')
|
|
1109
|
+
if args.check_v1:
|
|
1110
|
+
print('\n--- check_v1 ---')
|
|
1111
|
+
r1 = subprocess.run([sys.executable, args.check_v1,
|
|
1112
|
+
os.path.join(pack, 'design.md'), 'slide'])
|
|
1113
|
+
rc = rc or r1.returncode
|
|
1114
|
+
if rc:
|
|
1115
|
+
print('\n门禁未过(exit %d)。回修属 L 层的事:改判断单后重跑本脚本。' % rc)
|
|
1116
|
+
return rc
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
if __name__ == '__main__':
|
|
1120
|
+
sys.exit(main())
|