From 0da722a048d3d270059bd2c5931c8f002f3fc5cd Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 12 Nov 2017 22:19:04 +0100 Subject: [PATCH] Added correct URL to uploader tool. Added notice if logs collected. --- tclcheck.py | 2 ++ tclcheck_allfull.py | 2 ++ tclcheck_allota.py | 2 ++ tclcheck_findprd.py | 1 + tclcheck_findver.py | 1 + tcllib.py | 11 +++++++++++ upload_logs.py | 10 ++++++++-- 7 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tclcheck.py b/tclcheck.py index 3945cd3..e80f355 100755 --- a/tclcheck.py +++ b/tclcheck.py @@ -55,3 +55,5 @@ if fc.mode == fc.MODE.FULL: f.write(header) else: print("Header length invalid ({}).".format(len(header))) + +tcllib.FotaCheck.write_info_if_dumps_found() diff --git a/tclcheck_allfull.py b/tclcheck_allfull.py index a591b73..f9df025 100755 --- a/tclcheck_allfull.py +++ b/tclcheck_allfull.py @@ -43,3 +43,5 @@ with open("prds.txt", "rt") as f: except RequestException as e: print("{}: {}".format(prd, str(e))) continue + +tcllib.FotaCheck.write_info_if_dumps_found() diff --git a/tclcheck_allota.py b/tclcheck_allota.py index f6c806d..28be019 100755 --- a/tclcheck_allota.py +++ b/tclcheck_allota.py @@ -47,3 +47,5 @@ with open("prds.txt", "r") as f: except RequestException as e: print("{} ({}): {}".format(prd, lastver, str(e))) continue + +tcllib.FotaCheck.write_info_if_dumps_found() diff --git a/tclcheck_findprd.py b/tclcheck_findprd.py index 40a7db2..e53b31c 100755 --- a/tclcheck_findprd.py +++ b/tclcheck_findprd.py @@ -73,3 +73,4 @@ for center in sorted(prddict.keys()): continue print("Scan complete.") +tcllib.FotaCheck.write_info_if_dumps_found() diff --git a/tclcheck_findver.py b/tclcheck_findver.py index f2f2f5b..ef92814 100755 --- a/tclcheck_findver.py +++ b/tclcheck_findver.py @@ -61,3 +61,4 @@ for fv in allvers: continue print("Scan complete.") +tcllib.FotaCheck.write_info_if_dumps_found() diff --git a/tcllib.py b/tcllib.py index 7bb6716..08b4b91 100644 --- a/tcllib.py +++ b/tcllib.py @@ -7,6 +7,7 @@ import base64 import binascii import enum import errno +import glob import hashlib import os import platform @@ -148,6 +149,16 @@ class FotaCheck: with open(outfile, "w", encoding="utf-8") as f: f.write(data) + @staticmethod + def write_info_if_dumps_found(): + # To disable this info, uncomment the following line. + #return + files = glob.glob(os.path.normpath("logs/*.xml")) + if len(files) > 0: + print() + print("{}There are {} logs collected in the logs/ directory.{} Please consider uploading".format(ANSI_YELLOW, len(files), ANSI_RESET)) + print("them to https://tclota.birth-online.de/ by running {}./upload_logs.py{}.".format(ANSI_CYAN, ANSI_RESET)) + def do_check(self, https=True, timeout=10, max_tries=5): protocol = "https://" if https else "http://" url = protocol + self.g2master + "/check.php" diff --git a/upload_logs.py b/upload_logs.py index 5618738..710437c 100644 --- a/upload_logs.py +++ b/upload_logs.py @@ -10,7 +10,7 @@ import os import requests # This is the URL to an installation of https://github.com/mbirth/tcl_update_db -UPLOAD_URL = "http://example.org/tcl_update_db/" +UPLOAD_URL = "https://tclota.birth-online.de/" LOGS_GLOB = os.path.normpath("logs/*.xml") headers = { "Content-Type": "text/xml" } @@ -20,6 +20,12 @@ for fn in glob.glob(LOGS_GLOB): with open(fn, "rb") as f: r = requests.post(UPLOAD_URL, data=f, headers=headers) if r.status_code == 200: + os.remove(fn) print(" OK") else: - print(" ERROR: HTTP {}".format(r.status_code)) + add_text = "" + if r.status_code in [413, 406, 412]: + # File has been rejected by server, another try won't help + os.remove(fn) + add_text = " - Please try again later." + print(" ERROR: HTTP {}{}".format(r.status_code, add_text))