1
|
|
|
#!/usr/bin/env python3 |
2
|
4 |
|
"""This module is used for generation of URLs and related text files.""" |
3
|
|
|
|
4
|
4 |
|
from bbarchivist.networkutils import get_length # network |
5
|
4 |
|
from bbarchivist.utilities import create_bar_url, fsizer, generate_urls, stripper # utils |
6
|
|
|
|
7
|
4 |
|
__author__ = "Thurask" |
8
|
4 |
|
__license__ = "WTFPL v2" |
9
|
4 |
|
__copyright__ = "Copyright 2015-2016 Thurask" |
10
|
|
|
|
11
|
|
|
|
12
|
4 |
|
def system_link_writer(target, urls, avlty=False): |
13
|
|
|
""" |
14
|
|
|
Write OS/radio links to file. |
15
|
|
|
|
16
|
|
|
:param target: File to write to. |
17
|
|
|
:type target: file |
18
|
|
|
|
19
|
|
|
:param urls: Dictionary of URLs; name: URL |
20
|
|
|
:type urls: dict(str: str) |
21
|
|
|
|
22
|
|
|
:param avlty: If this OS release is available. Default is false. |
23
|
|
|
:type avlty: bool |
24
|
|
|
""" |
25
|
4 |
|
for key, val in urls.items(): |
26
|
4 |
|
if avlty: |
27
|
4 |
|
fsize = get_length(val) |
28
|
|
|
else: |
29
|
4 |
|
fsize = None |
30
|
4 |
|
target.write("{0} [{1}] {2}\n".format(key, fsizer(fsize), val)) |
31
|
|
|
|
32
|
|
|
|
33
|
4 |
|
def app_link_writer(target, urls): |
34
|
|
|
""" |
35
|
|
|
Write app links to file. |
36
|
|
|
|
37
|
|
|
:param target: File to write to. |
38
|
|
|
:type target: file |
39
|
|
|
|
40
|
|
|
:param urls: Dictionary of URLs; name: URL |
41
|
|
|
:type urls: dict(str: str) |
42
|
|
|
""" |
43
|
4 |
|
for app in urls: |
44
|
4 |
|
stoppers = ["8960", "8930", "8974", "m5730", "winchester"] |
45
|
4 |
|
if all(word not in app for word in stoppers): |
46
|
4 |
|
fsize = get_length(app) |
47
|
4 |
|
base = app.split('/')[-1] |
48
|
4 |
|
base = stripper(base) |
49
|
4 |
|
target.write("{0} [{1}] {2}\n".format(base, fsizer(fsize), app)) |
50
|
|
|
|
51
|
|
|
|
52
|
4 |
|
def dev_link_writer(target, finals): |
53
|
|
|
""" |
54
|
|
|
Write Dev Alpha autooloader links to file. |
55
|
|
|
|
56
|
|
|
:param target: File to write to. |
57
|
|
|
:type target: file |
58
|
|
|
|
59
|
|
|
:param finals: Dict of URL:content-length pairs. |
60
|
|
|
:type finals: dict(str: str) |
61
|
|
|
""" |
62
|
4 |
|
for key, val in finals.items(): |
63
|
4 |
|
target.write("{0} [{1}]\n".format(key, fsizer(int(val)))) |
64
|
|
|
|
65
|
|
|
|
66
|
4 |
|
def prep_thename(softwareversion, appendbars=False, temp=False): |
67
|
|
|
""" |
68
|
|
|
Generate name for output file. |
69
|
|
|
|
70
|
|
|
:param softwareversion: Software release version. |
71
|
|
|
:type softwareversion: str |
72
|
|
|
|
73
|
|
|
:param appendbars: Whether to add app bars to file. Default is false. |
74
|
|
|
:type appendbars: bool |
75
|
|
|
|
76
|
|
|
:param temp: If file we write to is temporary. Default is false. |
77
|
|
|
:type temp: bool |
78
|
|
|
""" |
79
|
4 |
|
thename = softwareversion |
80
|
4 |
|
if appendbars: |
81
|
4 |
|
thename += "plusapps" |
82
|
4 |
|
if temp: |
83
|
4 |
|
thename = "TEMPFILE" |
84
|
4 |
|
return thename |
85
|
|
|
|
86
|
|
|
|
87
|
4 |
|
def write_altsw(target, altsw): |
88
|
|
|
""" |
89
|
|
|
Write alternate software release to file. |
90
|
|
|
|
91
|
|
|
:param target: File to write to. |
92
|
|
|
:type target: file |
93
|
|
|
|
94
|
|
|
:param altsw: Radio software release version, if different. |
95
|
|
|
:type altsw: str |
96
|
|
|
""" |
97
|
4 |
|
if altsw is not None: |
98
|
4 |
|
target.write("RADIO SOFTWARE RELEASE: {0}\n".format(altsw)) |
99
|
|
|
|
100
|
|
|
|
101
|
4 |
|
def write_disclaimer(target, avlty): |
102
|
|
|
""" |
103
|
|
|
Write availability disclaimer to file. |
104
|
|
|
|
105
|
|
|
:param target: File to write to. |
106
|
|
|
:type target: file |
107
|
|
|
|
108
|
|
|
:param avlty: Availability of links to download. Default is false. |
109
|
|
|
:type avlty: bool |
110
|
|
|
""" |
111
|
4 |
|
if not avlty: |
112
|
4 |
|
target.write("\n!!EXISTENCE NOT GUARANTEED!!\n") |
113
|
|
|
|
114
|
|
|
|
115
|
4 |
|
def write_appbars(target, appendbars, appurls): |
116
|
|
|
""" |
117
|
|
|
Write app bar links to file. |
118
|
|
|
|
119
|
|
|
:param target: File to write to. |
120
|
|
|
:type target: file |
121
|
|
|
|
122
|
|
|
:param appendbars: Whether to add app bars to file. Default is false. |
123
|
|
|
:type appendbars: bool |
124
|
|
|
|
125
|
|
|
:param appurls: App bar URLs to add. |
126
|
|
|
:type softwareversion: list |
|
|
|
|
127
|
|
|
""" |
128
|
4 |
|
if appendbars: |
129
|
4 |
|
target.write("\nAPP URLS:\n") |
130
|
4 |
|
app_link_writer(target, appurls) |
131
|
|
|
|
132
|
|
|
|
133
|
4 |
|
def write_signedbars(target, urllist, avlty, message): |
134
|
|
|
""" |
135
|
|
|
Write debrick/core/radio URLs to file. |
136
|
|
|
|
137
|
|
|
:param target: File to write to. |
138
|
|
|
:type target: file |
139
|
|
|
|
140
|
|
|
:param urllist: List of URLs to write. |
141
|
|
|
:type urllist: list(str) |
142
|
|
|
|
143
|
|
|
:param avlty: Availability of links to download. Default is false. |
144
|
|
|
:type avlty: bool |
145
|
|
|
|
146
|
|
|
:param message: Header for this section: debrick, core or radio. |
147
|
|
|
:type message: str |
148
|
|
|
""" |
149
|
4 |
|
target.write("\n{0}:\n".format(message)) |
150
|
4 |
|
system_link_writer(target, urllist, avlty) |
151
|
|
|
|
152
|
|
|
|
153
|
4 |
|
def write_header(target, softwareversion, osversion, radioversion): |
154
|
|
|
""" |
155
|
|
|
Write header for file. |
156
|
|
|
|
157
|
|
|
:param target: File to write to. |
158
|
|
|
:type target: file |
159
|
|
|
|
160
|
|
|
:param softwareversion: Software release version. |
161
|
|
|
:type softwareversion: str |
162
|
|
|
|
163
|
|
|
:param osversion: OS version. |
164
|
|
|
:type osversion: str |
165
|
|
|
|
166
|
|
|
:param radioversion: Radio version. |
167
|
|
|
:type radioversion: str |
168
|
|
|
""" |
169
|
4 |
|
target.write("OS VERSION: {0}\n".format(osversion)) |
170
|
4 |
|
target.write("RADIO VERSION: {0}\n".format(radioversion)) |
171
|
4 |
|
target.write("SOFTWARE RELEASE: {0}\n".format(softwareversion)) |
172
|
|
|
|
173
|
|
|
|
174
|
4 |
|
def write_links(softwareversion, osversion, radioversion, osurls, coreurls, radiourls, |
175
|
|
|
avlty=False, appendbars=False, appurls=None, temp=False, altsw=None): |
176
|
|
|
""" |
177
|
|
|
Write lookup links to file. Check for availability, can include app bars. |
178
|
|
|
|
179
|
|
|
:param softwareversion: Software release version. |
180
|
|
|
:type softwareversion: str |
181
|
|
|
|
182
|
|
|
:param osversion: OS version. |
183
|
|
|
:type osversion: str |
184
|
|
|
|
185
|
|
|
:param radioversion: Radio version. |
186
|
|
|
:type radioversion: str |
187
|
|
|
|
188
|
|
|
:param osurls: Pre-formed debrick OS URLs. |
189
|
|
|
:type osurls: dict{str:str} |
190
|
|
|
|
191
|
|
|
:param coreurls: Pre-formed core OS URLs. |
192
|
|
|
:type coreurls: dict{str:str} |
193
|
|
|
|
194
|
|
|
:param radiourls: Pre-formed radio URLs. |
195
|
|
|
:type radiourls: dict{str:str} |
196
|
|
|
|
197
|
|
|
:param avlty: Availability of links to download. Default is false. |
198
|
|
|
:type avlty: bool |
199
|
|
|
|
200
|
|
|
:param appendbars: Whether to add app bars to file. Default is false. |
201
|
|
|
:type appendbars: bool |
202
|
|
|
|
203
|
|
|
:param appurls: App bar URLs to add. |
204
|
|
|
:type softwareversion: list |
205
|
|
|
|
206
|
|
|
:param temp: If file we write to is temporary. Default is false. |
207
|
|
|
:type temp: bool |
208
|
|
|
|
209
|
|
|
:param altsw: Radio software release version, if different. |
210
|
|
|
:type altsw: str |
211
|
|
|
""" |
212
|
4 |
|
thename = prep_thename(softwareversion, appendbars, temp) |
213
|
4 |
|
with open("{0}.txt".format(thename), "w") as target: |
214
|
4 |
|
write_header(target, softwareversion, osversion, radioversion) |
215
|
4 |
|
write_altsw(target, altsw) |
216
|
4 |
|
write_disclaimer(target, avlty) |
217
|
4 |
|
write_signedbars(target, osurls, avlty, "DEBRICK URLS") |
218
|
4 |
|
write_signedbars(target, coreurls, avlty, "CORE URLS") |
219
|
4 |
|
write_signedbars(target, radiourls, avlty, "RADIO URLS") |
220
|
4 |
|
write_appbars(target, appendbars, appurls) |
221
|
|
|
|
222
|
|
|
|
223
|
4 |
|
def export_devloader(osversion, finals): |
224
|
|
|
""" |
225
|
|
|
Export Dev Alpha URLs to file. |
226
|
|
|
|
227
|
|
|
:param osversion: OS version. |
228
|
|
|
:type osversion: str |
229
|
|
|
|
230
|
|
|
:param finals: Dict of URL:content-length pairs. |
231
|
|
|
:type finals: dict(str: str) |
232
|
|
|
""" |
233
|
4 |
|
with open("DevAlpha-{0}.txt".format(osversion), "w") as target: |
234
|
4 |
|
dev_link_writer(target, finals) |
235
|
|
|
|
236
|
|
|
|
237
|
4 |
|
def url_gen(osversion, radioversion, softwareversion): |
238
|
|
|
""" |
239
|
|
|
Return all debrick, core and radio URLs from given OS, radio software. |
240
|
|
|
|
241
|
|
|
:param softwareversion: Software release version. |
242
|
|
|
:type softwareversion: str |
243
|
|
|
|
244
|
|
|
:param osversion: OS version. |
245
|
|
|
:type osversion: str |
246
|
|
|
|
247
|
|
|
:param radioversion: Radio version. |
248
|
|
|
:type radioversion: str |
249
|
|
|
""" |
250
|
4 |
|
radlist = [ |
251
|
|
|
"STL100-1", |
252
|
|
|
"STL100-X/P9982", |
253
|
|
|
"STL100-4", |
254
|
|
|
"Q10/Q5/P9983", |
255
|
|
|
"Z30/LEAP/CLASSIC", |
256
|
|
|
"Z3", |
257
|
|
|
"PASSPORT" |
258
|
|
|
] |
259
|
4 |
|
oslist = [ |
260
|
|
|
"STL100-1", |
261
|
|
|
"QC8960", |
262
|
|
|
"VERIZON QC8960", |
263
|
|
|
"Z3", |
264
|
|
|
"PASSPORT" |
265
|
|
|
] |
266
|
4 |
|
oses, radios, cores = generate_urls(softwareversion, osversion, radioversion, True) |
267
|
4 |
|
vzw = create_bar_url(softwareversion, "qc8960.verizon_sfi.desktop", osversion) |
268
|
4 |
|
oses.insert(2, vzw) |
269
|
4 |
|
cores.insert(2, oses[2].replace(".desktop", "")) |
270
|
4 |
|
ospairs = {} |
271
|
4 |
|
for title, url in zip(oslist, oses): |
272
|
4 |
|
ospairs[title] = url |
273
|
4 |
|
corepairs = {} |
274
|
4 |
|
for title, url in zip(oslist, cores): |
275
|
4 |
|
corepairs[title] = url |
276
|
4 |
|
radiopairs = {} |
277
|
4 |
|
for title, url in zip(radlist, radios): |
278
|
4 |
|
radiopairs[title] = url |
279
|
|
|
return ospairs, corepairs, radiopairs |
280
|
|
|
|