-
Notifications
You must be signed in to change notification settings - Fork 0
/
chromium-latest.py
executable file
·344 lines (280 loc) · 11.5 KB
/
chromium-latest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/usr/bin/python3
# Copyright 2010,2015-2019 Tom Callaway <[email protected]>
# Copyright 2013-2016 Tomas Popela <[email protected]>
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
try:
import argparse
optparse = False
except ImportError:
from optparse import OptionParser
optparse = True
import csv
import glob
import hashlib
import locale
import os
import shutil
import io
import sys
import urllib.request, urllib.parse, urllib.error
chromium_url = "http://commondatastorage.googleapis.com/chromium-browser-official/"
chromium_root_dir = "."
version_string = "stable"
name = 'Chromium Latest'
script_version = 0.9
my_description = '{0} {1}'.format(name, script_version)
def dlProgress(count, blockSize, totalSize):
if (totalSize <= blockSize):
percent = int(count * 100)
else:
percent = int(count * blockSize * 100 / totalSize)
sys.stdout.write("\r" + "Downloading ... %d%%" % percent)
sys.stdout.flush()
def delete_chromium_dir(ch_dir):
full_dir = "%s/%s" % (latest_dir, ch_dir)
print('Deleting %s ' % full_dir)
if os.path.isdir(full_dir):
shutil.rmtree(full_dir)
print('[DONE]')
else:
print('[NOT FOUND]')
def delete_chromium_files(files):
full_path = "%s/%s" % (latest_dir, files)
print('Deleting ' + full_path + ' ', end=' ')
for filename in glob.glob(full_path):
print('Deleting ' + filename + ' ', end=' ')
os.remove(filename)
print('[DONE]')
def check_omahaproxy(channel="stable"):
version = 0
status_url = "http://omahaproxy.appspot.com/all?os=linux&channel=" + channel
usock = urllib.request.urlopen(status_url)
status_dump = usock.read().decode('utf-8')
usock.close()
status_list = io.StringIO(status_dump)
status_reader = list(csv.reader(status_list, delimiter=','))
linux_channels = [s for s in status_reader if "linux" in s]
linux_channel = [s for s in linux_channels if channel in s]
version = linux_channel[0][2]
if version == 0:
print('I could not find the latest %s build. Bailing out.' % channel)
sys.exit(1)
else:
print('Latest Chromium Version on %s at %s is %s' % (channel, status_url, version))
return version
def remove_file_if_exists(filename):
if os.path.isfile("./%s" % filename):
try:
os.remove(filename)
except Exception:
pass
def download_file_and_compare_hashes(file_to_download):
hashes_file = '%s.hashes' % file_to_download
if (args.clean):
remove_file_if_exists(file_to_download)
remove_file_if_exists(hashes_file)
# Let's make sure we haven't already downloaded it.
tarball_local_file = "./%s" % file_to_download
if os.path.isfile(tarball_local_file):
print("%s already exists!" % file_to_download)
else:
path = '%s%s' % (chromium_url, file_to_download)
print("Downloading %s" % path)
# Perhaps look at using python-progressbar at some point?
info=urllib.request.urlretrieve(path, file_to_download, reporthook=dlProgress)[1]
urllib.request.urlcleanup()
print("")
if (info["Content-Type"] != "application/x-tar"):
print('Chromium tarballs for %s are not on servers.' % file_to_download)
remove_file_if_exists (file_to_download)
sys.exit(1)
hashes_local_file = "./%s" % hashes_file
if not os.path.isfile(hashes_local_file):
path = '%s%s' % (chromium_url, hashes_file)
print("Downloading %s" % path)
# Perhaps look at using python-progressbar at some point?
info=urllib.request.urlretrieve(path, hashes_file, reporthook=dlProgress)[1]
urllib.request.urlcleanup()
print("")
if os.path.isfile(hashes_local_file):
with open(hashes_local_file, "r") as input_file:
md5sum = input_file.readline().split()[1]
md5 = hashlib.md5()
with open(tarball_local_file, "rb") as f:
for block in iter(lambda: f.read(65536), b""):
md5.update(block)
if (md5sum == md5.hexdigest()):
print("MD5 matches for %s!" % file_to_download)
else:
print("MD5 mismatch for %s!" % file_to_download)
sys.exit(1)
else:
print("Cannot compare hashes for %s!" % file_to_download)
def download_version(version):
download_file_and_compare_hashes ('chromium-%s.tar.xz' % version)
if (args.tests):
download_file_and_compare_hashes ('chromium-%s-testdata.tar.xz' % version)
def nacl_versions(version):
if sys.version_info[0] == 2 and sys.version_info[1] == 6:
return
myvars = {}
chrome_dir = './chromium-%s' % version
with open(chrome_dir + "/native_client/tools/REVISIONS") as myfile:
for line in myfile:
name, var = line.partition("=")[::2]
myvars[name] = var
print("nacl-binutils commit: %s" % myvars["NACL_BINUTILS_COMMIT"])
print("nacl-gcc commit: %s" % myvars["NACL_GCC_COMMIT"])
print("nacl-newlib commit: %s" % myvars["NACL_NEWLIB_COMMIT"])
# Parse GIT_REVISIONS dict from toolchain_build.py
sys.path.append(os.path.abspath(chrome_dir + "/native_client/toolchain_build"))
from toolchain_build import GIT_REVISIONS
print("nacl-arm-binutils commit: %s" % GIT_REVISIONS['binutils']['rev'])
print("nacl-arm-gcc commit: %s" % GIT_REVISIONS['gcc']['rev'])
def download_chrome_latest_rpm(arch):
chrome_rpm = 'google-chrome-%s_current_%s.rpm' % (version_string, arch)
path = 'https://dl.google.com/linux/direct/%s' % chrome_rpm
if (args.clean):
remove_file_if_exists(chrome_rpm)
# Let's make sure we haven't already downloaded it.
if os.path.isfile("./%s" % chrome_rpm):
print("%s already exists!" % chrome_rpm)
else:
print("Downloading %s" % path)
# Perhaps look at using python-progressbar at some point?
info=urllib.request.urlretrieve(path, chrome_rpm, reporthook=dlProgress)[1]
urllib.request.urlcleanup()
print("")
if (info["Content-Type"] != "binary/octet-stream" and info["Content-Type"] != "application/x-redhat-package-manager"):
print('Chrome %s rpms are not on servers.' % version_string)
remove_file_if_exists (chrome_rpm)
sys.exit(1)
# This is where the magic happens
if __name__ == '__main__':
# Locale magic
locale.setlocale(locale.LC_ALL, '')
# Create the parser object
if optparse:
parser = OptionParser(description=my_description)
parser_add_argument = parser.add_option
else:
parser = argparse.ArgumentParser(description=my_description)
parser_add_argument = parser.add_argument
parser_add_argument(
'--ffmpegarm', action='store_true',
help='Leave arm sources when cleaning ffmpeg')
parser_add_argument(
'--beta', action='store_true',
help='Get the latest beta Chromium source')
parser_add_argument(
'--clean', action='store_true',
help='Re-download all previously downloaded sources')
parser_add_argument(
'--cleansources', action='store_true',
help='Get the latest Chromium release from given channel and clean various directories to from unnecessary or unwanted stuff')
parser_add_argument(
'--dev', action='store_true',
help='Get the latest dev Chromium source')
parser_add_argument(
'--ffmpegclean', action='store_true',
help='Get the latest Chromium release from given channel and cleans ffmpeg sources from proprietary stuff')
parser_add_argument(
'--chrome', action='store_true',
help='Get the latest Chrome rpms for the given channel')
parser_add_argument(
'--prep', action='store_true',
help='Prepare everything, but don\'t compress the result')
parser_add_argument(
'--stable', action='store_true',
help='Get the latest stable Chromium source')
parser_add_argument(
'--tests', action='store_true',
help='Get the additional data for running tests')
parser_add_argument(
'--version',
help='Download a specific version of Chromium')
parser_add_argument(
'--naclvers',
help='Display the commit versions of nacl toolchain components')
# Parse the args
if optparse:
args, options = parser.parse_args()
else:
args = parser.parse_args()
if args.stable:
version_string = "stable"
elif args.beta:
version_string = "beta"
elif args.dev:
version_string = "dev"
elif (not (args.stable or args.beta or args.dev)):
if (not args.version):
print('No version specified, downloading STABLE')
args.stable = True
chromium_version = args.version if args.version else check_omahaproxy(version_string)
if args.dev:
version_string = "unstable"
if args.chrome:
if args.version:
print('You cannot specify a Chrome RPM version!')
sys.exit(1)
latest = 'google-chrome-%s_current_i386' % version_string
download_chrome_latest_rpm("i386")
latest = 'google-chrome-%s_current_x86_64' % version_string
download_chrome_latest_rpm("x86_64")
if (not (args.ffmpegclean or args.tests)):
sys.exit(0)
latest = 'chromium-%s.tar.xz' % chromium_version
download_version(chromium_version)
# Lets make sure we haven't unpacked it already
latest_dir = "%s/chromium-%s" % (chromium_root_dir, chromium_version)
if (args.clean and os.path.isdir(latest_dir)):
shutil.rmtree(latest_dir)
if os.path.isdir(latest_dir):
print("%s already exists, perhaps %s has already been unpacked?" % (latest_dir, latest))
else:
print("Unpacking %s into %s, please wait." % (latest, latest_dir))
if (os.system("tar -xJf %s" % latest) != 0):
print("%s is possibly corrupted, exiting." % (latest))
sys.exit(1)
if (args.naclvers):
nacl_versions(chromium_version)
if (args.cleansources):
junk_dirs = ['third_party/WebKit/Tools/Scripts/webkitpy/layout_tests',
'webkit/data/layout_tests', 'third_party/hunspell/dictionaries',
'chrome/test/data', 'native_client/tests',
'third_party/WebKit/LayoutTests']
# First, the dirs:
for directory in junk_dirs:
delete_chromium_dir(directory)
# There has got to be a better, more portable way to do this.
os.system("find %s -depth -name reference_build -type d -exec rm -rf {} \;" % latest_dir)
# I could not find good bindings for xz/lzma support, so we system call here too.
chromium_clean_xz_file = "chromium-" + chromium_version + "-clean.tar.xz"
remove_file_if_exists(chromium_clean_xz_file)
if (args.ffmpegclean):
print("Cleaning ffmpeg from proprietary things...")
os.system("./clean_ffmpeg.sh %s %d" % (latest_dir, 0 if args.ffmpegarm else 1))
print("Done!")
if (not args.prep):
print("Compressing cleaned tree, please wait...")
os.chdir(chromium_root_dir)
os.system("tar --exclude=\.svn -cf - chromium-%s | xz -9 -T 0 -f > %s" % (chromium_version, chromium_clean_xz_file))
print("Finished!")