`./receipt.py serve` (receipt_web.py, the new [web] extra) serves a page for printing a note or an uploaded image. The site's nginx gates /receipt/ on the admin session and proxies to it over Tailscale, adding X-Receipt-Token; nothing but /healthz answers without it, and POSTs also need X-Requested-With: receipt. Jobs run one at a time behind a lock around run_action(), and uploads print from memory. run_action(), _dispatch() and setup_network_quiet() move from the TUI to receipt.py so the server doesn't need textual. --no-setup (needs_setup()) skips the sudo connect script everywhere it would run; serve always sets it. cmd_print takes in-memory `data`. deploy/ has the systemd user units. receipt-update.timer runs update.sh every 5 minutes: it fast-forwards the clone from Gitea, runs the tests and restarts receipt-web, rolling back if they fail. Also included from earlier uncommitted work: the CI matrix moved to the right place, connect_receipt.sh no longer re-parses CLI values in bash -c, RECEIPT_PRINTER_IP/PORT are validated, pyusb is declared, the ruff S rules are on, and the img/ cache and junk/ are no longer tracked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
39 lines
858 B
Python
39 lines
858 B
Python
"""Shared test fakes."""
|
|
|
|
import argparse
|
|
|
|
|
|
class FakePrinter:
|
|
"""Records escpos calls instead of talking to hardware."""
|
|
|
|
def __init__(self):
|
|
self.calls = []
|
|
|
|
def textln(self, text=""):
|
|
self.calls.append(("textln", text))
|
|
|
|
def image(self, img, **kwargs):
|
|
self.calls.append(("image", img))
|
|
|
|
def qr(self, content, **kwargs):
|
|
self.calls.append(("qr", content))
|
|
|
|
def cut(self):
|
|
self.calls.append(("cut", None))
|
|
|
|
def close(self):
|
|
self.calls.append(("close", None))
|
|
|
|
|
|
def make_args(**overrides):
|
|
defaults = {
|
|
"usb": True, # avoids the network setup script in tests
|
|
"ip": "192.168.192.168",
|
|
"port": 9100,
|
|
"timestamp": False,
|
|
"message": None,
|
|
"name": None,
|
|
}
|
|
defaults.update(overrides)
|
|
return argparse.Namespace(**defaults)
|