#!/usr/bin/env python3 """Interactive pty driver for the tudor_cli enrollment/verification flow. Spawns tudor_cli under a pseudo-terminal so its prompts work. Streams all output and forwards stdin so the session can be driven interactively: - type commands directly, or - pass "auto" as first arg to send an enroll command automatically. """ import os import pty import select import sys import time BUILD = "/home/nebulon/projects/fingerprint/work/synaTudor/build" CLI = os.path.join(BUILD, "cli", "tudor_cli") DATASTORE = "/home/nebulon/projects/fingerprint/work/debug/datastore.bin" MODE = sys.argv[1] if len(sys.argv) > 1 else "interactive" os.chdir(BUILD) pid, fd = pty.fork() if pid == 0: os.execv(CLI, [CLI, DATASTORE]) buf = b"" sent_setup = False init_deadline = time.time() + 240 while True: r, _, _ = select.select([fd, sys.stdin], [], [], 1.0) if sys.stdin in r: data = os.read(sys.stdin.fileno(), 4096) if data: os.write(fd, data) if fd in r: try: data = os.read(fd, 4096) except OSError: break if not data: break buf += data sys.stdout.write(data.decode("utf-8", "replace")) sys.stdout.flush() text = buf.decode("utf-8", "replace") if MODE == "auto" and not sent_setup and "> " in text: sent_setup = True time.sleep(0.5) os.write(fd, b"e\n") time.sleep(0.5) os.write(fd, b"1\n") time.sleep(0.5) os.write(fd, b"1\n") print("\n=== auto-enroll input sent; touch the sensor ===") sys.stdout.flush() if not sent_setup and MODE == "auto" and time.time() > init_deadline: print("\n=== init timed out ===") break try: os.close(fd) except OSError: pass os.waitpid(pid, 0) print("\n=== session ended ===")