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

69 lines
2.1 KiB
Python
Raw Normal View History

2018-01-23 21:59:21 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=C0111,C0326,C0103
2018-02-03 21:25:26 +00:00
"""Find new PRDs for a range of variants."""
2018-01-23 21:59:21 +00: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
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
2018-01-23 21:59:21 +00:00
# Variants to scan for
SCAN_VARIANTS = ["001", "003", "009", "010", "700"]
dpdesc = """
Finds new PRD numbers for a range of variants. 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-23 21:59:21 +00:00
dp.add_argument("floor", nargs="?", help="Model number to start with", type=int, default=63116)
dp.add_argument("ceiling", nargs="?", help="Model number to end with", type=int, default=99999)
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)
2018-01-23 21:59:21 +00: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 known devices...", end="", flush=True)
2018-02-09 20:41:12 +00:00
prd_db = devlist.get_devicelist(local=args.local)
2018-01-23 21:59:21 +00:00
print(" OK")
print("Valid PRDs not already in database:")
known_centers = set(int(x.replace("PRD-", "").split("-")[0]) for x in prd_db)
scan_list = set(range(floor, ceiling))
to_scan = scan_list - known_centers
total_count = len(to_scan) * len(SCAN_VARIANTS)
done_count = 0
2018-02-11 00:24:01 +00:00
dev = DesktopDevice()
runner = RequestRunner(ServerVoteSelector(), https=False)
runner.max_tries = 20
2018-01-23 21:59:21 +00:00
for center in to_scan:
for j in SCAN_VARIANTS:
curef = "PRD-{:05}-{:3}".format(center, j)
done_count += 1
print("Checking {} ({}/{})".format(curef, done_count, total_count))
print(ansi.UP_DEL, end="")
2018-02-11 00:24:01 +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))
2018-01-23 21:59:21 +00:00
print("Scan complete.")
2018-02-11 00:24:01 +00:00
write_info_if_dumps_found()