testsAndMisc/python_pkg/morning_routine/_orchestrator.py
Krzysztof kuhy Rudnicki e9ba82ed66
Some checks are pending
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
Put the kuhy credit on every python_pkg CLI
Twelve interactive CLIs end their --help on credit_line() from
kuhy-credit v0.3.1 (android_ui, workout_firebase_flow, app_icons,
archwiki_rag, artgate, code_tutor, js_anki, morning_routine,
phone_lease, random_jpg, sql_drills, vscode_optimizer). The repo has
no GUI, web app or game, so --help is the only surface.

morning_routine's unit runs /usr/bin/python, so its install.sh now
installs the requirements.txt pin there. Stdio/daemon entry points
stay without it; the evidence file lists each with the reason.

Also bumps Flutter to 3.50.1 and the stale Python pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 10:17:38 +01:00

84 lines
2.5 KiB
Python

"""Run the morning workout lock, started at the phone's alarm time.
This used to sequence two fullscreen Tk windows: the PC wake alarm first, then
the workout screen lock. The PC no longer wakes anyone -- the phone does, and
`wake_alarm._alarm` has been deleted -- so there is only one leg left and no
collision left to prevent.
What still points here: `wake-alarm-trigger.timer` ticks every minute and
starts `morning-routine.service` at the synced alarm time
(`wake_alarm._constants.TRIGGER_TARGET_UNIT`). Keeping this indirection means
that unit name stays true, and the workout lock keeps its own gates.
``screen_locker`` is pip-installed into system Python's user site-packages by
its own install.sh, so ``python -m <module>`` resolves it with no extra
``PYTHONPATH``/``cwd`` plumbing here.
Usage:
python -m python_pkg.morning_routine._orchestrator
"""
from __future__ import annotations
import argparse
import logging
import subprocess
import sys
from kuhy_credit import credit_line
from python_pkg.shared.logging_setup import configure_logging
_logger = logging.getLogger(__name__)
# Modules invoked as ``python -m <module> --production``.
WORKOUT_LOCK_MODULE: str = "screen_locker.screen_lock"
def _run_module(module: str) -> int:
"""Run *module* as a blocking ``python -m`` subprocess in production mode.
Args:
module: Dotted module path to execute with ``python -m``.
Returns:
The subprocess exit code, or ``1`` when the process could not start.
"""
cmd = [sys.executable, "-m", module, "--production"]
_logger.info("morning-routine: running %s", module)
try:
result = subprocess.run(cmd, check=False)
except OSError:
_logger.warning("Failed to run %s", module, exc_info=True)
return 1
return result.returncode
def _run_workout_lock() -> int:
"""Run the workout screen lock after the alarm has been dealt with."""
return _run_module(WORKOUT_LOCK_MODULE)
def _parse_args(argv: list[str]) -> argparse.Namespace:
"""Parse CLI arguments for the orchestrator."""
parser = argparse.ArgumentParser(
description="Unified morning routine.", epilog=credit_line()
)
parser.add_argument(
"--production",
action="store_true",
help="Production mode (kept for systemd/CLI symmetry).",
)
return parser.parse_args(argv)
def main() -> None:
"""Entry point: run the workout lock."""
configure_logging()
_parse_args(sys.argv[1:])
_run_workout_lock()
if __name__ == "__main__":
main()