tclcheck_allota   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 0
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
# pylint: disable=C0111,C0326,C0103
5
6
"""Check all/given PRDs for OTA updates."""
7
8
import sys
9
10
from tcllib import ansi, argparser, devlist
11
from tcllib.devices import MobileDevice
12
from tcllib.dumpmgr import write_info_if_dumps_found
13
from tcllib.requests import CheckRequest, RequestRunner, ServerVoteSelector
14
15
16
dev = MobileDevice()
17
18
dpdesc = """
19
    Checks for the latest OTA updates for all PRD numbers or only for the PRD specified
20
    as prd. Initial software version can be specified with forcever.
21
    """
22
dp = argparser.DefaultParser(__file__, dpdesc)
23
dp.add_argument("forcever", help="Initial software version to check for OTA updates, e.g. AAM481", nargs="?", default=None)
24
dp.add_argument("-p", "--prd", help="CU Reference # to filter scan results", dest="tocheck", nargs="?", default=None, metavar="PRD")
25
dp.add_argument("-l", "--local", help="Force using local database", dest="local", action="store_true", default=False)
26
args = dp.parse_args(sys.argv[1:])
27
28
if args.forcever is not None:
29
    force_ver_text = " from {}".format(args.forcever)
30
else:
31
    force_ver_text = ""
32
33
prdcheck = "" if args.tocheck is None else args.tocheck
34
35
print("Loading list of devices.")
36
prds = devlist.get_devicelist(local=args.local)
37
38
print("List of latest OTA firmware{} by PRD:".format(force_ver_text))
39
40
runner = RequestRunner(ServerVoteSelector())
41
runner.max_tries = 20
42
43
for prd, variant in prds.items():
44
    if "PRD" not in prd:
45
        continue
46
    model = variant["variant"]
47
    lastver = variant["last_ota"]
48
    lastver = variant["last_full"] if lastver is None else lastver
49
    if args.forcever is not None:
50
        lastver = args.forcever
51
    if not prdcheck in prd:
52
        continue
53
    dev.curef = prd
54
    dev.fwver = lastver
55
    chk = CheckRequest(dev)
56
    runner.run(chk)
57
    if chk.success:
58
        result = chk.get_result()
59
        versioninfo = ansi.YELLOW_DARK + result.fvver + ansi.RESET + " ⇨ " + ansi.YELLOW + result.tvver + ansi.RESET + " (FULL: {})".format(variant["last_full"])
60
        print("{}: {} {} ({})".format(prd, versioninfo, result.filehash, model))
61
    else:
62
        print("{} ({}): {}".format(prd, lastver, chk.error))
63
64
write_info_if_dumps_found()
65