Completed
Push — master ( d294ee...3e0e3f )
by John
01:19
created

devloader_main()   A

Complexity

Conditions 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
c 1
b 0
f 1
dl 0
loc 21
rs 9.3142
1
#!/usr/bin/env python3
2
"""Generate Dev Alpha autoloader URLs."""
3
4
import sys  # load arguments
5
from bbarchivist import networkutils  # check function
6
from bbarchivist import jsonutils  # json
7
from bbarchivist import scriptutils  # default parser
8
from bbarchivist import textgenerator  # export
9
from bbarchivist import utilities  # filesize
10
11
__author__ = "Thurask"
12
__license__ = "WTFPL v2"
13
__copyright__ = "Copyright 2015-2016 Thurask"
14
15
16
def grab_args():
17
    """
18
    Parse arguments from argparse/questionnaire.
19
20
    Invoke :func:`devloader.devloader_main` with arguments.
21
    """
22
    if len(sys.argv) > 1:
23
        parser = scriptutils.default_parser("bb-devloader", "Dev Alpha URL generator")
24
        parser.add_argument(
25
            "os",
26
            help="OS version, 10.x.y.zzzz")
27
        parser.add_argument(
28
            "-e", "--export",
29
            dest="export",
30
            help="Export links to files",
31
            action="store_true",
32
            default=False)
33
        parser.set_defaults()
34
        args = parser.parse_args(sys.argv[1:])
35
        devloader_main(args.os, args.export)
36
    else:
37
        osversion = input("OS VERSION: ")
38
        export = utilities.s2b(input("EXPORT TO FILE?: "))
39
        print(" ")
40
        devloader_main(osversion, export)
41
        scriptutils.enter_to_exit(True)
42
43
44
def devloader_main(osversion, export=False):
45
    """
46
    Wrap around :mod:`bbarchivist.networkutils` Dev Alpha autoloader searching.
47
48
    :param osversion: OS version.
49
    :type osversion: str
50
51
    :param export: If we write URLs to file. Default is false.
52
    :type export: bool
53
    """
54
    skels = jsonutils.load_json('devskeletons')
55
    scriptutils.slim_preamble("DEVLOADER")
56
    print("OS VERSION: {0}".format(osversion))
57
    print("\nGENERATING...\n")
58
    urls = networkutils.devalpha_urls(osversion, skels)
59
    urls = networkutils.dev_dupe_cleaner(urls)
60
    if export:
61
        print("EXPORTING...")
62
        textgenerator.export_devloader(osversion, urls)
63
    else:
64
        scriptutils.lprint(urls.keys())
65
66
if __name__ == "__main__":
67
    grab_args()
68