diff --git a/worldbuild-manager.py b/worldbuild-manager.py index 17259ed..0b41cff 100755 --- a/worldbuild-manager.py +++ b/worldbuild-manager.py @@ -97,7 +97,7 @@ def set_state(name, status): sql = "UPDATE tile SET status_id = " + str(sid[0]) + " WHERE parent_id = " + str(pid[0]) cursor.execute(sql) else: - sql = "UPDATE tile SET status_id = (SELECT if FROM status WHERE name = '" + status + "') WHERE id = " + name + sql = "UPDATE tile SET status_id = (SELECT id FROM status WHERE name = '" + status + "') WHERE id = " + name cursor.execute(sql) db.commit() @@ -113,6 +113,8 @@ try: msg = c.recv(128) msg = msg.decode() + db.ping(reconnect=True) + match = re.match(r"(set) ([ew]\d{3}[ns]\d{2}|[0-9]{1,7}) (done|started|rebuild|skip|pending|packaged)", msg) if match != None: action = "set" @@ -139,22 +141,22 @@ try: additional_type = "" if get != "pending": additional_type = "OR status_id = (SELECT id FROM status WHERE name = '" + get + "')" - sql = "SELECT id FROM tile WHERE status_id = (SELECT id FROM status WHERE name = 'pending') " + additional_type + " LIMIT 1" - cursor.execute() + sql = "SELECT id FROM tile WHERE status_id = (SELECT id FROM status WHERE name = 'pending') " + additional_type + " ORDER BY parent_id LIMIT 1" + cursor.execute(sql) result = cursor.fetchone() if result == None: tile = "None" else: tile = result[0] - sql = "UPDATE tile SET status_id = (SELECT id FROM status WHERE name = 'started') WHERE id = " + tile - cursor.execute() + sql = "UPDATE tile SET status_id = (SELECT id FROM status WHERE name = 'started') WHERE id = " + str(tile) + cursor.execute(sql) db.commit() if verbose: - print("Asigning job on tile " + tile) + print("Asigning job on tile " + str(tile)) - c.send(tile.encode()) + c.send(str(tile).encode()) elif action == "get-done": sql = "SELECT id FROM secondLevel WHERE status_id = (SELECT id FROM status WHERE name = 'done') LIMIT 1" cursor.execute(sql) @@ -164,18 +166,18 @@ try: else: tile = result[0] - c.send(tile.encode()) + c.send(str(tile).encode()) elif action == "status": match = re.match(r"([ew])(\d{3})([ns])(\d{2})", name) if match != None: sql = "SELECT name FROM status WHERE id = (SELECT status_id FROM secondLevel WHERE name = '" + name + "')" - cursor.execute() + cursor.execute(sql) result = cursor.fetchone() c.send(str(result[0]).encode()) else: sql = "SELECT name FROM status WHERE id = (SELECT status_id FROM tile WHERE id = '" + name + "')" - cursor.execute() + cursor.execute(sql) result = cursor.fetchone() c.send(str(result[0]).encode())