probe.py (3968B)
1 # This file is part of GNU Taler 2 # (C) 2026 Taler Systems S.A. 3 # 4 # GNU Taler is free software; you can redistribute it and/or modify it under the 5 # terms of the GNU General Public License as published by the Free Software 6 # Foundation; either version 3, or (at your option) any later version. 7 # 8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 10 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 # 12 # You should have received a copy of the GNU General Public License along with 13 # GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 14 """One action, then a dump. This is how labels get discovered. 15 16 python3 probe.py just dump 17 python3 probe.py tap 'Connect' tap a label and dump 18 python3 probe.py goto history open a drawer destination 19 python3 probe.py drawer open the navigation drawer 20 python3 probe.py uri 'taler-pos://.' deliver a setup URI 21 python3 probe.py nfc what is published over NFC 22 python3 probe.py dialog read the modal on screen 23 python3 probe.py shot /tmp/a.png screenshot 24 python3 probe.py log 80 the terminal's own log lines 25 26 An ad-hoc probe must name its serial, or it interferes with a running round: 27 `POS_WORKER=4 python3 probe.py ...`, or POS_SERIAL for the serial itself. 28 """ 29 30 from __future__ import annotations 31 32 import os 33 import sys 34 import time 35 36 from device import Device, serial_for 37 from pos import Pos 38 39 40 def serial() -> str: 41 return serial_for() 42 43 44 def main(argv: list[str]) -> int: 45 dev = Device(serial()) 46 app = Pos(dev) 47 cmd = argv[0] if argv else "dump" 48 arg = argv[1] if len(argv) > 1 else None 49 50 if cmd == "tap" and arg: 51 app.tap_button(arg) 52 elif cmd == "goto" and arg: 53 app.goto(arg) 54 elif cmd == "drawer": 55 app.open_drawer() 56 elif cmd == "uri" and arg: 57 dev.setup_uri(arg) 58 time.sleep(4) 59 elif cmd == "back": 60 dev.back() 61 time.sleep(1.5) 62 elif cmd == "scroll": 63 dev.scroll(down=(arg != "up"), screen=dev.dump()) 64 time.sleep(1.5) 65 elif cmd == "type" and arg: 66 screen = dev.dump() 67 fields = screen.editable() 68 if not fields: 69 print("no editable field on screen") 70 return 1 71 dev.clear_field(fields[0], screen) 72 dev.type_text(arg) 73 time.sleep(1) 74 elif cmd == "nfc": 75 print(f"nfc payload: {dev.report_nfc_payload()}") 76 return 0 77 elif cmd == "dialog": 78 print(f"dialog: {app.read_dialog()}") 79 return 0 80 elif cmd == "shot": 81 dev.screenshot(arg or "/tmp/pos-probe.png") 82 print(f"wrote {arg or '/tmp/pos-probe.png'}") 83 return 0 84 elif cmd == "log": 85 log = dev.logcat(lines=int(arg or 120)) 86 for line in log.splitlines(): 87 if any(t in line for t in ("taler-pos", "ConfigManager", "ConfigFragment", 88 "PaymentManager", "HistoryManager", 89 "RefundManager", "OrderManager", "PosSimHooks", 90 "AndroidRuntime", "taler-wallet-hce")): 91 print(line) 92 return 0 93 elif cmd != "dump": 94 print(__doc__) 95 return 2 96 97 screen = dev.dump() 98 print(f"activity: {screen.activity}") 99 print(f"window: {dev.size()}") 100 print(f"nodes: {len(screen.nodes)} labelled: {len(screen.labelled())} " 101 f"tappable: {len(screen.tappable())} editable: {len(screen.editable())}") 102 print(screen) 103 anonymous = screen.unnamed_clickables() 104 if anonymous: 105 print(f"-- {len(anonymous)} clickable(s) with no accessible name:") 106 for node in anonymous: 107 print(f" {node}") 108 return 0 109 110 111 if __name__ == "__main__": 112 sys.exit(main(sys.argv[1:]))