Files
idriz/idriz/printer.py
idriz 78967e15f9 Idriz v0.1: Realtime voice assistant with Wikipedia summaries and coloring pages
- OpenAI Realtime session (server VAD, half-duplex audio via pacat/PipeWire)
- Tools: wikipedia_sazetak (en.wikipedia -> Bosnian summary, max 2 A4 pages via WeasyPrint)
  and bojanka (image generation -> pure line art on A4)
- CUPS printing, systemd user service, install script, offline test script

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LzKpYaEsuWDevuNnvSjcFW
2026-09-02 18:37:39 +02:00

30 lines
1.0 KiB
Python

"""Štampanje preko CUPS-a (lp)."""
import asyncio
import logging
from pathlib import Path
log = logging.getLogger("idriz.printer")
async def print_file(path: Path, printer: str, dry_run: bool = False, fit: bool = True) -> str:
if dry_run:
log.info("DRY RUN: ne štampam %s", path)
return "dry-run"
args = ["lp", "-d", printer, "-o", "media=A4"]
if fit:
args += ["-o", "fit-to-page"]
args.append(str(path))
proc = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
out, err = await proc.communicate()
if proc.returncode != 0:
raise RuntimeError(f"lp greška: {err.decode().strip()}")
job = out.decode().strip()
log.info("poslano na printer: %s", job)
return job
async def printer_ok(printer: str) -> bool:
proc = await asyncio.create_subprocess_exec("lpstat", "-p", printer, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
out, _ = await proc.communicate()
return proc.returncode == 0 and b"disabled" not in out