From c9e279e9dba64b5a1e6f3b9c7f1bb9ea656d78f2 Mon Sep 17 00:00:00 2001 From: fly Date: Thu, 16 Jan 2020 00:56:20 +0000 Subject: [PATCH] Set status script Signed-off-by: fly --- set-status.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 set-status.py diff --git a/set-status.py b/set-status.py new file mode 100755 index 0000000..3272953 --- /dev/null +++ b/set-status.py @@ -0,0 +1,95 @@ +#! /usr/bin/python3 +# Copyright (C) 2018-2019 Merspieler, merspieler _at_ airmail.cc +# +# 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 + +host = socket.gethostname() +port = 12345 +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] + elif sys.argv[i] == "-v": + verbose = True + elif sys.argv[i] == "-f" or sys.argv[i] == "--file": + i += 1 + sfile = sys.argv[i] + elif sys.argv[i] == "-h" or sys.argv[i] == "--help": + print("usage: set-status.py [OPTIONS]") + print("Manually set a tile status") + print("") + print(" Is the tile name") + print(" Is the new status to set the tile to") + print(" Can be:") + print(" - pending") + print(" - skip") + print(" - rebuild") + print(" - done") + print("OPTIONS") + print(" , --host Manager host") + print(" , --port Manager port") + print(" -h, --help Shows this help and exit") + sys.exit(0) + else: + if first == 1: + match = re.match(r"(n-pole|s-pole|[ew]\d{3}[ns]\d{2})", sys.argv[i]) + if match == None: + print("ERROR: Invalid tile name " + sys.argv[i]) + sys.exit(1) + first = 2 + tile = match.group(0) + elif first == 2: + match = re.match(r"(done|pending|rebuild|skip)", sys.argv[i]) + 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) + +try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((host, port)) + sock.send(("set " + name + " " + status).encode()) + sock.close() +except IOError: + print("ERROR: Unable to send status.") + sys.exit(1) + +print("Status set successfully")