1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
"""This module is used for generation of URLs and related text files.""" |
3
|
|
|
|
4
|
|
|
from bbarchivist.networkutils import create_base_url, get_length # network |
5
|
|
|
from bbarchivist.utilities import fsizer, generate_urls, stripper # utils |
6
|
|
|
|
7
|
|
|
__author__ = "Thurask" |
8
|
|
|
__license__ = "WTFPL v2" |
9
|
|
|
__copyright__ = "Copyright 2015-2016 Thurask" |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
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
|
|
|
for key, val in urls.items(): |
26
|
|
|
if avlty: |
27
|
|
|
fsize = get_length(val) |
28
|
|
|
else: |
29
|
|
|
fsize = None |
30
|
|
|
target.write("{0} [{1}] {2}\n".format(key, fsizer(fsize), val)) |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
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
|
|
|
for app in urls: |
44
|
|
|
stoppers = ["8960", "8930", "8974", "m5730", "winchester"] |
45
|
|
|
if all(word not in app for word in stoppers): |
46
|
|
|
fsize = get_length(app) |
47
|
|
|
base = app.split('/')[-1] |
48
|
|
|
base = stripper(base) |
49
|
|
|
target.write("{0} [{1}] {2}\n".format(base, fsizer(fsize), app)) |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
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
|
|
|
for key, val in finals.items(): |
63
|
|
|
target.write("{0} [{1}]\n".format(key, fsizer(int(val)))) |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
def write_links(softwareversion, osversion, radioversion, |
67
|
|
|
osurls, coreurls, radiourls, avlty=False, |
68
|
|
|
appendbars=False, appurls=None, temp=False, altsw=None): |
69
|
|
|
""" |
70
|
|
|
Write lookup links to file. Check for availability, can include app bars. |
71
|
|
|
|
72
|
|
|
:param softwareversion: Software release version. |
73
|
|
|
:type softwareversion: str |
74
|
|
|
|
75
|
|
|
:param osversion: OS version. |
76
|
|
|
:type osversion: str |
77
|
|
|
|
78
|
|
|
:param radioversion: Radio version. |
79
|
|
|
:type radioversion: str |
80
|
|
|
|
81
|
|
|
:param osurls: Pre-formed debrick OS URLs. |
82
|
|
|
:type osurls: dict{str:str} |
83
|
|
|
|
84
|
|
|
:param coreurls: Pre-formed core OS URLs. |
85
|
|
|
:type coreurls: dict{str:str} |
86
|
|
|
|
87
|
|
|
:param radiourls: Pre-formed radio URLs. |
88
|
|
|
:type radiourls: dict{str:str} |
89
|
|
|
|
90
|
|
|
:param avlty: Availability of links to download. Default is false. |
91
|
|
|
:type avlty: bool |
92
|
|
|
|
93
|
|
|
:param appendbars: Whether to add app bars to file. Default is false. |
94
|
|
|
:type appendbars: bool |
95
|
|
|
|
96
|
|
|
:param appurls: App bar URLs to add. |
97
|
|
|
:type softwareversion: list |
98
|
|
|
|
99
|
|
|
:param temp: If file we write to is temporary. |
100
|
|
|
:type temp: bool |
101
|
|
|
|
102
|
|
|
:param altsw: Radio software release version, if different. |
103
|
|
|
:type altsw: str |
104
|
|
|
""" |
105
|
|
|
thename = softwareversion |
106
|
|
|
if appendbars: |
107
|
|
|
thename += "plusapps" |
108
|
|
|
if temp: |
109
|
|
|
thename = "TEMPFILE" |
110
|
|
|
with open("{0}.txt".format(thename), "w") as target: |
111
|
|
|
target.write("OS VERSION: {0}\n".format(osversion)) |
112
|
|
|
target.write("RADIO VERSION: {0}\n".format(radioversion)) |
113
|
|
|
target.write("SOFTWARE RELEASE: {0}\n".format(softwareversion)) |
114
|
|
|
if altsw is not None: |
115
|
|
|
target.write("RADIO SOFTWARE RELEASE: {0}\n".format(altsw)) |
116
|
|
|
if not avlty: |
117
|
|
|
target.write("\n!!EXISTENCE NOT GUARANTEED!!\n") |
118
|
|
|
target.write("\nDEBRICK URLS:\n") |
119
|
|
|
system_link_writer(target, osurls, avlty) |
120
|
|
|
target.write("\nCORE URLS:\n") |
121
|
|
|
system_link_writer(target, coreurls, avlty) |
122
|
|
|
target.write("\nRADIO URLS:\n") |
123
|
|
|
system_link_writer(target, radiourls, avlty) |
124
|
|
|
if appendbars: |
125
|
|
|
target.write("\nAPP URLS:\n") |
126
|
|
|
app_link_writer(target, appurls) |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
def export_devloader(osversion, finals): |
130
|
|
|
""" |
131
|
|
|
Export Dev Alpha URLs to file. |
132
|
|
|
|
133
|
|
|
:param osversion: OS version. |
134
|
|
|
:type osversion: str |
135
|
|
|
|
136
|
|
|
:param finals: Dict of URL:content-length pairs. |
137
|
|
|
:type finals: dict(str: str) |
138
|
|
|
""" |
139
|
|
|
with open("DevAlpha-{0}.txt".format(osversion), "w") as target: |
140
|
|
|
dev_link_writer(target, finals) |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
def url_gen(osversion, radioversion, softwareversion): |
144
|
|
|
""" |
145
|
|
|
Return all debrick, core and radio URLs from given OS, radio software. |
146
|
|
|
|
147
|
|
|
:param softwareversion: Software release version. |
148
|
|
|
:type softwareversion: str |
149
|
|
|
|
150
|
|
|
:param osversion: OS version. |
151
|
|
|
:type osversion: str |
152
|
|
|
|
153
|
|
|
:param radioversion: Radio version. |
154
|
|
|
:type radioversion: str |
155
|
|
|
""" |
156
|
|
|
baseurl = create_base_url(softwareversion) |
157
|
|
|
radlist = [ |
158
|
|
|
"STL100-1", |
159
|
|
|
"STL100-X/P9982", |
160
|
|
|
"STL100-4", |
161
|
|
|
"Q10/Q5/P9983", |
162
|
|
|
"Z30/LEAP/CLASSIC", |
163
|
|
|
"Z3", |
164
|
|
|
"PASSPORT" |
165
|
|
|
] |
166
|
|
|
oslist = [ |
167
|
|
|
"STL100-1", |
168
|
|
|
"QC8960", |
169
|
|
|
"VERIZON QC8960", |
170
|
|
|
"Z3", |
171
|
|
|
"PASSPORT" |
172
|
|
|
] |
173
|
|
|
oses, radios, cores = generate_urls(baseurl, osversion, radioversion, True) |
174
|
|
|
vzw = "/{0}-{1}-{2}".format("qc8960.verizon_sfi.desktop", osversion, "nto+armle-v7+signed.bar") |
175
|
|
|
oses.insert(2, baseurl + vzw) |
176
|
|
|
cores.insert(2, oses[2].replace(".desktop", "")) |
177
|
|
|
ospairs = {} |
178
|
|
|
for title, url in zip(oslist, oses): |
179
|
|
|
ospairs[title] = url |
180
|
|
|
corepairs = {} |
181
|
|
|
for title, url in zip(oslist, cores): |
182
|
|
|
corepairs[title] = url |
183
|
|
|
radiopairs = {} |
184
|
|
|
for title, url in zip(radlist, radios): |
185
|
|
|
radiopairs[title] = url |
186
|
|
|
return ospairs, corepairs, radiopairs |
187
|
|
|
|