1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-10 06:16:46 +00:00

Repeat server request when server error or timeout.

This commit is contained in:
Markus Birth 2017-09-13 01:40:19 +02:00
parent cc6b0fbbc4
commit 55de408ab7

View File

@ -4,9 +4,10 @@
# pylint: disable=C0111,C0326 # pylint: disable=C0111,C0326
import tcllib import tcllib
import sys
from requests.exceptions import RequestException, Timeout from requests.exceptions import RequestException, Timeout
ANSI_UP_DEL = u"\u001b[F\u001b[K"
fc = tcllib.FotaCheck() fc = tcllib.FotaCheck()
fc.serid = "3531510" fc.serid = "3531510"
fc.fv = "AAM481" fc.fv = "AAM481"
@ -22,17 +23,25 @@ print("List of latest {} firmware by PRD:".format("FULL" if fc.mode == fc.MODE_F
with open("prds.txt", "r") as afile: with open("prds.txt", "r") as afile:
prdx = afile.read() prdx = afile.read()
prds = list(filter(None, prdx.split("\n"))) prds = list(filter(None, prdx.split("\n")))
for prdline in prds:
prd, model = prdline.split(" ", 1) while len(prds) > 0:
prd, model = prds[0].split(" ", 1)
try: try:
fc.reset_session() fc.reset_session()
fc.curef = prd fc.curef = prd
check_xml = fc.do_check() check_xml = fc.do_check()
curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml) curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml)
print("{}: {} {} ({})".format(prd, tv, fhash, model)) print("{}: {} {} ({})".format(prd, tv, fhash, model))
prds.pop(0)
except Timeout as e: except Timeout as e:
print("{} failed. (Connection timed out.)".format(prd)) print("{} failed. (Connection timed out.)".format(prd))
print(ANSI_UP_DEL, end="")
continue continue
except (SystemExit, RequestException) as e: except (SystemExit, RequestException) as e:
print("{} failed. ({})".format(prd, str(e))) print("{} failed. ({})".format(prd, str(e)))
if e.response.status_code in [204, 404]:
# No update available or invalid request - remove from queue
prds.pop(0)
else:
print(ANSI_UP_DEL, end="")
continue continue