Added api support to packager

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2021-03-10 19:32:11 +00:00
parent 8450b7ae81
commit d379ffe25d

View file

@ -27,6 +27,8 @@ from common import norm, send_status, get_job
host = socket.gethostname()
port = 12345
api = None
api_token = None
output = ""
argc = len(sys.argv)
@ -42,6 +44,12 @@ while i < argc:
elif sys.argv[i] == "-o" or sys.argv[i] == "--output":
i += 1
output = sys.argv[i]
elif sys.argv[i] == "-a" or sys.argv[i] == "--api":
i += 1
api = sys.argv[i]
elif sys.argv[i] == "-t" or sys.argv[i] == "--api-token":
i += 1
api_token = sys.argv[i]
elif sys.argv[i] == "-h" or sys.argv[i] == "--help":
print("usage: worldbuild-packager.py [OPTIONS]")
print("Retrives done tiles from the manager and packages them")
@ -49,6 +57,8 @@ while i < argc:
print(" -o, --output Output directory. Path MUST be absolute")
print(" --host Manager host")
print(" --port Manager port")
print(" -a, --api Manager api url")
print(" -t, --api-token Manager api token")
print(" -h, --help Shows this help and exit")
sys.exit(0)
else:
@ -136,7 +146,10 @@ while running:
try:
name = "None"
while name == "None":
if api == None:
name = get_job("done", host, port, none_exit=False)
else:
name = api_get_job("done", api, token, none_exit=False)
if name == "None":
print("No job got asigned. Trying again in one hour.")
sleep(3600)
@ -176,7 +189,10 @@ while running:
print("Packaging " + name + " done")
if api == None:
send_status(name, "packaged", host, port)
else:
api_send_status(name, "packaged", api, token)
except KeyboardInterrupt:
print("Graceful shutdown triggered. To force immedate stop, press Ctrl+C again")
@ -184,7 +200,10 @@ while running:
try:
package.wait()
update_index(output, name, name_major)
send_status(name, "packaged")
if api == None:
send_status(name, "packaged", host, port)
else:
api_send_status(name, "packaged", api, token)
except KeyboardInterrupt:
# TODO doesn't work
print("Forcing shutdown...")