CloudLab CI/CD / 门禁 doctor (push) Failing after 44s
CloudLab CI/CD / 单元测试 (push) Skipped
CloudLab CI/CD / 归档完整性 (push) Skipped
CloudLab CI/CD / 构建站点与归档 (push) Skipped
CloudLab CI/CD / 部署到 lab.hdtime.space(rsync) (push) Skipped
CloudLab CI/CD / 构建镜像并推送 Gitea 容器仓库 (push) Skipped
CloudLab CI/CD / 容器部署到 lab.hdtime.space (push) Skipped
CloudLab CI/CD / 发布版本(Tag) (push) Skipped
分类体系:自建 14 类学科树(A 总论 / B 化学 / C 分子生物学 / D 遗传 / E 细胞微生物 / F 人体医学 / G 生信 / H 实验方法 / I 计算模拟 / J 法规伦理 / K 教材 / L 文献 / M 数据 / Z 工程资产),带分类号与索书号 底层上架:生命科学资料库 19 个 00–18 编号目录 → 学科码前缀目录, 书架按分类号相邻排列;同步重建 files.json / external-sources.json / 去重跳转页 / 门户目录说明;path-aliases.json + CL.resolvePath() 保证 收藏 / 书签 / 外部旧链接不失效 编目:catalog.json 全量 3456 条(学科/主题/索书号/架位), 2163 条上架,1293 条 AtomLab 运行时数据与源码归 Z 原位保留 (前端 3D 与构建脚本按固定路径加载,移动会失效) 翻阅:图书馆默认「学科书架」视图 + 学科大厅分类指示牌 + 二级主题架; 保留「目录」与「文件格式」视图可切换;面包屑显示学科 入库规范:docs/编目规范.md + tools/classify_new.py(新资料自动给分类号 与目标架位),后续搜集按同一分类 验证:不变量 216/FAIL 0、21 个 UI 测试全绿(新 ui_subject 16/16) Co-Authored-By: WorkBuddy <noreply@workbuddy.ai>
75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""新资料入库:按 CloudLab 学科分类给出分类号与目标上架目录。
|
||
|
||
用法:
|
||
python3 tools/classify_new.py "CRISPR 脱靶评估.pdf"
|
||
python3 tools/classify_new.py "生命科学资料库/新资料.pdf" --into
|
||
python3 tools/classify_new.py --list # 查看学科表
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import argparse
|
||
import json
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||
from library_catalog import SUBJECTS, RENAME, subject_of, ROOT, APP, LIB # noqa: E402
|
||
|
||
SHELF_DIRS = sorted({v for v in RENAME.values()})
|
||
|
||
|
||
def suggest(name: str) -> dict:
|
||
code, topic, on_shelf = subject_of(name)
|
||
subj = next((s for s in SUBJECTS if s[0] == code), SUBJECTS[0])
|
||
if code == "Z":
|
||
target = "(原位保留,不参与上架)"
|
||
else:
|
||
match = [d for d in SHELF_DIRS if d.startswith(code) and d.split("-", 1)[-1] == topic]
|
||
if not match:
|
||
match = [d for d in SHELF_DIRS if d.startswith(code)]
|
||
target = f"生命科学资料库/{match[0]}" if match else f"生命科学资料库/{code}1-{topic}"
|
||
return {
|
||
"name": name, "subject": code, "subject_name": subj[1],
|
||
"topic": topic, "target_dir": target, "on_shelf": on_shelf,
|
||
"callno_prefix": code,
|
||
}
|
||
|
||
|
||
def main():
|
||
ap = argparse.ArgumentParser()
|
||
ap.add_argument("name", nargs="?", help="新资料文件名或标题")
|
||
ap.add_argument("--list", action="store_true", help="列出学科分类表")
|
||
ap.add_argument("--into", action="store_true", help="把文件移动到建议目录(谨慎)")
|
||
args = ap.parse_args()
|
||
if args.list:
|
||
for c, n, d in SUBJECTS:
|
||
print(f" {c} {n:<12s} {d}")
|
||
return
|
||
if not args.name:
|
||
ap.error("请给出文件名或标题,或使用 --list")
|
||
r = suggest(args.name)
|
||
print(json.dumps(r, ensure_ascii=False, indent=2))
|
||
if args.into:
|
||
src = ROOT / args.name
|
||
if not src.exists():
|
||
print("文件不存在,未移动", file=sys.stderr)
|
||
return
|
||
if r["target_dir"].startswith("("):
|
||
print("工程资产不上架,未移动", file=sys.stderr)
|
||
return
|
||
dst_dir = ROOT / r["target_dir"]
|
||
dst_dir.mkdir(parents=True, exist_ok=True)
|
||
dst = dst_dir / src.name
|
||
if dst.exists():
|
||
print("目标已存在同名文件,未移动", file=sys.stderr)
|
||
return
|
||
src.rename(dst)
|
||
print(f"已上架 → {dst.relative_to(ROOT)}")
|
||
print("请运行:python3 tools/library_catalog.py --catalog-only && python3 cloudlab.py snapshot")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|