|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
|
|
4
|
|
|
# pylint: disable=C0111,C0326,C0103 |
|
5
|
|
|
|
|
6
|
|
|
"""Find new PRDs for a range of variants.""" |
|
7
|
|
|
|
|
8
|
|
|
import sys |
|
9
|
|
|
|
|
10
|
|
|
from tcllib import ansi, argparser, devlist |
|
11
|
|
|
from tcllib.devices import DesktopDevice |
|
12
|
|
|
from tcllib.dumpmgr import write_info_if_dumps_found |
|
13
|
|
|
from tcllib.requests import CheckRequest, RequestRunner, ServerVoteSelector |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
# Variants to scan for |
|
17
|
|
|
SCAN_VARIANTS = ["001", "003", "009", "010", "700"] |
|
18
|
|
|
|
|
19
|
|
|
dpdesc = """ |
|
20
|
|
|
Finds new PRD numbers for a range of variants. Scan range can be set by |
|
21
|
|
|
floor and ceiling switches. |
|
22
|
|
|
""" |
|
23
|
|
|
dp = argparser.DefaultParser(__file__, dpdesc) |
|
24
|
|
|
dp.add_argument("floor", nargs="?", help="Model number to start with", type=int, default=63116) |
|
25
|
|
|
dp.add_argument("ceiling", nargs="?", help="Model number to end with", type=int, default=99999) |
|
26
|
|
|
dp.add_argument("-l", "--local", help="Force using local database", dest="local", action="store_true", default=False) |
|
27
|
|
|
dp.add_argument("-k2", "--key2", help="V2 syntax", dest="key2mode", action="store_true", default=False) |
|
28
|
|
|
args = dp.parse_args(sys.argv[1:]) |
|
29
|
|
|
|
|
30
|
|
|
floor = args.floor |
|
31
|
|
|
ceiling = args.ceiling + 1 |
|
32
|
|
|
if ceiling < floor: |
|
33
|
|
|
print("Invalid range!") |
|
34
|
|
|
raise SystemExit |
|
35
|
|
|
|
|
36
|
|
|
print("Loading list of known devices...", end="", flush=True) |
|
37
|
|
|
prd_db = devlist.get_devicelist(local=args.local) |
|
38
|
|
|
print(" OK") |
|
39
|
|
|
|
|
40
|
|
|
print("Valid PRDs not already in database:") |
|
41
|
|
|
|
|
42
|
|
|
known_centers = set(int(x.replace("PRD-", "").replace("APBI-PRD", "")[0:5]) for x in prd_db) |
|
43
|
|
|
scan_list = set(range(floor, ceiling)) |
|
44
|
|
|
|
|
45
|
|
|
to_scan = scan_list - known_centers |
|
46
|
|
|
total_count = len(to_scan) * len(SCAN_VARIANTS) |
|
47
|
|
|
done_count = 0 |
|
48
|
|
|
|
|
49
|
|
|
dev = DesktopDevice() |
|
50
|
|
|
|
|
51
|
|
|
runner = RequestRunner(ServerVoteSelector(), https=False) |
|
52
|
|
|
runner.max_tries = 20 |
|
53
|
|
|
|
|
54
|
|
|
for center in to_scan: |
|
55
|
|
|
for j in SCAN_VARIANTS: |
|
56
|
|
|
if args.key2mode: |
|
57
|
|
|
curef = "APBI-PRD{:05}{:3}".format(center, j) |
|
58
|
|
|
else: |
|
59
|
|
|
curef = "PRD-{:05}-{:3}".format(center, j) |
|
60
|
|
|
done_count += 1 |
|
61
|
|
|
print("Checking {} ({}/{})".format(curef, done_count, total_count)) |
|
62
|
|
|
print(ansi.UP_DEL, end="") |
|
63
|
|
|
dev.curef = curef |
|
64
|
|
|
chk = CheckRequest(dev) |
|
65
|
|
|
runner.run(chk) |
|
66
|
|
|
if chk.success: |
|
67
|
|
|
chkres = chk.get_result() |
|
68
|
|
|
txt_tv = chkres.tvver |
|
69
|
|
|
print("{}: {} {}".format(curef, txt_tv, chkres.filehash)) |
|
70
|
|
|
|
|
71
|
|
|
print("Scan complete.") |
|
72
|
|
|
write_info_if_dumps_found() |
|
73
|
|
|
|