Files

36 lines
1.7 KiB
Python

import os as _os, sys as _sys
_w = _os.path.dirname(_os.path.abspath(__file__))
while _w != "/" and not _os.path.isdir(_os.path.join(_w, "hand")):
_w = _os.path.dirname(_w)
WURZEL = _w
for _u in ("lesen", "entscheiden", "hand", "lobby", "korpus", "betrieb", "mock"):
_q = _os.path.join(_w, _u)
if _os.path.isdir(_q) and _q not in _sys.path:
_sys.path.insert(0, _q)
import json, os, select, subprocess, sys, time
S = os.path.expanduser("~/Projects/pokerfreak-shell")
p = subprocess.Popen(["bash", os.path.join(S, "run.sh")], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, bufsize=1, cwd=S)
def send(o): p.stdin.write(json.dumps(o) + "\n"); p.stdin.flush()
def read(sek=30):
ende = time.time() + sek
while time.time() < ende:
if select.select([p.stdout], [], [], 0.3)[0]:
z = p.stdout.readline()
if z.strip():
try: return json.loads(z)
except Exception: return {"raw": z[:200]}
return None
def call(nr, name, args=None):
send({"jsonrpc":"2.0","id":nr,"method":"tools/call","params":{"name":name,"arguments":args or {}}})
a = read() or {}
inhalt = ((a.get("result") or {}).get("content") or [{}])
text = inhalt[0].get("text", "")
if not text and a.get("error"): text = "FEHLER: " + json.dumps(a["error"])[:200]
print(f"\n### {name} -> {text[:420]}")
send({"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"p","version":"1"}}})
read(15); send({"jsonrpc":"2.0","method":"notifications/initialized","params":{}})
for nr, name in enumerate(["tables","korpus","close_all_tables","status"], start=2):
call(nr, name)
p.terminate()