diff --git a/worldbuild-packager.py b/worldbuild-packager.py index 76a8933..20027fa 100755 --- a/worldbuild-packager.py +++ b/worldbuild-packager.py @@ -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,14 +44,22 @@ 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") print("") - print(" -o, --output Output directory. Path MUST be absolute") - print(" --host Manager host") - print(" --port Manager port") - print(" -h, --help Shows this help and exit") + 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: if first == 1: @@ -136,7 +146,10 @@ while running: try: name = "None" while name == "None": - name = get_job("done", host, port, none_exit=False) + 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") - send_status(name, "packaged", host, port) + 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...")