Completed
Push — master ( c0a25d...3bf3d6 )
by John
03:47 queued 38s
created

tcldelta_main()   A

Complexity

Conditions 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
c 1
b 1
f 1
dl 0
loc 20
rs 9.4285
1
#!/usr/bin/env python3
2
"""Grab latest delta update for TCL API devices."""
3
4
import sys  # load arguments
5
from bbarchivist import decorators  # enter to exit
6
from bbarchivist import scriptutils  # default parser
7
8
__author__ = "Thurask"
9
__license__ = "WTFPL v2"
10
__copyright__ = "2017-2018 Thurask"
11
12
13 View Code Duplication
def grab_args():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
14
    """
15
    Parse arguments from argparse/questionnaire.
16
17
    Invoke a function with those arguments.
18
    """
19
    parser = scriptutils.default_parser("bb-tcldelta", "Check for delta updates for TCL devices")
20
    parser.add_argument("curef", help="PRD to check", default=None, nargs="?")
21
    parser.add_argument("fvver", help="Current OS version", default=None, nargs="?")
22
    parser.add_argument(
23
        "-d",
24
        "--download",
25
        dest="download",
26
        help="Download update file",
27
        action="store_true",
28
        default=False)
29
    parser.add_argument(
30
        "-o",
31
        "--original-filename",
32
        dest="original",
33
        help="Save with original filename (implies -d)",
34
        action="store_true",
35
        default=False)
36
    parser.add_argument(
37
        "-x",
38
        "--export",
39
        dest="export",
40
        help="Write XML to logs folder",
41
        action="store_true",
42
        default=False)
43
    args = parser.parse_args(sys.argv[1:])
44
    parser.set_defaults()
45
    if None in (args.curef, args.fvver):
46
        args = questionnaire(args)
47
    tcldelta_main(args.curef, args.fvver, args.download, args.original, args.export)
48
    decorators.enter_to_exit(True)
49
50
51
def questionnaire(args):
52
    """
53
    Clear up missing arguments.
54
55
    :param args: Arguments.
56
    :type args: argparse.Namespace
57
    """
58
    if args.curef is None:
59
        args.curef = input("CUREF: ")
60
    if args.fvver is None:
61
        args.fvver = input("STARTING OS: ")
62
    return args
63
64
65
def tcldelta_main(curef, fvver, download=False, original=False, export=False):
66
    """
67
    Scan one PRD and produce download URL and filename.
68
69
    :param curef: PRD of the phone variant to check.
70
    :type curef: str
71
72
    :param fvver: Current firmware version.
73
    :type fvver: str
74
75
    :param download: If we'll download the file that this returns. Default is False.
76
    :type download: bool
77
78
    :param original: If we'll download the file with its original filename instead of delta-safe. Default is False.
79
    :type original: bool
80
81
    :param export: Whether to export XML response to file. Default is False.
82
    :type export: bool
83
    """
84
    scriptutils.tcl_prd_scan(curef, download, mode=2, fvver=fvver, original=original, export=export)
85
86
87
if __name__ == "__main__":
88
    grab_args()
89