2020-01-16 00:56:20 +00:00
|
|
|
#! /usr/bin/python3
|
2020-01-16 01:27:33 +00:00
|
|
|
# Copyright (C) 2018-2020 Merspieler, merspieler _at_ airmail.cc
|
2020-01-16 00:56:20 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation; either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
import socket
|
|
|
|
import re
|
|
|
|
import sys
|
2020-03-13 13:07:44 +00:00
|
|
|
from common import send_status
|
2020-01-16 00:56:20 +00:00
|
|
|
|
|
|
|
host = socket.gethostname()
|
|
|
|
port = 12345
|
2021-03-10 19:21:18 +00:00
|
|
|
api = None
|
|
|
|
apt_token = None
|
2020-01-16 00:56:20 +00:00
|
|
|
tile = ""
|
|
|
|
status = ""
|
|
|
|
|
|
|
|
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]
|
2021-03-10 19:21:18 +00:00
|
|
|
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]
|
2020-01-16 00:56:20 +00:00
|
|
|
elif sys.argv[i] == "-h" or sys.argv[i] == "--help":
|
|
|
|
print("usage: set-status.py <tile> <status> [OPTIONS]")
|
|
|
|
print("Manually set a tile status")
|
|
|
|
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")
|
2021-02-19 23:10:20 +00:00
|
|
|
print(" - started")
|
2020-01-16 00:56:20 +00:00
|
|
|
print(" - done")
|
2021-02-19 23:10:20 +00:00
|
|
|
print(" - packaged")
|
2020-01-16 00:56:20 +00:00
|
|
|
print("OPTIONS")
|
|
|
|
print(" , --host Manager host")
|
|
|
|
print(" , --port Manager port")
|
2021-03-10 19:21:18 +00:00
|
|
|
print(" -a, --api Manager api url")
|
|
|
|
print(" -t, --api-token Manager api token")
|
2020-01-16 00:56:20 +00:00
|
|
|
print(" -h, --help Shows this help and exit")
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
if first == 1:
|
2020-03-13 13:07:44 +00:00
|
|
|
match = re.match(r"([ew]\d{3}[ns]\d{2}|[0-9]{1,7})", sys.argv[i])
|
2020-01-16 00:56:20 +00:00
|
|
|
if match == None:
|
|
|
|
print("ERROR: Invalid tile name " + sys.argv[i])
|
|
|
|
sys.exit(1)
|
|
|
|
first = 2
|
|
|
|
tile = match.group(0)
|
|
|
|
elif first == 2:
|
2021-02-19 23:10:20 +00:00
|
|
|
match = re.match(r"(done|pending|rebuild|skip|packaged|started)", sys.argv[i])
|
2020-01-16 00:56:20 +00:00
|
|
|
if match == None:
|
|
|
|
print("ERROR: Invalid status " + sys.argv[i])
|
|
|
|
sys.exit(1)
|
|
|
|
first == 0
|
|
|
|
status = match.group(0)
|
|
|
|
else:
|
|
|
|
print("Unknown option " + sys.argv[i])
|
|
|
|
sys.exit(1)
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
if tile == "":
|
|
|
|
print("ERROR: No tile given")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if status == "":
|
|
|
|
print("ERROR: No status given")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-03-10 19:21:18 +00:00
|
|
|
if api != None and api_token == None:
|
|
|
|
print("Error: API given but no token")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if api == None:
|
|
|
|
send_status(tile, status, host, port)
|
|
|
|
else:
|
|
|
|
api_send_status(tile, status, api, api_token)
|
2020-01-16 00:56:20 +00:00
|
|
|
|
|
|
|
print("Status set successfully")
|