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
|
2017-10-10 12:28:52 +01:00
|
|
|
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
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2017-09-26 03:13:25 +01:00
|
|
|
|
|
|
|
fc = tcllib.FotaCheck()
|
|
|
|
fc.serid = "3531510"
|
|
|
|
fc.fv = "AAA000"
|
2017-10-15 00:51:38 +01:00
|
|
|
fc.mode = fc.MODE.FULL
|
2017-09-26 03:13:25 +01:00
|
|
|
|
2017-10-15 00:51:38 +01:00
|
|
|
# CLTP = 10 (only show actual updates or HTTP 206) / 2010 (always show latest version for MODE.FULL)
|
2018-02-03 20:24:36 +00:00
|
|
|
#fc.cltp = fc.CLTP.MOBILE
|
|
|
|
fc.cltp = fc.CLTP.DESKTOP
|
2017-09-26 03:13:25 +01:00
|
|
|
|
2018-01-30 17:31:05 +00:00
|
|
|
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)
|
2018-01-30 17:31:05 +00:00
|
|
|
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:])
|
|
|
|
|
2017-10-10 20:59:17 +01:00
|
|
|
floor = args.floor
|
|
|
|
ceiling = args.ceiling + 1
|
|
|
|
if ceiling < floor:
|
|
|
|
print("Invalid range!")
|
|
|
|
raise SystemExit
|
|
|
|
|
2017-12-17 02:12:09 +00:00
|
|
|
print("Loading list of devices...", end="", flush=True)
|
2018-02-05 15:32:26 +00:00
|
|
|
prd_db = devlist.get_devicelist()
|
2017-12-17 02:12:09 +00:00
|
|
|
print(" OK")
|
|
|
|
|
2017-09-26 03:13:25 +01:00
|
|
|
print("Valid PRDs not already in database:")
|
|
|
|
|
2017-12-17 02:12:09 +00:00
|
|
|
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-", "")
|
2017-10-10 12:28:52 +01:00
|
|
|
prdkeys = list(prddict.keys())
|
|
|
|
for k in prdkeys:
|
2017-10-10 20:25:38 +01:00
|
|
|
if k != args.tocheck:
|
2017-10-10 12:28:52 +01:00
|
|
|
del prddict[k]
|
2017-10-10 20:59:17 +01:00
|
|
|
if not prddict:
|
|
|
|
prddict[args.tocheck] = []
|
2017-09-26 23:39:41 +01:00
|
|
|
|
|
|
|
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]
|
2017-10-10 20:59:17 +01:00
|
|
|
total_count = len(safes)
|
2017-09-26 23:39:41 +01:00
|
|
|
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:
|
2017-09-26 23:39:41 +01:00
|
|
|
curef = "PRD-{}-{:03}".format(center, j)
|
|
|
|
done_count += 1
|
|
|
|
print("Checking {} ({}/{})".format(curef, done_count, total_count))
|
2018-02-03 00:36:08 +00:00
|
|
|
print(ansi.UP_DEL, end="")
|
2017-09-26 23:39:41 +01:00
|
|
|
try:
|
|
|
|
fc.reset_session()
|
|
|
|
fc.curef = curef
|
2017-10-12 15:58:29 +01:00
|
|
|
check_xml = fc.do_check(https=False, max_tries=20)
|
2017-09-26 23:39:41 +01:00
|
|
|
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.")
|
2017-11-12 21:19:04 +00:00
|
|
|
tcllib.FotaCheck.write_info_if_dumps_found()
|