Completed
Push — master ( 179bce...f223e9 )
by John
03:31
created

infogenerator_main()   A

Complexity

Conditions 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
1
#!/usr/bin/env python3
2
"""Makes a nice info file for a folder of autoloaders."""
3
4
import sys  # load arguments
5
import os  # path operations
6
from bbarchivist import utilities  # input validation
7
from bbarchivist import scriptutils  # default parser
8
9
__author__ = "Thurask"
10
__license__ = "WTFPL v2"
11
__copyright__ = "2016-2017 Thurask"
12
13
14
def grab_args():
15
    """
16
    Parse arguments from argparse/questionnaire.
17
18
    Invoke :func:`bbarchivist.scriptutils.make_info` with those arguments.
19
    """
20
    if len(sys.argv) > 1:
21
        parser = scriptutils.default_parser("bb-infogen", "Generate info files", flags=("folder", "osr"))
22
        parser.add_argument(
23
            "-d",
24
            "--device",
25
            help="Device (Android only)",
26
            nargs="?",
27
            default=None,
28
            type=utilities.droidlookup_devicetype)
29
        parser.set_defaults()
30
        args = parser.parse_args(sys.argv[1:])
31
        execute_args(args)
32
    else:
33
        questionnaire()
34
35
36
def questionnaire():
37
    """
38
    Questions to ask if no arguments given.
39
    """
40
    folder = os.getcwd()
41
    osver = input("OS VERSION: ")
42
    android = utilities.s2b(input("ANDROID OS (Y/N)?: "))
43
    if android:
44
        device = input("DEVICE: ")
45
        radio = None
46
        software = None
47
    else:
48
        device = None
49
        radio = input("RADIO VERSION: ")
50
        software = input("SOFTWARE RELEASE: ")
51
    print(" ")
52
    infogenerator_main(folder, osver, radio, software, device)
53
54
55
def execute_args(args):
56
    """
57
    Get args and decide what to do with them.
58
59
    :param args: Arguments.
60
    :type args: argparse.Namespace
61
    """
62
    args.folder = utilities.dirhandler(args.folder, os.getcwd())
63
    infogenerator_main(args.folder, args.os, args.radio, args.swrelease, args.device)
64
65
66
def infogenerator_main(folder, osver, radio=None, swrelease=None, device=None):
0 ignored issues
show
Unused Code introduced by
The argument swrelease seems to be unused.
Loading history...
67
    """
68
    Wrap around :mod:`bbarchivist.scriptutils` info generation.
69
70
    :param folder: Path to folder to analyze.
71
    :type folder: str
72
73
    :param osver: OS version, required for both types.
74
    :type osver: str
75
76
    :param radio: Radio version, required for QNX.
77
    :type radio: str
78
79
    :param swrelease: Software release, required for QNX.
80
    :type swrelease: str
81
82
    :param device: Device type, required for Android.
83
    :type device: str
84
    """
85
    scriptutils.make_info(folder, osver, radio, software, device)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'software'
Loading history...
86
87
88
if __name__ == "__main__":
89
    grab_args()
90