23 lines
1.1 KiB
Python
23 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""layer raw|wiki nos .md do Dev (código: docs=wiki, efémeros/testes/samples=raw)."""
|
|
import sys,re
|
|
from pathlib import Path
|
|
ROOT=Path("/media/ealmeida/Dados/Dev"); DRY="--dry-run" in sys.argv
|
|
EXCL_DIR=re.compile(r'/(node_modules|\.git|venv|\.venv|vendor|dist|build|site-packages|__pycache__|target|3rdparty)/')
|
|
RAW=re.compile(r'(worklog|/logs?/|sess[aã]o|di[aá]rio|checkup|deep-research|/fontes?/|pesquisa|/tests?/|/__tests__/|/fixtures?/|/examples?/|/samples?/|/test-data/|/\.cache/|CHANGELOG-old|reuni[aã]o)', re.I)
|
|
add=0
|
|
for f in ROOT.rglob("*.md"):
|
|
s=str(f)
|
|
if EXCL_DIR.search(s) or any(p.startswith(".") for p in f.parts): continue
|
|
if f.name in ("index.md","log.md"): continue
|
|
try: t=f.read_text(encoding="utf-8")
|
|
except: continue
|
|
if not t.startswith("---"): continue
|
|
e=t.find("\n---",3)
|
|
if e<0: continue
|
|
if re.search(r'^layer:',t[3:e],re.M): continue
|
|
layer = "raw" if RAW.search(s) else "wiki"
|
|
if not DRY: f.write_text(t[:e]+f"\nlayer: {layer}"+t[e:],encoding="utf-8")
|
|
add+=1
|
|
print(f"{'[DRY] ' if DRY else ''}layer adicionado: {add}")
|