Files
JJOllamaManager/tools/ppt_watch.py
diadmin 9aac2e4143 위키를 표준 AI WIKI 플랫폼 구조로 정리
- 표준 원본(_____AI_WIKI_Platform_std 38f17d7)을 new_project.py --update 방식으로 적용:
  CLAUDE.md, PROJECT.md, .claude/, .obsidian/app.json, tools/, assets/, raw/ 골격,
  wiki/00·02~07·09·99 표준 문서
- 프로젝트 고유 문서는 wiki/10_프로젝트/ 에 둠 (표준 갱신 때 덮어쓰지 않도록)
  - 01_구성_운영환경.md (옛 wiki/00 홈.md)
  - 02_작업현황.md (완료·남은 일)
- wiki/01_사용자지시: 20261103 위키 정리 지시 기록
- .obsidian: webui/ comfyui/ _claude/ jjollamamanager/ 검색 제외
- .gitignore/.gitattributes에 표준 규칙 합침

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HnDmXvY8ekNA8cQwBmcsUE
2026-11-03 08:05:18 +00:00

107 lines
4.7 KiB
Python

"""PPT 변경 감지 → PNG 자동 재생성 → 위키(화면설명.md / 장표설명.md) 자동 반영.
대상: wiki/08_화면/**/*.pptx, wiki/07_제안서/**/*.pptx
사용: python tools/ppt_watch.py (계속 감시, 5초 간격)
python tools/ppt_watch.py --once (한 번만 검사)
변환: Windows = PowerPoint(설치 시) → 없으면 LibreOffice / Mac·Linux = LibreOffice + pdftoppm
필요: pip install python-pptx (Windows PowerPoint 사용 시 pip install pywin32)"""
import sys, os, time, json, hashlib, pathlib, subprocess, shutil, tempfile, datetime, re
ROOT = pathlib.Path(__file__).resolve().parent.parent
TARGETS = [ROOT / "wiki" / "08_화면", ROOT / "wiki" / "07_제안서"]
STATE = ROOT / "tools" / ".ppt_state.json"
KST = datetime.timezone(datetime.timedelta(hours=9))
A, B = "<!-- PPT-AUTO-START -->", "<!-- PPT-AUTO-END -->"
def digest(p):
return hashlib.sha1(p.read_bytes()).hexdigest()
def png_name(pptx, i):
return pptx.with_name(f"{pptx.stem}.png" if i == 1 else f"{pptx.stem}_{i:02d}.png")
def to_png_powerpoint(pptx):
import win32com.client # pywin32
app = win32com.client.Dispatch("PowerPoint.Application")
pres = app.Presentations.Open(str(pptx), WithWindow=False)
try:
for i, s in enumerate(pres.Slides, 1):
s.Export(str(png_name(pptx, i)), "PNG", 1600, 900)
finally:
pres.Close()
def soffice():
for c in ("soffice", "libreoffice", r"C:\Program Files\LibreOffice\program\soffice.exe",
"/Applications/LibreOffice.app/Contents/MacOS/soffice"):
if shutil.which(c) or os.path.exists(c): return shutil.which(c) or c
raise RuntimeError("LibreOffice 가 필요합니다")
def to_png_libreoffice(pptx):
with tempfile.TemporaryDirectory() as t:
subprocess.run([soffice(), "--headless", "--convert-to", "pdf", "--outdir", t, str(pptx)],
check=True, capture_output=True)
pdf = pathlib.Path(t) / f"{pptx.stem}.pdf"
subprocess.run(["pdftoppm", "-png", "-r", "110", str(pdf), str(pathlib.Path(t) / "s")], check=True)
for i, f in enumerate(sorted(pathlib.Path(t).glob("s-*.png")), 1):
shutil.move(str(f), png_name(pptx, i))
def to_png(pptx):
for old in pptx.parent.glob(f"{pptx.stem}*.png"):
old.unlink()
if os.name == "nt":
try:
return to_png_powerpoint(pptx)
except Exception:
pass
to_png_libreoffice(pptx)
def slide_texts(pptx):
from pptx import Presentation
out = []
for i, s in enumerate(Presentation(str(pptx)).slides, 1):
t = [sh.text_frame.text.strip() for sh in s.shapes if sh.has_text_frame and sh.text_frame.text.strip()]
out.append((i, t))
return out
def update_wiki(pptx):
md = pptx.parent / ("화면설명.md" if "08_화면" in pptx.parts else f"{pptx.stem}_장표설명.md")
body = md.read_text(encoding="utf-8") if md.exists() else f"---\nstatus: 초안\n---\n# {pptx.stem}\n"
lines = [A, f"## PPT 내용 (자동 추출 — {pptx.name})"]
for i, t in slide_texts(pptx):
lines.append(f"### 슬라이드 {i}\n![[{png_name(pptx, i).name}]]")
lines += [f"- {x.replace(chr(10), ' / ')}" for x in t]
lines.append(B)
block = "\n".join(lines)
body = re.sub(re.escape(A) + ".*?" + re.escape(B), block, body, flags=re.S) if A in body else body.rstrip() + "\n\n" + block + "\n"
now = datetime.datetime.now(KST)
if "## 수정 이력" not in body:
body += "\n## 수정 이력\n"
body = body.rstrip() + f"\n- {now:%Y-%m-%d %H:%M} PPT 변경 감지 → 이미지·내용 자동 갱신 (검토 필요)\n"
body = re.sub(r"^status:\s*컨펌", "status: 검토중", body, flags=re.M) # 컨펌 후 바뀌면 재검토
md.write_text(body, encoding="utf-8")
def scan(state):
changed = []
for base in TARGETS:
for p in base.rglob("*.pptx"):
if p.name.startswith("~$"): continue
h = digest(p); k = p.relative_to(ROOT).as_posix()
if state.get(k) != h:
try:
to_png(p); update_wiki(p); state[k] = h; changed.append(k)
print("갱신:", k)
except Exception as e:
print("실패:", k, e)
if changed:
STATE.write_text(json.dumps(state, ensure_ascii=False, indent=1), encoding="utf-8")
subprocess.run([sys.executable, str(ROOT / "tools" / "build_menu.py")])
return changed
def main():
state = json.loads(STATE.read_text(encoding="utf-8")) if STATE.exists() else {}
if "--once" in sys.argv:
scan(state); return
print("PPT 감시 중... (Ctrl+C 종료)")
while True:
scan(state); time.sleep(5)
if __name__ == "__main__":
main()