testsAndMisc/linux_configuration/misc/tools/_transcribe_progress.py
Krzysztof kuhy Rudnicki 08aac8d7d1 Flatten i3-configuration and misc/testsAndMisc-bash
i3 config was filed under periodic_background, which it never was. It is
now linux_configuration/i3/ (config + installer) and
linux_configuration/i3blocks/ (the status scripts), both at depth 2.

misc/testsAndMisc-bash/ was a directory named after the repo it already
lived in, so its contents moved up to misc/. Its stray .gitignore came
along, keeping the media rules working from the new location; its
.vscode/tasks.json did not, because it invoked Bash/transcribe.sh, a path
this repo dropped long ago.

Most of this commit is the references the previous flatten missed. Its
regex skipped anything with a variable prefix, which left 16 files --
including check_and_enable_services.sh and install_core_system.sh, the
orchestrators -- still naming $CONFIG_DIR/scripts/periodic_background/...
It had also rewritten three i3 paths into scripts/i3blocks/, a directory
that has never existed; the i3blocks suites caught that by failing.

13 more symlinks broke on the i3 move. Repointed, and cpu_monitor/volume/
disk were run again to confirm the bar still reports.

Depth 139 -> 104. Roughly 47 of the remainder sit in digital_wellbeing
and hosts, still deferred. The rest encode real structure -- a C project,
Python package directories, artgate's routes/styles, systemd unit dirs --
so flattening them further would destroy information rather than
taxonomy.

Verified: 1798 tests at 100%, both i3blocks suites pass, the shell
coverage gate is clean, and the relocated media rules still ignore what
they should while test_fw.srt stays tracked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 19:02:18 +02:00

92 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""Live progress reporting for transcribe_fw.
``_format_progress_line`` is pure - seconds processed plus media duration in,
a display string out - which is what makes the percentage clamp and the ETA
testable without loading a model.
"""
from __future__ import annotations
import logging
import sys
import time
from typing import TYPE_CHECKING, Any
from _transcribe_output import hhmmss
if TYPE_CHECKING:
import argparse
logger = logging.getLogger(__name__)
_PROGRESS_THROTTLE_SEC = 0.2
_SECONDS_PER_DAY = 60 * 60 * 24
def _run_progress_loop(
args: argparse.Namespace,
model: object,
inp: str,
total_duration: float | None,
) -> tuple[list[Any], object]:
"""Transcribe with live progress output."""
start_ts = time.time()
iter_segments, info = model.transcribe(inp, language=args.language)
collected: list[Any] = []
processed = 0.0
last_prt = 0.0
tty = sys.stderr.isatty()
for seg in iter_segments:
collected.append(seg)
if getattr(seg, "end", None) is not None:
processed = max(processed, float(seg.end))
now = time.time()
if not args.no_progress and (tty or (now - last_prt) >= _PROGRESS_THROTTLE_SEC):
last_prt = now
line = _format_progress_line(
processed,
total_duration,
now,
start_ts,
)
if tty:
logger.info("\r%s", line)
else:
logger.info("%s", line)
if not args.no_progress and tty:
logger.info("")
return collected, info
def _format_progress_line(
processed: float,
total_duration: float | None,
now: float,
start_ts: float,
) -> str:
"""Format a progress line string."""
if total_duration and total_duration > 0:
pct = max(
0.0,
min(
100.0,
(processed / total_duration) * 100.0,
),
)
elapsed = now - start_ts
line = (
f"[PROGRESS] {hhmmss(processed)} / {hhmmss(total_duration)} ({pct:5.1f}%)"
)
if processed > 0:
rate = processed / max(1e-6, elapsed)
remaining = max(0.0, total_duration - processed)
eta = remaining / max(1e-6, rate)
if eta < _SECONDS_PER_DAY:
line += f" ETA ~{hhmmss(eta)}"
return line
return f"[PROGRESS] processed {hhmmss(processed)}"