From cfa151c8a10039010f6ab01b2d4c8560b72bc0a9 Mon Sep 17 00:00:00 2001 From: fly Date: Thu, 25 Jun 2020 01:22:47 +1000 Subject: [PATCH] Refactor and fix Signed-off-by: fly --- common.py | 2 +- worldbuild-manager.py | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/common.py b/common.py index fe1cff6..bf86b54 100644 --- a/common.py +++ b/common.py @@ -123,7 +123,7 @@ def get_job(action, host, port, none_exit=True): msg = sock.recv(128) sock.close() msg = msg.decode() - match = re.match(r"n-pole|s-pole|[ew]\d{3}[ns]\d{2}|None", msg) + match = re.match(r"[ew]\d{3}[ns]\d{2}|[0-9]{1,7}|None", msg) if match != None: ret = match.group(0) if ret == "None" and none_exit: diff --git a/worldbuild-manager.py b/worldbuild-manager.py index 93a2dc6..4d3ef7c 100755 --- a/worldbuild-manager.py +++ b/worldbuild-manager.py @@ -17,7 +17,6 @@ import socket import sys -import json import os import re import pymysql @@ -119,6 +118,7 @@ try: action = "set" name = match.group(2) status = match.group(3) + set_state(name, status) else: match = re.match(r"(get) (started|rebuild|skip|pending|done)", msg) if match != None: @@ -135,9 +135,6 @@ try: else: print("WARNING: Recived invalid package") - if action == "set": - set_state(name, status) - elif action == "get-job": additional_type = "" if get != "pending": @@ -171,21 +168,13 @@ try: elif action == "status": match = re.match(r"([ew])(\d{3})([ns])(\d{2})", name) if match != None: - sql = "SELECT status_id FROM secondLevel WHERE name = '" + name + "'" - cursor.execute() - result = cursor.fetchone() - - sql = "SELECT name FROM status WHERE id = " + result[0] + sql = "SELECT name FROM status WHERE id = (SELECT status_id FROM secondLevel WHERE name = '" + name + "')" cursor.execute() result = cursor.fetchone() c.send(str(result[0]).encode()) else: - sql = "SELECT status_id FROM tile WHERE id = " + name - cursor.execute() - result = cursor.fetchone() - - sql = "SELECT name FROM status WHERE id = " + result[0] + sql = "SELECT name FROM status WHERE id = (SELECT status_id FROM tile WHERE id = '" + name + "')" cursor.execute() result = cursor.fetchone()