Completed
Push — master ( bca551...4fb5d7 )
by John
01:18
created

kernchecker_main()   C

Complexity

Conditions 7

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 7
c 2
b 0
f 1
dl 0
loc 26
rs 5.5
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__ = "Copyright 2015-2016 Thurask"
13
14
15
def kernchecker_main():
16
    """
17
    Wrap around :mod:`bbarchivist.networkutils` kernel checking.
18
    """
19
    parser = scriptutils.default_parser("bb-kernchecker", "Kernel version scraper.")
20
    parser.add_argument(
21
        "-u",
22
        "--utils",
23
        help="Check android-utils repo instead",
24
        action="store_true",
25
        default=False)
26
    args = parser.parse_args(sys.argv[1:])
27
    parser.set_defaults()
28
    scriptutils.slim_preamble("KERNCHECKER")
29
    tocheck = "UTILS" if args.utils else "KERNELS"
30
    print("\nCHECKING {0}...\n".format(tocheck))
31
    kernlist = networkutils.kernel_scraper(args.utils)
32
    splitkerns = [x.split("/") for x in kernlist]
33
    platforms = list({x[0] for x in splitkerns})
34
    kerndict = {x: [] for x in platforms}
35
    for kernel in splitkerns:
36
        kerndict[kernel[0]].append("\t{0}".format(kernel[1]))
37
    for board in kerndict.keys():
38
        print(board)
39
        utilities.lprint(sorted(kerndict[board], reverse=True))
40
    decorators.enter_to_exit(True)
41
42
43
if __name__ == "__main__":
44
    kernchecker_main()
45