1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-09-19 22:33:25 +01:00

Convert tclcheck_findver.py to new style.

This commit is contained in:
Markus Birth 2018-02-11 01:27:00 +01:00
parent 072644a089
commit dfe366dd7c
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A

View File

@ -7,32 +7,28 @@
import sys
from requests.exceptions import RequestException, Timeout
from tcllib import ansi, argparser, devlist
from tcllib.devices import MobileDevice
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector, \
write_info_if_dumps_found
import tcllib
import tcllib.argparser
from tcllib import ansi
from tcllib.devices import DesktopDevice, MobileDevice
dev = MobileDevice()
fc = tcllib.FotaCheck()
dpdesc = """
Finds all valid OTA updates for a given PRD. Scan range can be set by
startver and endver switches.
"""
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp = argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("prd", help="CU Reference #, e.g. PRD-63117-011")
dp.add_argument("startver", help="Beginning of scan range", nargs="?", default="AAA000")
dp.add_argument("endver", help="End of scan range", nargs="?", default="AAZ999")
args = dp.parse_args(sys.argv[1:])
fc.curef = args.prd
dev = MobileDevice()
dev.curef = args.prd
start_ver = args.startver
end_ver = args.endver
print("Valid firmwares for model {} (between {} and {}):".format(fc.curef, start_ver, end_ver))
print("Valid firmwares for model {} (between {} and {}):".format(dev.curef, start_ver, end_ver))
cur_ver = start_ver
allvers = []
@ -53,21 +49,22 @@ while True:
break
cur_ver = "{:3}{:03d}".format("".join(letters), num)
runner = RequestRunner(ServerVoteSelector(), https=False)
runner.max_tries = 20
done_count = 0
total_count = len(allvers)
for fv in allvers:
done_count += 1
print("Checking {} ({}/{})".format(fv, done_count, total_count))
print(ansi.UP_DEL, end="")
try:
dev.fwver = fv
fc.reset_session(dev)
check_xml = fc.do_check(dev, https=False, max_tries=20)
curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml)
txt_tv = tv
print("{}: {}{} {}".format(curef, fv, txt_tv, fhash))
except (SystemExit, RequestException, Timeout) as e:
continue
dev.fwver = fv
chk = CheckRequest(dev)
runner.run(chk)
if chk.success:
chkres = chk.get_result()
txt_tv = chkres.tvver
print("{}: {}{} {}".format(curef, fv, txt_tv, chkres.filehash))
print("Scan complete.")
tcllib.FotaCheck.write_info_if_dumps_found()
write_info_if_dumps_found()