From dfe366dd7caad500bcf214a72cb47d95a7ce7f72 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 11 Feb 2018 01:27:00 +0100 Subject: [PATCH] Convert tclcheck_findver.py to new style. --- tclcheck_findver.py | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/tclcheck_findver.py b/tclcheck_findver.py index 301e66f..047ce0f 100755 --- a/tclcheck_findver.py +++ b/tclcheck_findver.py @@ -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()