mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-22 17:42:18 +01:00
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.6 KiB
Python
Executable File
72 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
r"""Export what the emulator phone published to the Firebase RTDB emulator.
|
|
|
|
The emulator live checks (a ``bypass`` reaching "the test backend") use a
|
|
probe build that syncs to the PC's RTDB emulator instead of prod
|
|
(``phone_app/lib/services/sync_emulator.dart``). This reads it back exactly
|
|
the way the PC reads prod -- ``_sync_transport._read_published``: device
|
|
discovery plus the E2E unlock -- and writes the ``[[device_id, alarm], ...]``
|
|
list that ``python -m wake_alarm._fallback --dry-run --published`` takes.
|
|
|
|
Run it with ``HOME`` set to a scratch directory whose
|
|
``.config/crdt-sync/password`` holds the dummy test passphrase the AVD was
|
|
given, so the real passphrase is never read, and with
|
|
``PYTHONUSERBASE=/home/kuhy/.local`` so ``crdt_sync`` still imports::
|
|
|
|
HOME=$SCRATCH PYTHONUSERBASE=$HOME/.local \\
|
|
/usr/bin/python3 scripts/emu_published.py http://127.0.0.1:9000 out.json
|
|
|
|
``crdt_sync`` is imported unguarded on purpose: the transport degrades a
|
|
missing module to "nothing published", which here would read as a failed
|
|
check instead of a broken setup.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
from crdt_sync import (
|
|
FirebaseSyncClient,
|
|
FirebaseTokenProvider,
|
|
MemoryCredentialStore,
|
|
)
|
|
|
|
from wake_alarm._sync_transport import _read_published
|
|
|
|
|
|
class _OwnerToken(FirebaseTokenProvider):
|
|
"""The emulator's admin token; the RTDB emulator accepts ``auth=owner``.
|
|
|
|
Never signs in: no API key, an empty store, and ``id_token`` overridden.
|
|
"""
|
|
|
|
def __init__(self) -> None:
|
|
"""A provider with nothing to refresh."""
|
|
super().__init__("", MemoryCredentialStore())
|
|
|
|
def id_token(self) -> str:
|
|
"""Every request's ``auth`` parameter."""
|
|
return "owner"
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
"""Write the emulator's published logs to the output file; 1 when empty."""
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument("url", help="the RTDB emulator's origin")
|
|
parser.add_argument("out", type=Path, help="where to write the JSON list")
|
|
args = parser.parse_args(argv)
|
|
client = FirebaseSyncClient(args.url, _OwnerToken())
|
|
published = _read_published(client)
|
|
pairs = [[device, json.loads(raw)] for device, raw in published]
|
|
args.out.write_text(json.dumps(pairs, indent=1), encoding="utf-8")
|
|
devices = " ".join(device for device, _ in pairs)
|
|
sys.stdout.write(f"{len(pairs)} device(s): {devices}\n")
|
|
return 0 if pairs else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|