|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
"""Check for new PRDs for TCL API devices.""" |
|
3
|
|
|
|
|
4
|
|
|
import sys # load arguments |
|
5
|
|
|
from bbarchivist import jsonutils # json |
|
6
|
|
|
from bbarchivist import scriptutils # default parser |
|
7
|
|
|
|
|
8
|
|
|
__author__ = "Thurask" |
|
9
|
|
|
__license__ = "WTFPL v2" |
|
10
|
|
|
__copyright__ = "2017 Thurask" |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
def grab_args(): |
|
14
|
|
|
""" |
|
15
|
|
|
Parse arguments from argparse/questionnaire. |
|
16
|
|
|
|
|
17
|
|
|
Invoke a function with those arguments. |
|
18
|
|
|
""" |
|
19
|
|
|
parser = scriptutils.default_parser("bb-tclnewprd", "Check for new PRDs for TCL devices") |
|
20
|
|
|
parser.add_argument("prd", help="Only scan one/custom PRD root", default=None, nargs="?") |
|
21
|
|
|
parser.add_argument( |
|
22
|
|
|
"-f", "--floor", |
|
23
|
|
|
dest="floor", |
|
24
|
|
|
help="When to start, default=1", |
|
25
|
|
|
default=1, |
|
26
|
|
|
type=int, |
|
27
|
|
|
choices=range(0, 998), |
|
28
|
|
|
metavar="INT") |
|
29
|
|
|
parser.add_argument( |
|
30
|
|
|
"-c", "--ceiling", |
|
31
|
|
|
dest="ceiling", |
|
32
|
|
|
help="When to stop, default=60", |
|
33
|
|
|
default=60, |
|
34
|
|
|
type=int, |
|
35
|
|
|
choices=range(1, 999), |
|
36
|
|
|
metavar="INT") |
|
37
|
|
|
args = parser.parse_args(sys.argv[1:]) |
|
38
|
|
|
parser.set_defaults() |
|
39
|
|
|
execute_args(args) |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def execute_args(args): |
|
43
|
|
|
""" |
|
44
|
|
|
Get args and decide what to do with them. |
|
45
|
|
|
|
|
46
|
|
|
:param args: Arguments. |
|
47
|
|
|
:type args: argparse.Namespace |
|
48
|
|
|
""" |
|
49
|
|
|
if args.ceiling < args.floor: |
|
50
|
|
|
print("INVALID RANGE!") |
|
51
|
|
|
raise SystemExit |
|
52
|
|
|
args.ceiling += 1 |
|
53
|
|
|
tclnewprd_main(args.prd, args.floor, args.ceiling) |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
def tclnewprd_main(prd=None, floor=1, ceiling=60): |
|
57
|
|
|
""" |
|
58
|
|
|
Scan every PRD and produce latest versions. |
|
59
|
|
|
|
|
60
|
|
|
:param prd: Specific PRD to check, None if we're checking all variants in database. Default is None. |
|
61
|
|
|
:type prd: str |
|
62
|
|
|
|
|
63
|
|
|
:param floor: When to start. Default is 1. |
|
64
|
|
|
:type floor: int |
|
65
|
|
|
|
|
66
|
|
|
:param ceiling: When to stop. Default is 60. |
|
67
|
|
|
:type ceiling: int |
|
68
|
|
|
""" |
|
69
|
|
|
scriptutils.slim_preamble("TCLNEWPRD") |
|
70
|
|
|
prdbase = jsonutils.load_json("prds") |
|
71
|
|
|
prddict = scriptutils.tcl_findprd_prepdict(prdbase) |
|
72
|
|
|
prddict = scriptutils.tcl_findprd_checkfilter(prddict, prd) |
|
73
|
|
|
scriptutils.tcl_findprd(prddict, floor, ceiling) |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
if __name__ == "__main__": |
|
77
|
|
|
grab_args() |
|
78
|
|
|
|