Fix bug
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
36dd490ed2
commit
59fff5fcae
1 changed files with 59 additions and 56 deletions
|
@ -69,47 +69,7 @@ def save_state(state):
|
|||
except IOError:
|
||||
print("WARNING: Failed to write to file")
|
||||
|
||||
if os.path.isfile(sfile):
|
||||
try:
|
||||
with open(sfile) as json_data:
|
||||
state = json.load(json_data)
|
||||
except ValueError:
|
||||
print("ERROR: Invalid status file")
|
||||
sys.exit(1)
|
||||
else:
|
||||
state = {}
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.bind((host, port))
|
||||
|
||||
sock.listen(5)
|
||||
print("Up and running...")
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
c, addr = sock.accept()
|
||||
msg = c.recv(128)
|
||||
msg = msg.decode()
|
||||
|
||||
match = re.match(r"(set) (n-pole|s-pole|[ew]\d{3}[ns]\d{2}) (done|started|rebuild|skip|pending)", msg)
|
||||
if match != None:
|
||||
action = "set"
|
||||
name = match.group(2)
|
||||
status = match.group(3)
|
||||
else:
|
||||
match = re.match(r"(get) (started|rebuild|skip|pending)", msg)
|
||||
if match != None:
|
||||
action = "get"
|
||||
get = match.group(2)
|
||||
else:
|
||||
match = re.match(r"(status) (n-pole|s-pole|[ew]\d{3}[ns]\d{2})", msg)
|
||||
if match != None:
|
||||
action = "status"
|
||||
name = match.group(2)
|
||||
else:
|
||||
print("WARNING: Recived invalid package")
|
||||
|
||||
if action == "set":
|
||||
def set_state(state, name, status):
|
||||
if verbose:
|
||||
print(name + " set status to " + status)
|
||||
|
||||
|
@ -164,6 +124,49 @@ try:
|
|||
else:
|
||||
state[name_major]["status"] = "pending"
|
||||
|
||||
if os.path.isfile(sfile):
|
||||
try:
|
||||
with open(sfile) as json_data:
|
||||
state = json.load(json_data)
|
||||
except ValueError:
|
||||
print("ERROR: Invalid status file")
|
||||
sys.exit(1)
|
||||
else:
|
||||
state = {}
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.bind((host, port))
|
||||
|
||||
sock.listen(5)
|
||||
print("Up and running...")
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
c, addr = sock.accept()
|
||||
msg = c.recv(128)
|
||||
msg = msg.decode()
|
||||
|
||||
match = re.match(r"(set) (n-pole|s-pole|[ew]\d{3}[ns]\d{2}) (done|started|rebuild|skip|pending)", msg)
|
||||
if match != None:
|
||||
action = "set"
|
||||
name = match.group(2)
|
||||
status = match.group(3)
|
||||
else:
|
||||
match = re.match(r"(get) (started|rebuild|skip|pending)", msg)
|
||||
if match != None:
|
||||
action = "get"
|
||||
get = match.group(2)
|
||||
else:
|
||||
match = re.match(r"(status) (n-pole|s-pole|[ew]\d{3}[ns]\d{2})", msg)
|
||||
if match != None:
|
||||
action = "status"
|
||||
name = match.group(2)
|
||||
else:
|
||||
print("WARNING: Recived invalid package")
|
||||
|
||||
if action == "set":
|
||||
state = set_state(state, name, status)
|
||||
|
||||
save_state(state)
|
||||
else:
|
||||
print("WARNING: Invalid status '" + status + "' recived from " + name)
|
||||
|
@ -173,10 +176,10 @@ try:
|
|||
# Build poles first
|
||||
if not "n-pole" in state or ("n-pole" in state and state["n-pole"]["status"] == get):
|
||||
tile = "n-pole"
|
||||
state["n-pole"]["status"] = "started"
|
||||
state = set_state(state, "n-pole", "started")
|
||||
elif not "s-pole" in state or ("s-pole" in state and state["s-pole"]["status"] == get):
|
||||
tile = "s-pole"
|
||||
state["s-pole"]["status"] = "started"
|
||||
state = set_state(state, "n-pole", "started")
|
||||
else:
|
||||
ii = -8
|
||||
|
||||
|
@ -214,7 +217,7 @@ try:
|
|||
name_minor = ew + norm(j, 3) + ns + norm(iii, 2)
|
||||
if not name in state or (not name_minor in state[name] or (name_minor in state[name] and (state[name][name_minor]["status"] == get or state[name][name_minor]["status"] == "pending"))):
|
||||
tile = name_minor
|
||||
state[name][name_minor]["status"] = "started"
|
||||
state = set_state(status, name, "started")
|
||||
break
|
||||
iii += ns_step
|
||||
j += ew_step
|
||||
|
|
Loading…
Reference in a new issue