Catch json errors
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
7ab046aa94
commit
99344471cc
1 changed files with 11 additions and 31 deletions
|
@ -18,12 +18,10 @@
|
|||
import socket
|
||||
import re
|
||||
import sys
|
||||
from common import send_status, api_send_status
|
||||
from common import api_send_status
|
||||
|
||||
host = socket.gethostname()
|
||||
port = 12345
|
||||
api = None
|
||||
apt_token = None
|
||||
api_token = None
|
||||
tile = ""
|
||||
status = ""
|
||||
|
||||
|
@ -31,13 +29,7 @@ argc = len(sys.argv)
|
|||
first = 1
|
||||
i = 1
|
||||
while i < argc:
|
||||
if sys.argv[i] == "--port":
|
||||
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":
|
||||
if 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":
|
||||
|
@ -49,16 +41,7 @@ while i < argc:
|
|||
print("")
|
||||
print(" <tile> Is the tile name")
|
||||
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(" , --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")
|
||||
|
@ -72,12 +55,8 @@ while i < argc:
|
|||
first = 2
|
||||
tile = match.group(0)
|
||||
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
|
||||
status = match.group(0)
|
||||
status = sys.argv[i]
|
||||
else:
|
||||
print("Unknown option " + sys.argv[i])
|
||||
sys.exit(1)
|
||||
|
@ -91,13 +70,14 @@ if status == "":
|
|||
print("ERROR: No status given")
|
||||
sys.exit(1)
|
||||
|
||||
if api != None and api_token == None:
|
||||
print("Error: API given but no token")
|
||||
if api == None:
|
||||
print("Error: No API URL given")
|
||||
sys.exit(1)
|
||||
|
||||
if api_token == None:
|
||||
print("Error: No API token given")
|
||||
sys.exit(1)
|
||||
|
||||
if api == None:
|
||||
send_status(tile, status, host, port)
|
||||
else:
|
||||
api_send_status(tile, status, api, api_token)
|
||||
|
||||
print("Status set successfully")
|
||||
|
|
Loading…
Reference in a new issue