68 lines
2.9 KiB
Python
68 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
||||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""handoff-status.py — 一条命令看清 05-交接单 里哪些单子【待执行】/【已完成】/【无状态】。
|
|||
|
|
|
|||
|
|
为什么需要它:`05-交接单/交接单-已完成/` 那层目录摊平后,**"目录位置"不再表达状态**。
|
|||
|
|
状态改由**机读字段**承载(与布局解耦,摊平/搬家都不失效):
|
|||
|
|
① 单子头部 `- 状态:…` 行(模板已有)→ ② 回退取 `05-交接单/README.md` 台账表的「状态」列
|
|||
|
|
|
|||
|
|
用法:python 07-scripts/handoff-status.py
|
|||
|
|
"""
|
|||
|
|
import os
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||
|
|
D = os.path.join(ROOT, "05-交接单")
|
|||
|
|
README = os.path.join(D, "README.md")
|
|||
|
|
|
|||
|
|
HEAD_STATUS = re.compile(r"^[\s>*\-|#]*\*{0,2}状态\*{0,2}\s*[::]\s*(.+?)\s*$", re.M)
|
|||
|
|
DONE_KW = ("已完成", "已落地", "已归档", "已收口", "已闭合", "已实施", "已上线",
|
|||
|
|
"已修复", "已释放", "已结束", "已通过", "全部完成", "全绿", "✅")
|
|||
|
|
WAIT_KW = ("待执行", "待开工", "进行中", "在途", "待验证", "待跑", "规划中", "未开工",
|
|||
|
|
"部分执行", "受阻", "未做", "设计定稿", "🔄", "⏳", "⏸", "🟡")
|
|||
|
|
|
|||
|
|
table = {}
|
|||
|
|
if os.path.exists(README):
|
|||
|
|
with open(README, encoding="utf-8") as fh:
|
|||
|
|
for line in fh:
|
|||
|
|
if not line.startswith("|"):
|
|||
|
|
continue
|
|||
|
|
cells = [c.strip() for c in line.strip().strip("|").split("|")]
|
|||
|
|
if len(cells) < 2 or ".md" not in cells[0]:
|
|||
|
|
continue
|
|||
|
|
table[cells[0].strip("`").split("/")[-1].strip()] = cells[1]
|
|||
|
|
|
|||
|
|
groups = {"待执行": [], "已完成": [], "无状态": []}
|
|||
|
|
targets = []
|
|||
|
|
for root2, dirs2, _f in os.walk(D):
|
|||
|
|
dirs2[:] = [x for x in dirs2 if not x.startswith(".")]
|
|||
|
|
for f2 in _f:
|
|||
|
|
if f2.endswith(".md") and f2 != "README.md" and not f2.startswith("."):
|
|||
|
|
rel = os.path.relpath(os.path.join(root2, f2), D).replace("\\", "/")
|
|||
|
|
targets.append((rel, os.path.join(root2, f2)))
|
|||
|
|
for n, path in sorted(targets):
|
|||
|
|
base = n.split("/")[-1]
|
|||
|
|
with open(path, encoding="utf-8", errors="ignore") as fh:
|
|||
|
|
head = "".join(fh.readlines()[:30])
|
|||
|
|
m = HEAD_STATUS.search(head)
|
|||
|
|
if m:
|
|||
|
|
s, src = m.group(1)[:44], "头部"
|
|||
|
|
elif base in table:
|
|||
|
|
s, src = table[base][:44], "台账表"
|
|||
|
|
else:
|
|||
|
|
s, src = "", ""
|
|||
|
|
if not s:
|
|||
|
|
groups["无状态"].append((n, "—"))
|
|||
|
|
elif any(k in s for k in DONE_KW):
|
|||
|
|
groups["已完成"].append((n, "%s ·%s" % (s, src)))
|
|||
|
|
elif any(k in s for k in WAIT_KW):
|
|||
|
|
groups["待执行"].append((n, "%s ·%s" % (s, src)))
|
|||
|
|
else:
|
|||
|
|
groups["无状态"].append((n, "%s ·%s未识别" % (s, src)))
|
|||
|
|
|
|||
|
|
for g in ("待执行", "已完成", "无状态"):
|
|||
|
|
print("【%s】%d 个" % (g, len(groups[g])))
|
|||
|
|
for n, s in groups[g]:
|
|||
|
|
print(" %-44s %s" % (n[:44], s))
|
|||
|
|
print()
|
|||
|
|
print("合计 %d 个单子(不含 README.md)" % sum(len(v) for v in groups.values()))
|