Catch json errors

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2021-04-20 10:09:25 +02:00
parent 7ab046aa94
commit 99344471cc

View file

@ -18,12 +18,10 @@
import socket import socket
import re import re
import sys import sys
from common import send_status, api_send_status from common import api_send_status
host = socket.gethostname()
port = 12345
api = None api = None
apt_token = None api_token = None
tile = "" tile = ""
status = "" status = ""
@ -31,13 +29,7 @@ argc = len(sys.argv)
first = 1 first = 1
i = 1 i = 1
while i < argc: while i < argc:
if sys.argv[i] == "--port": if sys.argv[i] == "-a" or sys.argv[i] == "--api":
i += 1
port = int(sys.argv[i])
elif sys.argv[i] == "--host":
i += 1
host = sys.argv[i]
elif sys.argv[i] == "-a" or sys.argv[i] == "--api":
i += 1 i += 1
api = sys.argv[i] api = sys.argv[i]
elif sys.argv[i] == "-t" or sys.argv[i] == "--api-token": elif sys.argv[i] == "-t" or sys.argv[i] == "--api-token":
@ -49,16 +41,7 @@ while i < argc:
print("") print("")
print(" <tile> Is the tile name") print(" <tile> Is the tile name")
print(" <status> Is the new status to set the tile to") print(" <status> Is the new status to set the tile to")
print(" Can be:")
print(" - pending")
print(" - skip")
print(" - rebuild")
print(" - started")
print(" - done")
print(" - packaged")
print("OPTIONS") print("OPTIONS")
print(" , --host Manager host")
print(" , --port Manager port")
print(" -a, --api Manager api url") print(" -a, --api Manager api url")
print(" -t, --api-token Manager api token") print(" -t, --api-token Manager api token")
print(" -h, --help Shows this help and exit") print(" -h, --help Shows this help and exit")
@ -72,12 +55,8 @@ while i < argc:
first = 2 first = 2
tile = match.group(0) tile = match.group(0)
elif first == 2: elif first == 2:
match = re.match(r"(done|pending|rebuild|skip|packaged|started)", sys.argv[i])
if match == None:
print("ERROR: Invalid status " + sys.argv[i])
sys.exit(1)
first == 0 first == 0
status = match.group(0) status = sys.argv[i]
else: else:
print("Unknown option " + sys.argv[i]) print("Unknown option " + sys.argv[i])
sys.exit(1) sys.exit(1)
@ -91,13 +70,14 @@ if status == "":
print("ERROR: No status given") print("ERROR: No status given")
sys.exit(1) sys.exit(1)
if api != None and api_token == None: if api == None:
print("Error: API given but no token") print("Error: No API URL given")
sys.exit(1)
if api_token == None:
print("Error: No API token given")
sys.exit(1) sys.exit(1)
if api == None:
send_status(tile, status, host, port)
else:
api_send_status(tile, status, api, api_token) api_send_status(tile, status, api, api_token)
print("Status set successfully") print("Status set successfully")