@sokeai/cli 1.0.116 → 1.0.117
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/skills/multi/demo-init/CHANGELOG.md +1241 -0
- package/skills/multi/demo-init/README.md +137 -0
- package/skills/multi/demo-init/SKILL.legacy.md +307 -0
- package/skills/multi/demo-init/assets/placeholder.pptx +0 -0
- package/skills/multi/demo-init/references/anti-patterns.md +83 -0
- package/skills/multi/demo-init/references/asset-design.md +230 -0
- package/skills/multi/demo-init/references/asset-spec.md +94 -0
- package/skills/multi/demo-init/references/blueprint-schema.md +174 -0
- package/skills/multi/demo-init/references/cli-onboarding.md +207 -0
- package/skills/multi/demo-init/references/cli-shared.md +183 -0
- package/skills/multi/demo-init/references/contracts.md +34 -0
- package/skills/multi/demo-init/references/course-setup.md +265 -0
- package/skills/multi/demo-init/references/demo-defaults.md +132 -0
- package/skills/multi/demo-init/references/demo-verify.md +355 -0
- package/skills/multi/demo-init/references/exam-setup.md +245 -0
- package/skills/multi/demo-init/references/gates-matrix.md +38 -0
- package/skills/multi/demo-init/references/map-setup.md +283 -0
- package/skills/multi/demo-init/references/plan-parse.md +185 -0
- package/skills/multi/demo-init/references/platform-access.md +55 -0
- package/skills/multi/demo-init/references/platform-commands.md +510 -0
- package/skills/multi/demo-init/references/point-setup.md +308 -0
- package/skills/multi/demo-init/references/portal-modules.md +130 -0
- package/skills/multi/demo-init/references/portal-setup.md +342 -0
- package/skills/multi/demo-init/references/project-setup.md +173 -0
- package/skills/multi/demo-init/references/run-protocol.md +208 -0
- package/skills/multi/demo-init/references/taxonomy-setup.md +101 -0
- package/skills/multi/demo-init/scripts/assign_backfill.py +281 -0
- package/skills/multi/demo-init/scripts/blueprint_lint.py +693 -0
- package/skills/multi/demo-init/scripts/blueprint_write.py +390 -0
- package/skills/multi/demo-init/scripts/category_bind.py +303 -0
- package/skills/multi/demo-init/scripts/category_create.py +748 -0
- package/skills/multi/demo-init/scripts/category_reassign.py +405 -0
- package/skills/multi/demo-init/scripts/category_verify.py +373 -0
- package/skills/multi/demo-init/scripts/cli_kit.py +597 -0
- package/skills/multi/demo-init/scripts/cli_probe.py +205 -0
- package/skills/multi/demo-init/scripts/course_build.py +857 -0
- package/skills/multi/demo-init/scripts/course_cover_repair.py +243 -0
- package/skills/multi/demo-init/scripts/doc_lint.py +619 -0
- package/skills/multi/demo-init/scripts/dup_cleanup.py +299 -0
- package/skills/multi/demo-init/scripts/dup_scan.py +368 -0
- package/skills/multi/demo-init/scripts/exam_build.py +551 -0
- package/skills/multi/demo-init/scripts/extract_docx.py +370 -0
- package/skills/multi/demo-init/scripts/gen_assets.py +1366 -0
- package/skills/multi/demo-init/scripts/guard.py +1272 -0
- package/skills/multi/demo-init/scripts/map_rebuild.py +391 -0
- package/skills/multi/demo-init/scripts/oss_image_upload.py +367 -0
- package/skills/multi/demo-init/scripts/portal_build.py +450 -0
- package/skills/multi/demo-init/scripts/portal_home_apply.py +255 -0
- package/skills/multi/demo-init/scripts/portal_home_layout.py +398 -0
- package/skills/multi/demo-init/scripts/project_build.py +309 -0
- package/skills/multi/demo-init/scripts/rebuild_taxonomy_map.py +100 -0
- package/skills/multi/demo-init/scripts/scope_plan.py +387 -0
- package/skills/multi/demo-init/scripts/selftest_all.py +211 -0
- package/skills/multi/demo-init/scripts/stock_probe.py +452 -0
- package/skills/multi/demo-init/scripts/taxonomy_build.py +512 -0
- package/skills/multi/demo-init-4.1.0.zip +0 -0
- package/skills/multi/demo-init-4.1.1.zip +0 -0
- package/skills/multi/demo-init-4.1.2.zip +0 -0
- package/skills/multi/demo-init-4.1.3.zip +0 -0
- package/skills/multi/ziQIJJpL +0 -0
- package/skills/multi/ziRsINis +0 -0
- package/skills/multi/ziUjKWRm +0 -0
- package/skills/multi/zipFWfuj +0 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""category_reassign.py — 已有对象「改挂分类」统一通道(含回读校验)
|
|
4
|
+
|
|
5
|
+
背景(2026-10-21 实测,corp=青岛鸿润):
|
|
6
|
+
· 培训班 : 官方无 update 命令,但底层 `PUT /skills/training_class/update/<uuid>` 可用;
|
|
7
|
+
必须**全量合并**(详情字段回填),只传 path 会把 open_time/班主任等清空。
|
|
8
|
+
· 正式考试: `exam +update-exam --category-path` 可用,但**必须同时传 --title**(老接口要求标题字段)。
|
|
9
|
+
且只能挂「已存在」的考试分类——本账号 `+create-category` 恒 [12000] 无权限。
|
|
10
|
+
· 学习地图: `PUT /skills/learningMap/update/<uuid>` 在本租户**恒返回系统故障**(任意请求体),
|
|
11
|
+
`+update-map --path` 返回 202 但分类不变 —— 结论:地图分类**没有**可靠的事后修改通道,
|
|
12
|
+
必须在 `+create-map --path` 时挂对;已建错的只能重建。
|
|
13
|
+
|
|
14
|
+
用法:
|
|
15
|
+
# 单个对象改挂
|
|
16
|
+
python3 category_reassign.py --tree training_class --object "钉学「90 天新兵营」培训项目" \
|
|
17
|
+
--category "01 新员工培养" --ids-dir ./demo-assets/dx-20261020
|
|
18
|
+
|
|
19
|
+
# 批量(读 category-bindings.json,按对象名匹配)
|
|
20
|
+
python3 category_reassign.py --bindings ./demo-assets/dx-20261020/category-bindings.json \
|
|
21
|
+
--ids-dir ./demo-assets/dx-20261020 --trees training_class,exam
|
|
22
|
+
|
|
23
|
+
# 只核对不回写
|
|
24
|
+
python3 category_reassign.py --bindings ... --ids-dir ... --verify-only
|
|
25
|
+
"""
|
|
26
|
+
import argparse
|
|
27
|
+
import json
|
|
28
|
+
import os
|
|
29
|
+
import re
|
|
30
|
+
import shutil
|
|
31
|
+
import subprocess
|
|
32
|
+
import sys
|
|
33
|
+
|
|
34
|
+
# CLI 路径解析:环境变量 → 常见安装位 → PATH 兜底(⛔ 不写死任何人的家目录)
|
|
35
|
+
CLI_CANDIDATES = [
|
|
36
|
+
os.environ.get("SOKE_CLI", ""),
|
|
37
|
+
os.path.expanduser("~/.npm-global/bin/soke-cli"),
|
|
38
|
+
"/usr/local/bin/soke-cli",
|
|
39
|
+
"/opt/homebrew/bin/soke-cli",
|
|
40
|
+
os.path.expanduser("~/.workbuddy/binaries/node/cli-connector-packages/bin/soke-cli"),
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def resolve_cli() -> str:
|
|
45
|
+
"""返回可执行的 soke-cli 路径;全候选落空时退回裸名,由调用处报错。"""
|
|
46
|
+
for cand in CLI_CANDIDATES:
|
|
47
|
+
if cand and os.path.isfile(cand) and os.access(cand, os.X_OK):
|
|
48
|
+
return cand
|
|
49
|
+
return shutil.which("soke-cli") or "soke-cli"
|
|
50
|
+
|
|
51
|
+
# 培训班 update 必须回填的可写字段(少传一个就丢一个,实测 open_time/head_teacher 会被清空)
|
|
52
|
+
TC_WRITABLE = [
|
|
53
|
+
"title", "path", "module", "open_time", "end_time", "is_new",
|
|
54
|
+
"head_teacher", "training_object", "undertaking_dept", "description",
|
|
55
|
+
"picture", "mobile_picture", "pc_picture", "activity_pictures",
|
|
56
|
+
"allow_enroll", "allow_enroll_start_time", "allow_enroll_end_time",
|
|
57
|
+
"allow_external", "enroll_check", "eligible_type", "class_eligible_rules",
|
|
58
|
+
"points_rules", "open_schedule", "is_public", "custom_public",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
TREE_LABEL = {"training_class": "培训班", "exam": "正式考试", "learning_map": "学习地图"}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# ---------------------------------------------------------------- CLI 调用层
|
|
65
|
+
class Cli:
|
|
66
|
+
def __init__(self, path, debug=False):
|
|
67
|
+
self.path = path
|
|
68
|
+
self.debug = debug
|
|
69
|
+
|
|
70
|
+
def run(self, args, timeout=180):
|
|
71
|
+
p = subprocess.run([self.path] + args, capture_output=True, text=True, timeout=timeout)
|
|
72
|
+
return p.returncode, p.stdout or "", p.stderr or ""
|
|
73
|
+
|
|
74
|
+
def json(self, args, timeout=180):
|
|
75
|
+
rc, out, err = self.run(args, timeout)
|
|
76
|
+
obj = parse_json(out)
|
|
77
|
+
if not obj:
|
|
78
|
+
return {"_error": (err or out or "")[:200], "_rc": rc}
|
|
79
|
+
obj["_rc"] = rc
|
|
80
|
+
return obj
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def parse_json(txt):
|
|
84
|
+
"""跳过升级 banner/框线,取第一个合法 JSON 对象"""
|
|
85
|
+
dec = json.JSONDecoder()
|
|
86
|
+
for i, ch in enumerate(txt):
|
|
87
|
+
if ch != "{":
|
|
88
|
+
continue
|
|
89
|
+
try:
|
|
90
|
+
obj, _ = dec.raw_decode(txt[i:])
|
|
91
|
+
except Exception:
|
|
92
|
+
continue
|
|
93
|
+
if isinstance(obj, dict) and ("code" in obj or "data" in obj):
|
|
94
|
+
return obj
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def rows_of(d):
|
|
99
|
+
d = d.get("data", d)
|
|
100
|
+
if isinstance(d, list):
|
|
101
|
+
return d
|
|
102
|
+
for k in ("list", "all", "info"):
|
|
103
|
+
v = d.get(k) if isinstance(d, dict) else None
|
|
104
|
+
if isinstance(v, list):
|
|
105
|
+
return v
|
|
106
|
+
if isinstance(v, dict):
|
|
107
|
+
for k2 in ("all", "list"):
|
|
108
|
+
if isinstance(v.get(k2), list):
|
|
109
|
+
return v[k2]
|
|
110
|
+
return []
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def nz(s):
|
|
114
|
+
return re.sub(r"\s+", "", str(s or ""))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# ---------------------------------------------------------------- 对象/分类解析
|
|
118
|
+
def find_category(cli, tree, name):
|
|
119
|
+
"""按名称找分类 uuid(同名取第一个),返回 (uuid, 平台名) 或 (None, None)"""
|
|
120
|
+
if tree == "training_class":
|
|
121
|
+
rs = rows_of(cli.json(["training-class", "+category-list", "--format", "json"]))
|
|
122
|
+
elif tree == "learning_map":
|
|
123
|
+
rs = rows_of(cli.json(["learning-map", "+list-categories", "--page-size", "100", "--format", "json"]))
|
|
124
|
+
elif tree == "exam":
|
|
125
|
+
rs = rows_of(cli.json(["exam", "+list-categories", "--page-size", "100", "--format", "json"]))
|
|
126
|
+
else:
|
|
127
|
+
return None, None
|
|
128
|
+
want = nz(name)
|
|
129
|
+
for r in rs:
|
|
130
|
+
if nz(r.get("title")) == want:
|
|
131
|
+
return r.get("uuid"), r.get("title")
|
|
132
|
+
return None, None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def find_object(cli, tree, name):
|
|
136
|
+
"""按标题找对象 uuid(同名取最新),返回 (uuid, 平台名, extra)"""
|
|
137
|
+
want = nz(name)
|
|
138
|
+
if tree == "training_class":
|
|
139
|
+
for st in ("0", "1"):
|
|
140
|
+
rs = rows_of(cli.json(["training-class", "+list", "--status", st,
|
|
141
|
+
"--page-size", "100", "--format", "json"]))
|
|
142
|
+
for r in rs:
|
|
143
|
+
if nz(r.get("title")) == want:
|
|
144
|
+
return r.get("uuid"), r.get("title"), {"status": r.get("status")}
|
|
145
|
+
elif tree == "exam":
|
|
146
|
+
rs = rows_of(cli.json(["exam", "+list-exams", "--page-size", "100", "--format", "json"]))
|
|
147
|
+
for r in rs:
|
|
148
|
+
if nz(r.get("title")) == want:
|
|
149
|
+
return r.get("exam_id") or r.get("uuid"), r.get("title"), {}
|
|
150
|
+
elif tree == "learning_map":
|
|
151
|
+
# 列表接口在本租户不稳,靠 ids 文件
|
|
152
|
+
return None, None, {}
|
|
153
|
+
return None, None, {}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def read_detail(cli, tree, uuid):
|
|
157
|
+
if tree == "training_class":
|
|
158
|
+
d = cli.json(["training-class", "+get", "--id", uuid, "--format", "json"])
|
|
159
|
+
return (d.get("data") or {}).get("info") or {}
|
|
160
|
+
if tree == "exam":
|
|
161
|
+
d = cli.json(["exam", "+get-exam", "--exam-id", uuid, "--format", "json"])
|
|
162
|
+
return (d.get("data") or {}).get("info") or {}
|
|
163
|
+
if tree == "learning_map":
|
|
164
|
+
d = cli.json(["learning-map", "+detail", "--uuid", uuid, "--format", "json"])
|
|
165
|
+
return (d.get("data") or {}).get("info") or {}
|
|
166
|
+
return {}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def read_category(cli, tree, uuid):
|
|
170
|
+
"""回读对象当前分类 (id, title)"""
|
|
171
|
+
if tree == "training_class":
|
|
172
|
+
for st in ("0", "1"):
|
|
173
|
+
for r in rows_of(cli.json(["training-class", "+list", "--status", st,
|
|
174
|
+
"--page-size", "100", "--format", "json"])):
|
|
175
|
+
if r.get("uuid") == uuid:
|
|
176
|
+
cid = r.get("category_id")
|
|
177
|
+
return (None if cid in ("empty", "", None) else cid), r.get("category_title")
|
|
178
|
+
elif tree == "exam":
|
|
179
|
+
for r in rows_of(cli.json(["exam", "+list-exams", "--page-size", "100", "--format", "json"])):
|
|
180
|
+
if (r.get("exam_id") or r.get("uuid")) == uuid:
|
|
181
|
+
return r.get("category_id"), r.get("category_title")
|
|
182
|
+
elif tree == "learning_map":
|
|
183
|
+
info = read_detail(cli, tree, uuid)
|
|
184
|
+
return info.get("category_id"), info.get("category_title")
|
|
185
|
+
return None, None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# ---------------------------------------------------------------- 写侧三通道
|
|
189
|
+
def build_tc_body(detail, path_uuid):
|
|
190
|
+
body = {}
|
|
191
|
+
for k in TC_WRITABLE:
|
|
192
|
+
if k in detail:
|
|
193
|
+
body[k] = detail[k]
|
|
194
|
+
body["path"] = [path_uuid]
|
|
195
|
+
body.setdefault("module", detail.get("module") or 2)
|
|
196
|
+
body.setdefault("title", detail.get("title"))
|
|
197
|
+
return body
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def reassign(cli, tree, uuid, cat_uuid, detail, dry_run=False):
|
|
201
|
+
"""返回 (ok, note)"""
|
|
202
|
+
if tree == "training_class":
|
|
203
|
+
body = build_tc_body(detail, cat_uuid)
|
|
204
|
+
if dry_run:
|
|
205
|
+
return True, "DRY PUT /skills/training_class/update/%s body_keys=%d" % (uuid[:8], len(body))
|
|
206
|
+
rc, out, err = cli.run(["api", "PUT", "/skills/training_class/update/" + uuid,
|
|
207
|
+
"--data", json.dumps(body, ensure_ascii=False)])
|
|
208
|
+
got = parse_json(out) or {}
|
|
209
|
+
if str(got.get("code")) not in ("200", "201", "202"):
|
|
210
|
+
return False, "update 失败: %s" % (str(got.get("message") or err or out)[:80])
|
|
211
|
+
return True, "PUT ok"
|
|
212
|
+
|
|
213
|
+
if tree == "exam":
|
|
214
|
+
title = detail.get("title") or ""
|
|
215
|
+
args = ["exam", "+update-exam", "--exam-id", uuid, "--category-path",
|
|
216
|
+
json.dumps([cat_uuid]), "--title", title, "--format", "json"]
|
|
217
|
+
if dry_run:
|
|
218
|
+
return True, "DRY exam update title=%s" % title[:16]
|
|
219
|
+
got = cli.json(args)
|
|
220
|
+
if str(got.get("code")) not in ("200", "201", "202"):
|
|
221
|
+
return False, "update 失败: %s" % str(got.get("message") or got.get("_error"))[:80]
|
|
222
|
+
return True, "update ok"
|
|
223
|
+
|
|
224
|
+
if tree == "learning_map":
|
|
225
|
+
args = ["learning-map", "+update-map", "--uuid", uuid, "--path", cat_uuid, "--format", "json"]
|
|
226
|
+
if dry_run:
|
|
227
|
+
return True, "DRY learning-map update-map --path"
|
|
228
|
+
got = cli.json(args)
|
|
229
|
+
if str(got.get("code")) not in ("200", "201", "202"):
|
|
230
|
+
return False, "update-map 失败: %s" % str(got.get("message") or got.get("_error"))[:80]
|
|
231
|
+
return True, "update-map 已提交(需回读确认是否生效)"
|
|
232
|
+
|
|
233
|
+
return False, "不支持的树: %s" % tree
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
# ---------------------------------------------------------------- 主流程
|
|
237
|
+
def plan_items(args, cli):
|
|
238
|
+
"""产出 [(tree, object_name, category_name)]"""
|
|
239
|
+
items = []
|
|
240
|
+
if args.bindings:
|
|
241
|
+
bp = json.load(open(args.bindings, encoding="utf-8"))
|
|
242
|
+
for grp, tree in (("classes", "training_class"), ("exams", "exam"), ("maps", "learning_map")):
|
|
243
|
+
if args.trees and tree not in args.trees:
|
|
244
|
+
continue
|
|
245
|
+
for r in bp.get(grp) or []:
|
|
246
|
+
if r.get("category"):
|
|
247
|
+
items.append((tree, r["name"], r["category"]))
|
|
248
|
+
if args.object and args.category:
|
|
249
|
+
items.append((args.tree, args.object, args.category))
|
|
250
|
+
return items
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def resolve_uuid(cli, tree, name, ids_dir):
|
|
254
|
+
uuid, title, extra = find_object(cli, tree, name)
|
|
255
|
+
if uuid:
|
|
256
|
+
return uuid, title
|
|
257
|
+
# 退回 ids 文件
|
|
258
|
+
if not ids_dir:
|
|
259
|
+
return None, None
|
|
260
|
+
f = {"training_class": "project-ids.json", "exam": "exam-ids.json",
|
|
261
|
+
"learning_map": "map-ids.json"}[tree]
|
|
262
|
+
p = os.path.join(ids_dir, f)
|
|
263
|
+
if not os.path.exists(p):
|
|
264
|
+
return None, None
|
|
265
|
+
d = json.load(open(p, encoding="utf-8"))
|
|
266
|
+
pool = d.get("projects") or d.get("exams") or d.get("maps") or []
|
|
267
|
+
for it in pool:
|
|
268
|
+
if nz(it.get("name")) == nz(name):
|
|
269
|
+
return it.get("uuid") or it.get("exam_id") or it.get("map_id"), it.get("name")
|
|
270
|
+
return None, None
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def main(argv=None):
|
|
274
|
+
ap = argparse.ArgumentParser()
|
|
275
|
+
ap.add_argument("--cli", default=None, help="soke-cli 路径(默认按 SOKE_CLI/PATH 自动解析)")
|
|
276
|
+
ap.add_argument("--tree", choices=list(TREE_LABEL), default="training_class")
|
|
277
|
+
ap.add_argument("--object", help="对象标题")
|
|
278
|
+
ap.add_argument("--category", help="目标分类标题")
|
|
279
|
+
ap.add_argument("--bindings", help="category-bindings.json")
|
|
280
|
+
ap.add_argument("--ids-dir", help="*-ids.json 所在目录")
|
|
281
|
+
ap.add_argument("--trees", help="逗号分隔,限定处理哪些树")
|
|
282
|
+
ap.add_argument("--dry-run", action="store_true")
|
|
283
|
+
ap.add_argument("--verify-only", action="store_true")
|
|
284
|
+
ap.add_argument("--self-test", action="store_true")
|
|
285
|
+
ap.add_argument("--out", default="")
|
|
286
|
+
args = ap.parse_args(argv)
|
|
287
|
+
|
|
288
|
+
if args.self_test:
|
|
289
|
+
return self_test()
|
|
290
|
+
|
|
291
|
+
if args.trees:
|
|
292
|
+
args.trees = [t.strip() for t in args.trees.split(",") if t.strip()]
|
|
293
|
+
|
|
294
|
+
cli = Cli(args.cli or resolve_cli())
|
|
295
|
+
items = plan_items(args, cli)
|
|
296
|
+
if not items:
|
|
297
|
+
print("没有待处理项:给 --bindings 或 --object/--category")
|
|
298
|
+
return 2
|
|
299
|
+
|
|
300
|
+
results, stats = [], {"moved": 0, "already": 0, "failed": 0, "unsupported": 0, "skipped": 0}
|
|
301
|
+
for tree, obj_name, cat_name in items:
|
|
302
|
+
uuid, title = resolve_uuid(cli, tree, obj_name, args.ids_dir)
|
|
303
|
+
if not uuid:
|
|
304
|
+
print(" ✗ %-30s 找不到对象" % obj_name[:30])
|
|
305
|
+
stats["failed"] += 1
|
|
306
|
+
results.append({"tree": tree, "object": obj_name, "status": "object_missing"})
|
|
307
|
+
continue
|
|
308
|
+
cat_uuid, cat_title = find_category(cli, tree, cat_name)
|
|
309
|
+
if not cat_uuid:
|
|
310
|
+
print(" ✗ %-30s 找不到分类「%s」" % (obj_name[:30], cat_name))
|
|
311
|
+
stats["failed"] += 1
|
|
312
|
+
results.append({"tree": tree, "object": obj_name, "status": "category_missing",
|
|
313
|
+
"category": cat_name})
|
|
314
|
+
continue
|
|
315
|
+
|
|
316
|
+
cur_id, cur_title = read_category(cli, tree, uuid)
|
|
317
|
+
if cur_id == cat_uuid:
|
|
318
|
+
print(" = %-30s 已在「%s」" % (obj_name[:30], cat_title))
|
|
319
|
+
stats["already"] += 1
|
|
320
|
+
results.append({"tree": tree, "object": obj_name, "uuid": uuid,
|
|
321
|
+
"category_id": cat_uuid, "status": "already"})
|
|
322
|
+
continue
|
|
323
|
+
|
|
324
|
+
if args.verify_only:
|
|
325
|
+
print(" ! %-30s 当前「%s」≠ 目标「%s」" % (obj_name[:30], cur_title or "空", cat_title))
|
|
326
|
+
stats["failed"] += 1
|
|
327
|
+
results.append({"tree": tree, "object": obj_name, "uuid": uuid,
|
|
328
|
+
"status": "mismatch", "actual": cur_title, "want": cat_title})
|
|
329
|
+
continue
|
|
330
|
+
|
|
331
|
+
detail = read_detail(cli, tree, uuid)
|
|
332
|
+
ok, note = reassign(cli, tree, uuid, cat_uuid, detail, args.dry_run)
|
|
333
|
+
if not ok:
|
|
334
|
+
print(" ✗ %-30s %s" % (obj_name[:30], note))
|
|
335
|
+
stats["failed"] += 1
|
|
336
|
+
results.append({"tree": tree, "object": obj_name, "uuid": uuid,
|
|
337
|
+
"status": "failed", "note": note})
|
|
338
|
+
continue
|
|
339
|
+
|
|
340
|
+
if args.dry_run:
|
|
341
|
+
print(" ~ %-30s → 「%s」(预演)" % (obj_name[:30], cat_title))
|
|
342
|
+
stats["moved"] += 1
|
|
343
|
+
continue
|
|
344
|
+
|
|
345
|
+
new_id, new_title = read_category(cli, tree, uuid)
|
|
346
|
+
if new_id == cat_uuid:
|
|
347
|
+
print(" ✓ %-30s → 「%s」" % (obj_name[:30], new_title or cat_title))
|
|
348
|
+
stats["moved"] += 1
|
|
349
|
+
results.append({"tree": tree, "object": obj_name, "uuid": uuid,
|
|
350
|
+
"category_id": cat_uuid, "status": "moved"})
|
|
351
|
+
else:
|
|
352
|
+
status = "unsupported" if tree == "learning_map" else "unverified"
|
|
353
|
+
print(" ! %-30s 回读仍为「%s」→ %s" % (obj_name[:30], new_title or "空", status))
|
|
354
|
+
stats["unsupported" if status == "unsupported" else "failed"] += 1
|
|
355
|
+
results.append({"tree": tree, "object": obj_name, "uuid": uuid,
|
|
356
|
+
"status": status, "actual": new_title, "want": cat_title})
|
|
357
|
+
|
|
358
|
+
print("\n分类改挂:%d 个对象 | 已改 %d / 本来正确 %d / 失败 %d / 通道不可用 %d"
|
|
359
|
+
% (len(items), stats["moved"], stats["already"], stats["failed"], stats["unsupported"]))
|
|
360
|
+
|
|
361
|
+
if args.out:
|
|
362
|
+
with open(args.out, "w", encoding="utf-8") as fh:
|
|
363
|
+
json.dump({"stats": stats, "results": results}, fh, ensure_ascii=False, indent=2)
|
|
364
|
+
print("明细已写入 %s" % args.out)
|
|
365
|
+
|
|
366
|
+
return 0 if stats["failed"] == 0 else 1
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
# ---------------------------------------------------------------- 自检
|
|
370
|
+
def self_test():
|
|
371
|
+
ok = True
|
|
372
|
+
|
|
373
|
+
def chk(cond, msg):
|
|
374
|
+
nonlocal ok
|
|
375
|
+
print((" PASS " if cond else " FAIL ") + msg)
|
|
376
|
+
ok = ok and bool(cond)
|
|
377
|
+
|
|
378
|
+
print("self-test: 培训班 update 体构造")
|
|
379
|
+
detail = {"title": "X班", "open_time": "2026-01-01 00:00:00", "end_time": "2026-02-01 00:00:00",
|
|
380
|
+
"head_teacher": '{"u":"n"}', "training_object": "{}", "undertaking_dept": "{}",
|
|
381
|
+
"module": 2, "is_new": 0, "points_rules": '{"a":"5"}', "junk_field": "别传"}
|
|
382
|
+
body = build_tc_body(detail, "CAT-UUID")
|
|
383
|
+
chk(body["path"] == ["CAT-UUID"], "path 写入数组")
|
|
384
|
+
chk(body["open_time"] == detail["open_time"] and body["head_teacher"] == detail["head_teacher"],
|
|
385
|
+
"开班时间/班主任被回填(不全量会丢)")
|
|
386
|
+
chk("junk_field" not in body, "白名单外字段不外传")
|
|
387
|
+
|
|
388
|
+
print("self-test: JSON 容错解析")
|
|
389
|
+
banner = "╭────────╮\n│ 🎉 发现新版本 │\n╰────────╯\n{\"code\":\"200\",\"data\":{\"list\":[1]}}"
|
|
390
|
+
chk(parse_json(banner).get("code") == "200", "跳过 banner 取到 JSON")
|
|
391
|
+
chk(parse_json("no json here") is None, "无 JSON 返回 None")
|
|
392
|
+
|
|
393
|
+
print("self-test: 行提取")
|
|
394
|
+
chk(rows_of({"data": {"list": {"all": [{"a": 1}]}}}) == [{"a": 1}], "list.all 嵌套")
|
|
395
|
+
chk(rows_of({"data": [{"a": 1}]}) == [{"a": 1}], "data 直接是数组")
|
|
396
|
+
|
|
397
|
+
print("self-test: 名称归一")
|
|
398
|
+
chk(nz(" 01 新员工 ") == "01新员工", "空白归一用于比名")
|
|
399
|
+
|
|
400
|
+
print("\n%d 项检查,%s" % (5, "全部通过" if ok else "有失败"))
|
|
401
|
+
return 0 if ok else 1
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
if __name__ == "__main__":
|
|
405
|
+
sys.exit(main())
|