testsAndMisc/python_pkg/token_dashboard/gitcmd.py
Krzysztof kuhy Rudnicki 1ba202c567
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
token_dashboard: ingester core + detail tables (calls, marks, turn_detail, ab_rows) for the control-panel dashboard
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JThjboXTeZ3yJPBzxMx5wS
2026-10-18 14:45:06 +02:00

30 lines
797 B
Python

"""One way to run git for the dashboard: absolute binary, bounded, never raises."""
from __future__ import annotations
import shutil
import subprocess
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pathlib import Path
GIT = shutil.which("git") or "/usr/bin/git"
TIMEOUT_S = 30
def run(repo: str | Path, *args: str, stdin: str | None = None) -> str | None:
"""``git -C repo args``: stdout, or ``None`` on any failure."""
try:
done = subprocess.run(
[GIT, "-C", str(repo), *args],
input=stdin,
capture_output=True,
text=True,
check=False,
timeout=TIMEOUT_S,
)
except OSError, subprocess.TimeoutExpired:
return None
return done.stdout if done.returncode == 0 else None