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