owenrusk.dev

casebench

test cases straight onto the board.

git clone https://owenrusk.dev/casebench.git

commit ea3d775814ba0f3fb3c20a8c3343ad703511c311
parent 8156dd1c33b189dd92bb6f861aa6b4dd6d1d3469
author Owen Rusk <owen@papermothgames.com>
date   2025-06-11 16:33:14 -0500
pull: take a test case off a board

takes its items, notes and lock with it.
casebench/cli.py+13-0
casebench/db.py+6-0
diff --git a/casebench/cli.py b/casebench/cli.py
index d8eca0f..0a96a51 100644
--- a/casebench/cli.py
+++ b/casebench/cli.py
@@ -47,6 +47,11 @@ def main(argv: list[str] | None = None) -> int:
     lister.add_argument("--player")
     lister.set_defaults(run=run_list)
 
+    puller = sub.add_parser("pull", help="take a test case off a board")
+    puller.add_argument("case")
+    puller.add_argument("--player", required=True)
+    puller.set_defaults(run=run_pull)
+
     args = parser.parse_args(argv)
     dsn = os.environ.get("CASEBENCH_DSN")
     if not dsn:
@@ -110,3 +115,11 @@ def run_unlock(conn: psycopg.Connection, args: argparse.Namespace) -> None:
 def run_list(conn: psycopg.Connection, args: argparse.Namespace) -> None:
     for handle, case_id, title in db.bench_cases(conn, args.player):
         print(f"{handle}\t{case_id}\t{title}")
+
+
+def run_pull(conn: psycopg.Connection, args: argparse.Namespace) -> None:
+    who = player(conn, args.player)
+    if db.source(conn, who, args.case) is None:
+        raise Fail(f"{args.player} doesn't have {args.case}")
+    db.pull(conn, who, args.case)
+    print(f"{args.player}: pulled {args.case}")
diff --git a/casebench/db.py b/casebench/db.py
index 1a4dd8c..b3556a0 100644
--- a/casebench/db.py
+++ b/casebench/db.py
@@ -98,3 +98,9 @@ def bench_cases(conn: psycopg.Connection, handle: str | None = None) -> list[tup
         query += " and p.handle = %s"
         params = (handle,)
     return conn.execute(query + " order by p.handle, c.placed_at", params).fetchall()
+
+
+def pull(conn: psycopg.Connection, player: str, case_id: str) -> None:
+    with conn.transaction():
+        for table in ("board_locks", "board_notes", "board_items", "board_cases"):
+            conn.execute(f"delete from {table} where player_id = %s and case_id = %s", (player, case_id))