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_findprd.py

83 lines
2.6 KiB
Python
Raw Normal View History

2017-09-26 03:13:25 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2017-10-06 01:23:38 +01:00
# pylint: disable=C0111,C0326,C0103
2017-09-26 03:13:25 +01:00
2018-02-03 21:25:26 +00:00
"""Find new PRDs for a given variant(s)."""
2017-09-26 03:13:25 +01:00
import collections
import sys
2018-02-03 20:24:36 +00:00
from requests.exceptions import RequestException, Timeout
2017-09-26 03:13:25 +01:00
import tcllib
2018-02-02 02:33:53 +00:00
import tcllib.argparser
2018-02-06 00:03:25 +00:00
from tcllib import ansi, devlist
from tcllib.devices import DesktopDevice, MobileDevice
2018-02-03 20:24:36 +00:00
2017-09-26 03:13:25 +01:00
dev = DesktopDevice()
2017-09-26 03:13:25 +01:00
fc = tcllib.FotaCheck()
dpdesc = """
Finds new PRD numbers for all known variants, or specified variants with tocheck. Scan range
can be set by floor and ceiling switches.
"""
2018-02-02 02:33:53 +00:00
dp = tcllib.argparser.DefaultParser(__file__, dpdesc)
dp.add_argument("tocheck", help="CU Reference # to filter scan results", nargs="?", default=None)
dp.add_argument("-f", "--floor", help="Beginning of scan range", dest="floor", nargs="?", type=int, default=0)
dp.add_argument("-c", "--ceiling", help="End of scan range", dest="ceiling", nargs="?", type=int, default=999)
2017-10-10 20:25:38 +01:00
args = dp.parse_args(sys.argv[1:])
floor = args.floor
ceiling = args.ceiling + 1
if ceiling < floor:
print("Invalid range!")
raise SystemExit
print("Loading list of devices...", end="", flush=True)
prd_db = devlist.get_devicelist()
print(" OK")
2017-09-26 03:13:25 +01:00
print("Valid PRDs not already in database:")
prds = [x.replace("PRD-", "").split("-") for x in prd_db]
prdx = list({x[0]: x[1]} for x in prds)
prddict = collections.defaultdict(list)
for prdc in prdx:
for key, value in prdc.items():
prddict[key].append(value)
2017-09-26 03:13:25 +01:00
2017-10-10 20:25:38 +01:00
if args.tocheck is not None:
2017-10-26 19:16:39 +01:00
args.tocheck = args.tocheck.replace("PRD-", "")
prdkeys = list(prddict.keys())
for k in prdkeys:
2017-10-10 20:25:38 +01:00
if k != args.tocheck:
del prddict[k]
if not prddict:
prddict[args.tocheck] = []
for center in sorted(prddict.keys()):
2017-09-26 03:13:25 +01:00
tails = [int(i) for i in prddict[center]]
2017-10-10 21:16:27 +01:00
safes = [g for g in range(floor, ceiling) if g not in tails]
total_count = len(safes)
done_count = 0
print("Checking {} variant codes for model {}.".format(total_count, center))
2017-10-10 21:16:27 +01:00
for j in safes:
curef = "PRD-{}-{:03}".format(center, j)
done_count += 1
print("Checking {} ({}/{})".format(curef, done_count, total_count))
print(ansi.UP_DEL, end="")
try:
dev.curef = curef
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, txt_tv, fhash))
except (SystemExit, RequestException, Timeout) as e:
continue
print("Scan complete.")
tcllib.FotaCheck.write_info_if_dumps_found()