1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
"""Generate Dev Alpha autoloader URLs.""" |
3
|
|
|
|
4
|
|
|
import sys # load arguments |
5
|
|
|
|
6
|
|
|
import requests # session |
7
|
|
|
from bbarchivist import argutils # arguments |
8
|
|
|
from bbarchivist import decorators # wrap Ctrl+C |
9
|
|
|
from bbarchivist import jsonutils # json |
10
|
|
|
from bbarchivist import networkutils # check function |
11
|
|
|
from bbarchivist import textgenerator # export |
12
|
|
|
from bbarchivist import utilities # filesize |
13
|
|
|
|
14
|
|
|
__author__ = "Thurask" |
15
|
|
|
__license__ = "WTFPL v2" |
16
|
|
|
__copyright__ = "2015-2019 Thurask" |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
def grab_args(): |
20
|
|
|
""" |
21
|
|
|
Parse arguments from argparse/questionnaire. |
22
|
|
|
|
23
|
|
|
Invoke :func:`devloader.devloader_main` with arguments. |
24
|
|
|
""" |
25
|
|
|
if len(sys.argv) > 1: |
26
|
|
|
parser = argutils.default_parser("bb-devloader", "Dev Alpha URL generator") |
27
|
|
|
parser.add_argument( |
28
|
|
|
"os", |
29
|
|
|
help="OS version, 10.x.y.zzzz") |
30
|
|
|
parser.add_argument( |
31
|
|
|
"-l", "--loop", |
32
|
|
|
dest="recurse", |
33
|
|
|
help="Loop lookup, CTRL-C to quit", |
34
|
|
|
action="store_true", |
35
|
|
|
default=False) |
36
|
|
|
parser.add_argument( |
37
|
|
|
"-e", "--export", |
38
|
|
|
dest="export", |
39
|
|
|
help="Export links to files", |
40
|
|
|
action="store_true", |
41
|
|
|
default=False) |
42
|
|
|
parser.add_argument( |
43
|
|
|
"-i", "--increment", |
44
|
|
|
dest="increment", |
45
|
|
|
help="Loop increment, default = 3", |
46
|
|
|
default=3, |
47
|
|
|
type=argutils.positive_integer, |
48
|
|
|
metavar="INT") |
49
|
|
|
parser.add_argument( |
50
|
|
|
"-c", "--ceiling", |
51
|
|
|
dest="ceiling", |
52
|
|
|
help="When to stop script, default = 9996", |
53
|
|
|
default=9999, |
54
|
|
|
type=int, |
55
|
|
|
choices=range(1, 10000), |
56
|
|
|
metavar="INT") |
57
|
|
|
parser.set_defaults() |
58
|
|
|
args = parser.parse_args(sys.argv[1:]) |
59
|
|
|
devloader_main(args.os, args.export, args.recurse, args.ceiling, args.increment) |
60
|
|
|
else: |
61
|
|
|
osversion = input("OS VERSION: ") |
62
|
|
|
export = utilities.i2b("EXPORT TO FILE (Y/N)?: ") |
63
|
|
|
print(" ") |
64
|
|
|
devloader_main(osversion, export) |
65
|
|
|
decorators.enter_to_exit(True) |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
def devloader_exporter(osversion, export, urls): |
69
|
|
|
""" |
70
|
|
|
Handle exporting links to text/stdout. |
71
|
|
|
|
72
|
|
|
:param osversion: OS version. |
73
|
|
|
:type osversion: str |
74
|
|
|
|
75
|
|
|
:param export: If we write URLs to file. Default is false. |
76
|
|
|
:type export: bool |
77
|
|
|
|
78
|
|
|
:param urls: List of Dev Alpha URLs. |
79
|
|
|
:type urls: list(str) |
80
|
|
|
""" |
81
|
|
|
if export: |
82
|
|
|
print("EXPORTING...") |
83
|
|
|
textgenerator.export_devloader(osversion, urls) |
84
|
|
|
else: |
85
|
|
|
utilities.lprint(urls.keys()) |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
@decorators.wrap_keyboard_except |
89
|
|
|
def devloader_main(osversion, export=False, loop=False, ceiling=9999, inc=3): |
90
|
|
|
""" |
91
|
|
|
Wrap around :mod:`bbarchivist.networkutils` Dev Alpha autoloader searching. |
92
|
|
|
|
93
|
|
|
:param osversion: OS version. |
94
|
|
|
:type osversion: str |
95
|
|
|
|
96
|
|
|
:param export: If we write URLs to file. Default is false. |
97
|
|
|
:type export: bool |
98
|
|
|
|
99
|
|
|
:param loop: Whether or not to automatically lookup. Default is false. |
100
|
|
|
:type loop: bool |
101
|
|
|
|
102
|
|
|
:param ceiling: When to stop loop. Default is 9999 (i.e. 10.x.y.9999). |
103
|
|
|
:type ceiling: int |
104
|
|
|
|
105
|
|
|
:param inc: Lookup increment. Default is 3. |
106
|
|
|
:type inc: int |
107
|
|
|
""" |
108
|
|
|
skels = jsonutils.load_json('devskeletons') |
109
|
|
|
argutils.slim_preamble("DEVLOADER") |
110
|
|
|
sess = requests.Session() |
111
|
|
|
while True: |
112
|
|
|
if loop and int(osversion.split(".")[3]) > ceiling: |
113
|
|
|
break |
114
|
|
|
print("OS VERSION: {0}".format(osversion), end="\r") |
115
|
|
|
urls = networkutils.devalpha_urls_bootstrap(osversion, skels, sess) |
116
|
|
|
if urls: |
117
|
|
|
urls = networkutils.dev_dupe_cleaner(urls) |
118
|
|
|
print("{0} AVAILABLE! \n".format(osversion), end="\r") # spaces to clear line |
119
|
|
|
devloader_exporter(osversion, export, urls) |
120
|
|
|
if not loop: |
121
|
|
|
break |
122
|
|
|
else: |
123
|
|
|
if not loop: |
124
|
|
|
print("NOT FOUND! ", end="\r") |
125
|
|
|
break |
126
|
|
|
if loop: |
127
|
|
|
osversion = utilities.increment(osversion, inc) |
128
|
|
|
continue |
129
|
|
|
|
130
|
|
|
if __name__ == "__main__": |
131
|
|
|
grab_args() |
132
|
|
|
|