Completed
Push — master ( 50b3ee...e3adfe )
by John
02:43
created

kernchecker_prep()   B

Complexity

Conditions 5

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
dl 0
loc 13
rs 8.5454
1
#!/usr/bin/env python3
2
"""Checks BlackBerry's Android kernel repo for available branches."""
3
4
import sys  # load arguments
5
from bbarchivist import decorators  # enter to exit
6
from bbarchivist import networkutils  # check function
7
from bbarchivist import scriptutils  # default parser
8
from bbarchivist import utilities  # lprint
9
10
__author__ = "Thurask"
11
__license__ = "WTFPL v2"
12
__copyright__ = "2015-2017 Thurask"
13
14
15
def grab_args():
16
    """
17
    Parse arguments from argparse/questionnaire.
18
19
    Invoke :func:`kernchecker.kernchecker_main` with those arguments.
20
    """
21
    parser = scriptutils.default_parser("bb-kernchecker", "Kernel version scraper.")
22
    parser.add_argument(
23
        "-u",
24
        "--utils",
25
        help="Check android-utils repo instead",
26
        action="store_true",
27
        default=False)
28
    args = parser.parse_args(sys.argv[1:])
29
    parser.set_defaults()
30
    kernchecker_main(args.utils)
31
32
33
def kernchecker_prep(kernlist):
34
    """
35
    Prepare output from kernel list.
36
37
    :param kernlist: List of kernel URLs.
38
    :type kernlist: list(str)
39
    """
40
    splitkerns = [x.split("/") for x in kernlist]
41
    platforms = list({x[0] for x in splitkerns})
42
    kerndict = {x: [] for x in platforms}
43
    for kernel in splitkerns:
44
        kerndict[kernel[0]].append("\t{0}".format(kernel[1]))
45
    return kerndict
46
47
48
def kernchecker_main(utils=False):
0 ignored issues
show
Unused Code introduced by
The argument utils seems to be unused.
Loading history...
49
    """
50
    Wrap around :mod:`bbarchivist.networkutils` kernel checking.
51
52
    :param utils: If we're checking utilities rather than kernels.
53
    :type utils: bool
54
    """
55
    scriptutils.slim_preamble("KERNCHECKER")
56
    tocheck = "UTILS" if args.utils else "KERNELS"
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'args'
Loading history...
57
    print("\nCHECKING {0}...\n".format(tocheck))
58
    kernlist = networkutils.kernel_scraper(args.utils)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'args'
Loading history...
59
    kerndict = kernchecker_prep(kernlist)
60
    for board in kerndict.keys():
61
        print(board)
62
        utilities.lprint(sorted(kerndict[board], reverse=True))
63
    decorators.enter_to_exit(True)
64
65
66
if __name__ == "__main__":
67
    grab_args()
68