121 lines
3.6 KiB
Python
121 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Управление статусами проекта в ops/STATUS.md.
|
|
|
|
status.py list — показать статусы
|
|
status.py check <ID> — проверить, что ID существует
|
|
status.py set <ID> <статус> — сменить статус (✅ 🔄 ⏳ ⛔)
|
|
status.py add <ID> <раздел> <задача> <приоритет>
|
|
"""
|
|
import re
|
|
import sys
|
|
|
|
STATUS = "/root/buryan-infra/ops/STATUS.md"
|
|
ICONS = {"done": "✅", "wip": "🔄", "todo": "⏳", "blocked": "⛔"}
|
|
|
|
|
|
def read():
|
|
try:
|
|
return open(STATUS, encoding="utf-8").read()
|
|
except Exception:
|
|
return ""
|
|
|
|
|
|
def write(text):
|
|
open(STATUS, "w", encoding="utf-8").write(text)
|
|
|
|
|
|
def rows(text):
|
|
"""Все строки таблиц с ID вида X-01."""
|
|
out = []
|
|
for line in text.splitlines():
|
|
if re.match(r"^\|\s*[A-Z]+-\d+\s*\|", line):
|
|
out.append(line)
|
|
return out
|
|
|
|
|
|
def has_id(text, ident):
|
|
return re.search(rf"\|\s*{re.escape(ident)}\s*\|", text) is not None
|
|
|
|
|
|
def cmd_check(ident):
|
|
text = read()
|
|
if has_id(text, ident):
|
|
print(f"ok: {ident} найден")
|
|
return 0
|
|
print(f"ОШИБКА: {ident} нет в ops/STATUS.md — сначала добавьте задачу")
|
|
return 1
|
|
|
|
|
|
def cmd_list():
|
|
text = read()
|
|
for line in rows(text):
|
|
print(line.strip())
|
|
|
|
|
|
def cmd_set(ident, state):
|
|
icon = ICONS.get(state.lower(), state)
|
|
text = read()
|
|
lines = text.splitlines()
|
|
changed = False
|
|
for i, line in enumerate(lines):
|
|
if re.match(rf"^\|\s*{re.escape(ident)}\s*\|", line):
|
|
parts = line.split("|")
|
|
# статус — третья колонка (индекс 3 для | # | задача | статус |)
|
|
if len(parts) > 4:
|
|
parts[3] = f" {icon} "
|
|
lines[i] = "|".join(parts)
|
|
changed = True
|
|
break
|
|
if not changed:
|
|
print(f"не найдено: {ident}")
|
|
return 1
|
|
write("\n".join(lines) + "\n")
|
|
print(f"{ident} → {icon}")
|
|
return 0
|
|
|
|
|
|
def cmd_add(ident, section, task, prio="средний"):
|
|
text = read()
|
|
if has_id(text, ident):
|
|
print("уже есть")
|
|
return 0
|
|
marker = f"## {section}"
|
|
if marker not in text:
|
|
text = text.rstrip() + f"\n\n{marker}\n\n| # | Задача | Статус | Приоритет |\n|---|---|---|---|\n"
|
|
new_row = f"| {ident} | {task} | ⏳ | {prio} |"
|
|
lines = text.splitlines()
|
|
insert_at = None
|
|
in_section = False
|
|
for i, line in enumerate(lines):
|
|
if line.strip() == marker:
|
|
in_section = True
|
|
continue
|
|
if in_section:
|
|
if line.startswith("## "):
|
|
insert_at = i
|
|
break
|
|
if line.startswith("|") and not line.startswith("|---") and "Задача" not in line:
|
|
insert_at = i + 1
|
|
if insert_at is None:
|
|
insert_at = len(lines)
|
|
lines.insert(insert_at, new_row)
|
|
write("\n".join(lines) + "\n")
|
|
print(f"добавлено: {new_row}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 2:
|
|
cmd_list()
|
|
elif sys.argv[1] == "list":
|
|
cmd_list()
|
|
elif sys.argv[1] == "check" and len(sys.argv) > 2:
|
|
sys.exit(cmd_check(sys.argv[2]))
|
|
elif sys.argv[1] == "set" and len(sys.argv) > 3:
|
|
sys.exit(cmd_set(sys.argv[2], sys.argv[3]))
|
|
elif sys.argv[1] == "add" and len(sys.argv) > 4:
|
|
sys.exit(cmd_add(sys.argv[2], sys.argv[3], sys.argv[4],
|
|
sys.argv[5] if len(sys.argv) > 5 else "средний"))
|
|
else:
|
|
print(__doc__)
|