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
|
|
|
|
2018-02-11 00:24:01 +00:00
|
|
|
from tcllib import ansi, argparser, devlist
|
2018-02-11 00:21:09 +00:00
|
|
|
from tcllib.devices import DesktopDevice
|
2018-02-11 00:48:47 +00:00
|
|
|
from tcllib.dumpmgr import write_info_if_dumps_found
|
|
|
|
from tcllib.requests import RequestRunner, CheckRequest, ServerVoteSelector
|
2018-02-03 20:24:36 +00:00
|
|
|
|
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-11 00:24:01 +00:00
|
|
|
dp = 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)
|
2018-02-09 20:41:12 +00:00
|
|
|
dp.add_argument("-l", "--local", help="Force using local database", dest="local", action="store_true", default=False)
|
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-09 20:41:12 +00:00
|
|
|
prd_db = devlist.get_devicelist(local=args.local)
|
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
|
|
|
|
2018-02-11 00:21:09 +00:00
|
|
|
dev = DesktopDevice()
|
|
|
|
|
|
|
|
runner = RequestRunner(ServerVoteSelector(), https=False)
|
|
|
|
runner.max_tries = 20
|
|
|
|
|
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="")
|
2018-02-11 00:21:09 +00:00
|
|
|
dev.curef = curef
|
|
|
|
chk = CheckRequest(dev)
|
|
|
|
runner.run(chk)
|
|
|
|
if chk.success:
|
|
|
|
chkres = chk.get_result()
|
|
|
|
txt_tv = chkres.tvver
|
|
|
|
print("{}: {} {}".format(curef, txt_tv, chkres.filehash))
|
2017-09-26 23:39:41 +01:00
|
|
|
|
|
|
|
print("Scan complete.")
|
2018-02-11 00:21:09 +00:00
|
|
|
write_info_if_dumps_found()
|