Bunch of fixes

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2020-02-13 16:46:37 +00:00
parent cad582f393
commit 937775b3c5

View file

@ -19,9 +19,12 @@ import os
import sys
import hashlib
import re
import socket
from subprocess import run, Popen, STDOUT
from time import sleep
host = socket.gethostname()
port = 12345
output = ""
argc = len(sys.argv)
@ -87,8 +90,9 @@ def get_job(action):
if match != None:
ret = match.group(0)
if ret == "None":
print("No job got asigned. Exiting...")
sys.exit(0)
print("No job got asigned. Trying again in one hour.")
sleep(3600)
ret = get_job(action)
else:
print("Recived invalid job. Retrying in 10 seconds...")
sleep(10)
@ -101,14 +105,17 @@ def get_job(action):
return ret
def get_sha1(fname):
sha1 = hashlib.sha1()
with open(fname, 'rb') as f:
while True:
data = f.read(65536)
if not data:
break
sha1.update(data)
return sha1.hexdigest()
if os.path.isfile(fname):
sha1 = hashlib.sha1()
with open(fname, 'rb') as f:
while True:
data = f.read(65536)
if not data:
break
sha1.update(data)
return sha1.hexdigest()
else:
return None
def read_index(fname):
@ -127,31 +134,35 @@ def read_index(fname):
def write_index(fname, index):
with open(fname, 'w') as f:
for element in index:
f.write(element + ":" index[element])
f.write(element + ":" + str(index[element]) + "\n")
def update_index(output, name, name_major):
if os.path.isfile(output + "/" name_major + "/.dirindex"):
index = read_index(output + "/" name_major + "/.dirindex")
if os.path.isfile(output + "/" + name_major + "/.dirindex"):
index = read_index(output + "/" + name_major + "/.dirindex")
else:
index = {}
index["version"] = 1
index["path"] = name_major
index["z:" + name] = get_sha1(output + "/" name_major + "/" + name + ".zip")
sha = get_sha1(output + "/" + name_major + "/" + name + ".zip")
if sha != None:
index["z:" + name] = sha
write_index(output + "/" name_major + "/.dirindex", index)
write_index(output + "/" + name_major + "/.dirindex", index)
if os.path.isfile(output + "/.dirindex"):
main_index = read_index(output + "/.dirindex")
else:
main_index = {}
main_index["version"] = 1
main_index["path"] = ""
if os.path.isfile(output + "/.dirindex"):
main_index = read_index(output + "/.dirindex")
else:
main_index = {}
main_index["version"] = 1
main_index["path"] = ""
main_index["d:" + name_major] = get_sha1(output + "/" name_major + "/.dirindex")
sha = get_sha1(output + "/" + name_major + "/.dirindex")
if sha != None:
main_index["z:" + name] = sha
write_index(output + "/.dirindex", main_index)
write_index(output + "/.dirindex", main_index)
running = True
@ -186,14 +197,19 @@ while running:
name_major = ew + norm(ew_val_major, 3) + ns + norm(ns_val_major, 2)
run("mkdir -p " + output + "/" + name_major)
run("mkdir -p " + output + "/" + name_major, shell=True)
run("rm -f " + output + "/" + name_major + "/" + name + ".zip")
run("rm -f " + output + "/" + name_major + "/" + name + ".zip", shell=True)
package = Popen("cd projects/worldbuild/scenery && zip -rq " + output + "/" + name_major + "/" + name + ".zip . -i {Details,Pylons,Buildings,Roads}/" + name_major + "/" + name + "/*" , shell=True, start_new_session=True)
print("Packaging " + name + "...")
with open(os.devnull, 'w') as fp:
package = Popen("cd projects/worldbuild/scenery && zip -rq " + output + "/" + name_major + "/" + name + ".zip {Details,Pylons,Buildings,Roads}/" + name_major + "/" + name + "/*" , shell=True, start_new_session=True, stdout=fp)
package.wait()
print("Packaging " + name + " done")
update_index(output, name, name_major)
send_status(name, "packaged")