Bunch of fixes

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2020-01-15 11:33:31 +00:00
parent 7116fc64f9
commit e08fbea737
2 changed files with 79 additions and 64 deletions

View file

@ -41,9 +41,8 @@ while i < argc:
i += 1 i += 1
sfile = sys.argv[i] sfile = sys.argv[i]
elif sys.argv[i] == "-h" or sys.argv[i] == "--help": elif sys.argv[i] == "-h" or sys.argv[i] == "--help":
print("usage: wb-progress-logger.py [OPTIONS]") print("usage: worldbuild-manager.py [OPTIONS]")
print("Logs progress of the worldbuild when run") print("Handles job asignments and keeps track of the status")
print("with database strategies 'chunk' and 'mono'")
print("") print("")
print("OPTIONS") print("OPTIONS")
print(" -f, --file Status file to use") print(" -f, --file Status file to use")
@ -51,6 +50,7 @@ while i < argc:
print(" , --host hostname or interface to bind to") print(" , --host hostname or interface to bind to")
print(" , --port Port to bind to") print(" , --port Port to bind to")
print(" -h, --help Shows this help and exit") print(" -h, --help Shows this help and exit")
sys.exit(0)
else: else:
print("Unknown option " + sys.argv[i]) print("Unknown option " + sys.argv[i])
sys.exit(1) sys.exit(1)
@ -62,7 +62,7 @@ def norm(num, length):
num = "0" + num num = "0" + num
return num return num
def save_state(state) def save_state(state):
try: try:
with open(sfile, 'w') as f: with open(sfile, 'w') as f:
json.dump(state, f, indent=4) json.dump(state, f, indent=4)
@ -165,9 +165,9 @@ try:
elif action == "get": elif action == "get":
tile = "" tile = ""
# Build poles first # Build poles first
if not "n-pole" in status or ("n-pole" in status and status["n-pole"]["status"] == get): if not "n-pole" in state or ("n-pole" in state and state["n-pole"]["status"] == get):
tile = "n-pole" tile = "n-pole"
elif not "s-pole" in status or ("s-pole" in status and status["s-pole"]["status"] == get): elif not "s-pole" in state or ("s-pole" in state and state["s-pole"]["status"] == get):
tile = "s-pole" tile = "s-pole"
else: else:
ii = -8 ii = -8
@ -188,7 +188,7 @@ try:
name = ew + norm(abs(j), 3) + ns + norm(abs(i), 2) name = ew + norm(abs(j), 3) + ns + norm(abs(i), 2)
if not name in status or (name in status and status[name]["status"] != "done"): if not name in state or (name in state and state[name]["status"] != "done"):
if ns == "s": if ns == "s":
ns_step = -1 ns_step = -1
else: else:
@ -204,7 +204,7 @@ try:
iii = abs(i) iii = abs(i)
for l in range(0, 10): for l in range(0, 10):
name_minor = ew + norm(j, 3) + ns + norm(iii, 2) name_minor = ew + norm(j, 3) + ns + norm(iii, 2)
if not name in status or (not name_minor in status[name] or (name_minor in status[name] and (status[name][name_minor]["status"] == get))): 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))):
tile = name_minor tile = name_minor
break break
iii += ns_step iii += ns_step

View file

@ -48,8 +48,8 @@ while i < argc:
print ("ERROR: Unknown action " + sys.argv[i]) print ("ERROR: Unknown action " + sys.argv[i])
sys.exit(1) sys.exit(1)
elif sys.argv[i] == "-h" or sys.argv[i] == "--help": elif sys.argv[i] == "-h" or sys.argv[i] == "--help":
print("usage: build_chunk.py [OPTIONS]") print("usage:worldbuild-worker.py [OPTIONS]")
print("Runs a single chunk build. Mainly handles status logging") print("Retrives jobs from the manager and executes them")
print("") print("")
print(" -p, --prefix Database prefix to use") print(" -p, --prefix Database prefix to use")
print(" --host Logger host") print(" --host Logger host")
@ -60,6 +60,7 @@ while i < argc:
print(" rebuild: Build tiles flaged for rebuild") print(" rebuild: Build tiles flaged for rebuild")
print(" skip: Force building tile that are marked for being skipped") print(" skip: Force building tile that are marked for being skipped")
print(" -h, --help Shows this help and exit") print(" -h, --help Shows this help and exit")
sys.exit(0)
else: else:
if first == 1: if first == 1:
first = 0 first = 0
@ -110,63 +111,77 @@ def get_job(action):
ret = get_job(action) ret = get_job(action)
return ret return ret
def execute_build(name, prefix):
send_status(name, "started")
run("mkdir -p projects/worldbuild-" + name, shell=True) running = True
while running:
name = get_job(action)
run("cp projects/worldbuild/params.ini projects/worldbuild-" + name + "/", shell=True) try:
send_status(name, "started")
if name == "n-pole": run("mkdir -p projects/worldbuild-" + name, shell=True)
bounds = "bounds=*-180_80_180_90"
db_name = prefix + "n-pole" run("cp projects/worldbuild/params.ini projects/worldbuild-" + name + "/", shell=True)
elif name == "s-pole":
bounds = "bounds=*-180_-90_180_-80" if name == "n-pole":
db_name = prefix + "s-pole" bounds = "bounds=*-180_80_180_90"
else: db_name = prefix + "n-pole"
match = re.match(r"([ew])(\d{3})([ns])(\d{2})", name) elif name == "s-pole":
if match == None: bounds = "bounds=*-180_-90_180_-80"
print("ERROR: Invalid tile name") db_name = prefix + "s-pole"
sys.exit(1)
else: else:
ew = match.group(1) match = re.match(r"([ew])(\d{3})([ns])(\d{2})", name)
ew_val = int(match.group(2)) if match == None:
ns = match.group(3) print("ERROR: Invalid tile name")
ns_val = int(match.group(4)) sys.exit(1)
if ew == "w":
ew_val *= -1
if ns == "s":
ns_val *= -1
if ew_val < 0:
bounds = "bounds=*"
else: else:
bounds = "bounds=" ew = match.group(1)
ew_val = int(match.group(2))
ns = match.group(3)
ns_val = int(match.group(4))
bounds += str(ew_val) + "_" + str(ns_val) + "_" + str(ew_val + 10) + "_" + str(ns_val + 10) if ew == "w":
if ew_val % 10 != 0: ew_val *= -1
ew_val = ew_val - (ew_val % 10) if ns == "s":
ns_val *= -1
if ns_val % 10 != 0: if ew_val < 0:
ns_val = ns_val - (ns_val % 10) bounds = "bounds=*"
else:
bounds = "bounds="
db_name = prefix + ew + norm(ew_val, 3) + ns + norm(ns_val, 2) bounds += str(ew_val) + "_" + str(ns_val) + "_" + str(ew_val + 10) + "_" + str(ns_val + 10)
if ew_val % 10 != 0:
ew_val = ew_val - (ew_val % 10)
run("sed -i 's/DB_NAME.*/DB_NAME = \"" + db_name + "\"/' projects/worldbuild-" + name + "/params.ini", shell=True) if ns_val % 10 != 0:
ns_val = ns_val - (ns_val % 10)
run("echo '" + bounds + "' > projects/worldbuild-" + name + "/settings", shell=True) db_name = prefix + ew + norm(ew_val, 3) + ns + norm(ns_val, 2)
build = Popen("./build -S 10 -t 1 worldbuild-" + name, shell=True, start_new_session=True) run("sed -i 's/DB_NAME.*/DB_NAME = \"" + db_name + "\"/' projects/worldbuild-" + name + "/params.ini", shell=True)
if os.path.isfile("projects/worldbuild-" + name + "/osm2city-exceptions.log"): run("echo '" + bounds + "' > projects/worldbuild-" + name + "/settings", shell=True)
run("mv projects/worldbuild-" + name + "/osm2city-exceptions.log projects/worldbuild/output/error/" + name + ".exceptions.log", shell=True)
run("rm -rf projects/worldbuild-" + name, shell=True) build = Popen("./build -S 10 -t 1 worldbuild-" + name, shell=True, start_new_session=True)
send_status(name, "done") if os.path.isfile("projects/worldbuild-" + name + "/osm2city-exceptions.log"):
run("mv projects/worldbuild-" + name + "/osm2city-exceptions.log projects/worldbuild/output/error/" + name + ".exceptions.log", shell=True)
run = True: sleep(10)
while run: run("rm -rf projects/worldbuild-" + name, shell=True)
tile = get_job(action)
execute_build(tile, prefix) send_status(name, "done")
except KeyboardInterrupt:
print("Graceful shutdown triggered. To force immedate stop, press Ctrl+C again")
running = False
try:
build.wait()
except KeyboardInterrupt:
#TODO doesn't work
print("Forcing shutdown...")
build.terminate()
sleep(5)
build.kill()
sleep(5)
sys.exit(0)