Claude
Scaffold PPTX/PDF accessibility tools web app
307de64 unverified
Raw History Blame Contribute Delete
2.24 kB
#!/usr/bin/env python3
"""
run.py — single entry point for the PPTX / PDF accessibility tools.
List everything:
python run.py
python run.py --list
Run a tool (everything after the name is passed straight through):
python run.py convert_caps deck.pptx --keep AI API
python run.py clear_pdf_metadata *.pdf
python run.py fix_pdf_lang_tags in.pdf out.pdf --to en-US
Get a tool's own help:
python run.py convert_caps -h
"""
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
TOOLS_DIR = ROOT / "tools"
def discover():
"""Return {name: path} for every tool script, and its one-line summary."""
tools = {}
for script in sorted(TOOLS_DIR.rglob("*.py")):
tools[script.stem] = script
return tools
def summary(path):
"""First non-empty line of the module docstring, for the listing."""
try:
text = path.read_text(encoding="utf-8", errors="replace")
except Exception:
return ""
if '"""' not in text:
return ""
body = text.split('"""', 2)
if len(body) < 2:
return ""
for line in body[1].splitlines():
line = line.strip()
# Skip blanks, the filename line, and decorative divider rows.
if not line or line.endswith(".py"):
continue
if not any(ch.isalnum() for ch in line):
continue
return line
return ""
def print_list(tools):
print("\nAvailable tools (group/name):\n")
for name, path in tools.items():
group = path.parent.name
print(f" {group:5} {name:28} {summary(path)}")
print("\nRun one with: python run.py <name> [args...]")
print("Tool help: python run.py <name> -h\n")
def main():
tools = discover()
args = sys.argv[1:]
if not args or args[0] in ("--list", "-l", "-h", "--help"):
print_list(tools)
return 0
name = args[0]
if name not in tools:
print(f"Unknown tool: {name!r}")
print_list(tools)
return 1
# Forward all remaining args to the target script unchanged.
cmd = [sys.executable, str(tools[name]), *args[1:]]
return subprocess.call(cmd)
if __name__ == "__main__":
raise SystemExit(main())