1
0
mirror of https://github.com/mbirth/tcl_ota_check.git synced 2024-11-09 22:06:47 +00:00
tcl_ota_check/tclcheck_findver.py

71 lines
2.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=C0111,C0326,C0103
2018-02-03 21:25:26 +00:00
"""Find all OTA updates for a given PRD."""
import sys
2018-02-03 20:24:36 +00:00
from tcllib import ansi, argparser, devlist
from tcllib.devices import MobileDevice
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector, \
write_info_if_dumps_found
2018-02-03 20:24:36 +00:00
dpdesc = """
Finds all valid OTA updates for a given PRD. Scan range can be set by
startver and endver switches.
"""
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")
2017-10-10 20:25:38 +01:00
args = dp.parse_args(sys.argv[1:])
dev = MobileDevice()
dev.curef = args.prd
2017-10-10 20:25:38 +01:00
start_ver = args.startver
end_ver = args.endver
print("Valid firmwares for model {} (between {} and {}):".format(dev.curef, start_ver, end_ver))
cur_ver = start_ver
allvers = []
while True:
allvers.append(cur_ver)
if cur_ver == end_ver:
break
letters = list(cur_ver[:3])
num = int(cur_ver[3:6])
num += 1
if num > 999:
num = 0
for i in range(2, -1, -1):
if letters[i] == "Z":
letters[i] = "A"
continue
letters[i] = chr(ord(letters[i])+1)
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="")
dev.fwver = fv
chk = CheckRequest(dev)
runner.run(chk)
if chk.success:
chkres = chk.get_result()
txt_tv = chkres.tvver
2018-02-11 00:31:07 +00:00
print("{}: {}{} {}".format(dev.curef, fv, txt_tv, chkres.filehash))
print("Scan complete.")
write_info_if_dumps_found()