diff options
Diffstat (limited to 'salis.py')
| -rwxr-xr-x | salis.py | 18 |
1 files changed, 5 insertions, 13 deletions
@@ -1,7 +1,6 @@ #!/usr/bin/env -S PYTHONDONTWRITEBYTECODE=1 python import ctypes -import enum import json import os import random @@ -194,11 +193,6 @@ def fmt_opts(opts): log.info(f"Called '{prog} {args.command}' with the following options: {fmt_opts(vars(args))}") ns = SimpleNamespace() -class Request(enum.Enum): - REQUEST_NAME = "n" - REQUEST_OPTS = "o" - REQUEST_HASH = "h" - def gen_sim_paths(): ns.sim_dir = os.path.join(args.home, args.name) ns.sim_opts = os.path.join(ns.sim_dir, "opts.json") @@ -219,7 +213,8 @@ def source_from_opts_file(): def request_from_server(request): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client: client.connect((args.ip, args.port)) - client.sendall(request.value.encode()) + client.sendall(json.dumps(request).encode()) + client.shutdown(socket.SHUT_WR) return json.load(client.makefile(mode="r")) # New simulation @@ -263,10 +258,10 @@ if args.command == "server": if args.command == "client": # Pull basic information from the server # Required to build the client with correct flags - args.name = request_from_server(Request.REQUEST_NAME)["name"] + args.name = request_from_server({"request": "name"})["name"] log.info(f"Sourced simulation name from '{args.ip}:{args.port}': {args.name}") - opts = request_from_server(Request.REQUEST_OPTS) + opts = request_from_server({"request": "opts"}) for key, val in opts.items(): setattr(args, key, val) @@ -274,7 +269,7 @@ if args.command == "client": log.info(f"Sourced configuration from '{args.ip}:{args.port}': {fmt_opts(opts)}") # Server and client should be on the same hash - server_hash = request_from_server(Request.REQUEST_HASH)["hash"] + server_hash = request_from_server({"request": "hash"})["hash"] client_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").strip() if server_hash != client_hash: @@ -358,9 +353,6 @@ def pop_sim_path_vars(): def pop_net_vars(): ns.b.defines.add(f"-DPORT={args.port}") ns.b.defines.add(f"-DPORT_STR=\"{args.port}\"") - ns.b.defines.add(f"-DREQUEST_NAME='{Request.REQUEST_NAME.value}'") - ns.b.defines.add(f"-DREQUEST_OPTS='{Request.REQUEST_OPTS.value}'") - ns.b.defines.add(f"-DREQUEST_HASH='{Request.REQUEST_HASH.value}'") ns.b.links.add("-ljson-c") def pop_general(): |
