2017-10-06 01:23:47 +01:00
|
|
|
#!/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."""
|
|
|
|
|
2017-10-06 01:23:47 +01:00
|
|
|
import sys
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-02-11 01:38:38 +00:00
|
|
|
from tcllib import ansi, argparser
|
2018-02-11 00:27:00 +00:00
|
|
|
from tcllib.devices import MobileDevice
|
2018-02-11 00:48:47 +00:00
|
|
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
2018-02-11 01:38:38 +00:00
|
|
|
from tcllib.requests import CheckRequest, RequestRunner, ServerVoteSelector
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2017-10-06 01:23:47 +01:00
|
|
|
|
2018-01-30 17:31:05 +00:00
|
|
|
dpdesc = """
|
|
|
|
Finds all valid OTA updates for a given PRD. Scan range can be set by
|
|
|
|
startver and endver switches.
|
|
|
|
"""
|
2018-02-11 00:27:00 +00:00
|
|
|
dp = argparser.DefaultParser(__file__, dpdesc)
|
2018-01-30 17:31:05 +00:00
|
|
|
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:])
|
|
|
|
|
2018-02-11 00:27:00 +00:00
|
|
|
dev = MobileDevice()
|
|
|
|
dev.curef = args.prd
|
2017-10-10 20:25:38 +01:00
|
|
|
start_ver = args.startver
|
|
|
|
end_ver = args.endver
|
2017-10-06 01:23:47 +01:00
|
|
|
|
2018-02-11 00:27:00 +00:00
|
|
|
print("Valid firmwares for model {} (between {} and {}):".format(dev.curef, start_ver, end_ver))
|
2017-10-06 01:23:47 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2018-02-11 00:27:00 +00:00
|
|
|
runner = RequestRunner(ServerVoteSelector(), https=False)
|
|
|
|
runner.max_tries = 20
|
|
|
|
|
2017-10-06 01:23:47 +01:00
|
|
|
done_count = 0
|
|
|
|
total_count = len(allvers)
|
|
|
|
for fv in allvers:
|
|
|
|
done_count += 1
|
|
|
|
print("Checking {} ({}/{})".format(fv, done_count, total_count))
|
2018-02-03 00:36:08 +00:00
|
|
|
print(ansi.UP_DEL, end="")
|
2018-02-11 00:27:00 +00:00
|
|
|
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))
|
2017-10-06 01:23:47 +01:00
|
|
|
|
|
|
|
print("Scan complete.")
|
2018-02-11 00:27:00 +00:00
|
|
|
write_info_if_dumps_found()
|