2020-01-16 02:48:44 +00:00
|
|
|
#! /usr/bin/python3
|
|
|
|
# Copyright (C) 2018-2020 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
|
2021-04-21 13:51:04 +00:00
|
|
|
from common import api_send_status, api_get_status
|
2020-01-16 02:48:44 +00:00
|
|
|
|
2021-04-21 13:51:04 +00:00
|
|
|
api = None
|
|
|
|
api_token = None
|
2020-01-16 02:48:44 +00:00
|
|
|
tile = ""
|
|
|
|
status = ""
|
|
|
|
verbose = False
|
|
|
|
|
|
|
|
argc = len(sys.argv)
|
|
|
|
first = True
|
|
|
|
i = 1
|
|
|
|
while i < argc:
|
2021-04-21 13:51:04 +00:00
|
|
|
if sys.argv[i] == "-a" or sys.argv[i] == "--api":
|
2020-01-16 02:48:44 +00:00
|
|
|
i += 1
|
2021-04-21 13:51:04 +00:00
|
|
|
api = sys.argv[i]
|
|
|
|
elif sys.argv[i] == "-t" or sys.argv[i] == "--api-token":
|
2020-01-16 02:48:44 +00:00
|
|
|
i += 1
|
2021-04-21 13:51:04 +00:00
|
|
|
api_token = sys.argv[i]
|
2020-01-16 02:48:44 +00:00
|
|
|
elif sys.argv[i] == "-v" or sys.argv[i] == "--verbose":
|
|
|
|
verbose = True
|
|
|
|
elif sys.argv[i] == "-h" or sys.argv[i] == "--help":
|
|
|
|
print("usage: flag-rebuild.py <file> [OPTIONS]")
|
|
|
|
print("Flags tiles for rebuild based on terrasync log file")
|
|
|
|
print("")
|
|
|
|
print(" <file> Terrasync log file")
|
|
|
|
print("OPTIONS")
|
2021-04-21 13:51:04 +00:00
|
|
|
print(" -a, --api Manager api url")
|
|
|
|
print(" -t, --api-token Manager api token")
|
2020-01-16 02:48:44 +00:00
|
|
|
print(" -v, --verbose Verbose printouts")
|
|
|
|
print(" -h, --help Shows this help and exit")
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
if first:
|
|
|
|
lfile = sys.argv[i]
|
|
|
|
else:
|
|
|
|
print("Unknown option " + sys.argv[i])
|
|
|
|
sys.exit(1)
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
if lfile == "":
|
|
|
|
print("ERROR: No file given")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-04-21 13:51:04 +00:00
|
|
|
if not api:
|
|
|
|
print("ERROR: No api given")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not api_token:
|
|
|
|
print("ERROR: No api token given")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-01-16 02:48:44 +00:00
|
|
|
try:
|
|
|
|
tiles = []
|
|
|
|
with open(lfile) as f:
|
|
|
|
for line in f:
|
2020-03-17 17:44:28 +00:00
|
|
|
match = re.match(r".*[ew]\d{3}[ns]\d{2}/[ew]\d{3}[ns]\d{2}/([0-9]{1,7})\.[bs]tg", line)
|
2020-01-16 02:48:44 +00:00
|
|
|
if match != None:
|
|
|
|
tiles.append(match.group(1))
|
|
|
|
except IOError:
|
|
|
|
print("ERROR: Failed to read file")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
tiles = set(tiles)
|
|
|
|
|
|
|
|
for tile in tiles:
|
2021-04-21 13:51:04 +00:00
|
|
|
status = api_get_status(tile, api, api_token)
|
2020-01-24 11:24:03 +00:00
|
|
|
if status == "done" or status == "packaged":
|
2020-01-16 02:48:44 +00:00
|
|
|
if verbose:
|
|
|
|
print("Flagging " + tile)
|
2021-04-21 13:51:04 +00:00
|
|
|
api_send_status(tile, "rebuild", api, api_token)
|
2020-01-16 02:48:44 +00:00
|
|
|
elif verbose:
|
|
|
|
print("Skipping " + tile + ". Not yet build")
|