update chromium-latest.py to Python3

epel8
Tom Callaway 5 years ago
parent ec9d075ebb
commit 9bb933dc67

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python3
# Copyright 2010,2015-2016 Tom Callaway <tcallawa@redhat.com> # Copyright 2010,2015-2019 Tom Callaway <tcallawa@redhat.com>
# Copyright 2013-2016 Tomas Popela <tpopela@redhat.com> # Copyright 2013-2016 Tomas Popela <tpopela@redhat.com>
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -32,9 +32,9 @@ import hashlib
import locale import locale
import os import os
import shutil import shutil
import StringIO import io
import sys import sys
import urllib import urllib.request, urllib.parse, urllib.error
chromium_url = "http://commondatastorage.googleapis.com/chromium-browser-official/" chromium_url = "http://commondatastorage.googleapis.com/chromium-browser-official/"
@ -59,22 +59,22 @@ def dlProgress(count, blockSize, totalSize):
def delete_chromium_dir(ch_dir): def delete_chromium_dir(ch_dir):
full_dir = "%s/%s" % (latest_dir, ch_dir) full_dir = "%s/%s" % (latest_dir, ch_dir)
print 'Deleting %s ' % full_dir print('Deleting %s ' % full_dir)
if os.path.isdir(full_dir): if os.path.isdir(full_dir):
shutil.rmtree(full_dir) shutil.rmtree(full_dir)
print '[DONE]' print('[DONE]')
else: else:
print '[NOT FOUND]' print('[NOT FOUND]')
def delete_chromium_files(files): def delete_chromium_files(files):
full_path = "%s/%s" % (latest_dir, files) full_path = "%s/%s" % (latest_dir, files)
print 'Deleting ' + full_path + ' ', print('Deleting ' + full_path + ' ', end=' ')
for filename in glob.glob(full_path): for filename in glob.glob(full_path):
print 'Deleting ' + filename + ' ', print('Deleting ' + filename + ' ', end=' ')
os.remove(filename) os.remove(filename)
print '[DONE]' print('[DONE]')
def check_omahaproxy(channel="stable"): def check_omahaproxy(channel="stable"):
@ -82,20 +82,20 @@ def check_omahaproxy(channel="stable"):
version = 0 version = 0
status_url = "http://omahaproxy.appspot.com/all?os=linux&channel=" + channel status_url = "http://omahaproxy.appspot.com/all?os=linux&channel=" + channel
usock = urllib.urlopen(status_url) usock = urllib.request.urlopen(status_url)
status_dump = usock.read() status_dump = usock.read().decode('utf-8')
usock.close() usock.close()
status_list = StringIO.StringIO(status_dump) status_list = io.StringIO(status_dump)
status_reader = list(csv.reader(status_list, delimiter=',')) status_reader = list(csv.reader(status_list, delimiter=','))
linux_channels = [s for s in status_reader if "linux" in s] linux_channels = [s for s in status_reader if "linux" in s]
linux_channel = [s for s in linux_channels if channel in s] linux_channel = [s for s in linux_channels if channel in s]
version = linux_channel[0][2] version = linux_channel[0][2]
if version == 0: if version == 0:
print 'I could not find the latest %s build. Bailing out.' % channel print('I could not find the latest %s build. Bailing out.' % channel)
sys.exit(1) sys.exit(1)
else: else:
print 'Latest Chromium Version on %s at %s is %s' % (channel, status_url, version) print('Latest Chromium Version on %s at %s is %s' % (channel, status_url, version))
return version return version
@ -119,27 +119,27 @@ def download_file_and_compare_hashes(file_to_download):
# Let's make sure we haven't already downloaded it. # Let's make sure we haven't already downloaded it.
tarball_local_file = "./%s" % file_to_download tarball_local_file = "./%s" % file_to_download
if os.path.isfile(tarball_local_file): if os.path.isfile(tarball_local_file):
print "%s already exists!" % file_to_download print("%s already exists!" % file_to_download)
else: else:
path = '%s%s' % (chromium_url, file_to_download) path = '%s%s' % (chromium_url, file_to_download)
print "Downloading %s" % path print("Downloading %s" % path)
# Perhaps look at using python-progressbar at some point? # Perhaps look at using python-progressbar at some point?
info=urllib.urlretrieve(path, file_to_download, reporthook=dlProgress)[1] info=urllib.request.urlretrieve(path, file_to_download, reporthook=dlProgress)[1]
urllib.urlcleanup() urllib.request.urlcleanup()
print "" print("")
if (info["Content-Type"] != "application/x-tar"): if (info["Content-Type"] != "application/x-tar"):
print 'Chromium tarballs for %s are not on servers.' % file_to_download print('Chromium tarballs for %s are not on servers.' % file_to_download)
remove_file_if_exists (file_to_download) remove_file_if_exists (file_to_download)
sys.exit(1) sys.exit(1)
hashes_local_file = "./%s" % hashes_file hashes_local_file = "./%s" % hashes_file
if not os.path.isfile(hashes_local_file): if not os.path.isfile(hashes_local_file):
path = '%s%s' % (chromium_url, hashes_file) path = '%s%s' % (chromium_url, hashes_file)
print "Downloading %s" % path print("Downloading %s" % path)
# Perhaps look at using python-progressbar at some point? # Perhaps look at using python-progressbar at some point?
info=urllib.urlretrieve(path, hashes_file, reporthook=dlProgress)[1] info=urllib.request.urlretrieve(path, hashes_file, reporthook=dlProgress)[1]
urllib.urlcleanup() urllib.request.urlcleanup()
print "" print("")
if os.path.isfile(hashes_local_file): if os.path.isfile(hashes_local_file):
with open(hashes_local_file, "r") as input_file: with open(hashes_local_file, "r") as input_file:
@ -149,12 +149,12 @@ def download_file_and_compare_hashes(file_to_download):
for block in iter(lambda: f.read(65536), b""): for block in iter(lambda: f.read(65536), b""):
md5.update(block) md5.update(block)
if (md5sum == md5.hexdigest()): if (md5sum == md5.hexdigest()):
print "MD5 matches for %s!" % file_to_download print("MD5 matches for %s!" % file_to_download)
else: else:
print "MD5 mismatch for %s!" % file_to_download print("MD5 mismatch for %s!" % file_to_download)
sys.exit(1) sys.exit(1)
else: else:
print "Cannot compare hashes for %s!" % file_to_download print("Cannot compare hashes for %s!" % file_to_download)
def download_version(version): def download_version(version):
@ -175,16 +175,16 @@ def nacl_versions(version):
for line in myfile: for line in myfile:
name, var = line.partition("=")[::2] name, var = line.partition("=")[::2]
myvars[name] = var myvars[name] = var
print "nacl-binutils commit: %s" % myvars["NACL_BINUTILS_COMMIT"] print("nacl-binutils commit: %s" % myvars["NACL_BINUTILS_COMMIT"])
print "nacl-gcc commit: %s" % myvars["NACL_GCC_COMMIT"] print("nacl-gcc commit: %s" % myvars["NACL_GCC_COMMIT"])
print "nacl-newlib commit: %s" % myvars["NACL_NEWLIB_COMMIT"] print("nacl-newlib commit: %s" % myvars["NACL_NEWLIB_COMMIT"])
# Parse GIT_REVISIONS dict from toolchain_build.py # Parse GIT_REVISIONS dict from toolchain_build.py
sys.path.append(os.path.abspath(chrome_dir + "/native_client/toolchain_build")) sys.path.append(os.path.abspath(chrome_dir + "/native_client/toolchain_build"))
from toolchain_build import GIT_REVISIONS from toolchain_build import GIT_REVISIONS
print "nacl-arm-binutils commit: %s" % GIT_REVISIONS['binutils']['rev'] print("nacl-arm-binutils commit: %s" % GIT_REVISIONS['binutils']['rev'])
print "nacl-arm-gcc commit: %s" % GIT_REVISIONS['gcc']['rev'] print("nacl-arm-gcc commit: %s" % GIT_REVISIONS['gcc']['rev'])
def download_chrome_latest_rpm(arch): def download_chrome_latest_rpm(arch):
@ -197,15 +197,15 @@ def download_chrome_latest_rpm(arch):
# Let's make sure we haven't already downloaded it. # Let's make sure we haven't already downloaded it.
if os.path.isfile("./%s" % chrome_rpm): if os.path.isfile("./%s" % chrome_rpm):
print "%s already exists!" % chrome_rpm print("%s already exists!" % chrome_rpm)
else: else:
print "Downloading %s" % path print("Downloading %s" % path)
# Perhaps look at using python-progressbar at some point? # Perhaps look at using python-progressbar at some point?
info=urllib.urlretrieve(path, chrome_rpm, reporthook=dlProgress)[1] info=urllib.request.urlretrieve(path, chrome_rpm, reporthook=dlProgress)[1]
urllib.urlcleanup() urllib.request.urlcleanup()
print "" print("")
if (info["Content-Type"] != "binary/octet-stream" and info["Content-Type"] != "application/x-redhat-package-manager"): 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 print('Chrome %s rpms are not on servers.' % version_string)
remove_file_if_exists (chrome_rpm) remove_file_if_exists (chrome_rpm)
sys.exit(1) sys.exit(1)
@ -274,7 +274,7 @@ if __name__ == '__main__':
version_string = "dev" version_string = "dev"
elif (not (args.stable or args.beta or args.dev)): elif (not (args.stable or args.beta or args.dev)):
if (not args.version): if (not args.version):
print 'No version specified, downloading STABLE' print('No version specified, downloading STABLE')
args.stable = True args.stable = True
chromium_version = args.version if args.version else check_omahaproxy(version_string) chromium_version = args.version if args.version else check_omahaproxy(version_string)
@ -284,7 +284,7 @@ if __name__ == '__main__':
if args.chrome: if args.chrome:
if args.version: if args.version:
print 'You cannot specify a Chrome RPM version!' print('You cannot specify a Chrome RPM version!')
sys.exit(1) sys.exit(1)
latest = 'google-chrome-%s_current_i386' % version_string latest = 'google-chrome-%s_current_i386' % version_string
download_chrome_latest_rpm("i386") download_chrome_latest_rpm("i386")
@ -303,11 +303,11 @@ if __name__ == '__main__':
shutil.rmtree(latest_dir) shutil.rmtree(latest_dir)
if os.path.isdir(latest_dir): if os.path.isdir(latest_dir):
print "%s already exists, perhaps %s has already been unpacked?" % (latest_dir, latest) print("%s already exists, perhaps %s has already been unpacked?" % (latest_dir, latest))
else: else:
print "Unpacking %s into %s, please wait." % (latest, latest_dir) print("Unpacking %s into %s, please wait." % (latest, latest_dir))
if (os.system("tar -xJf %s" % latest) != 0): if (os.system("tar -xJf %s" % latest) != 0):
print "%s is possibly corrupted, exiting." % (latest) print("%s is possibly corrupted, exiting." % (latest))
sys.exit(1) sys.exit(1)
if (args.naclvers): if (args.naclvers):
@ -334,11 +334,11 @@ if __name__ == '__main__':
if (args.ffmpegclean): if (args.ffmpegclean):
print("Cleaning ffmpeg from proprietary things...") print("Cleaning ffmpeg from proprietary things...")
os.system("./clean_ffmpeg.sh %s %d" % (latest_dir, 0 if args.ffmpegarm else 1)) os.system("./clean_ffmpeg.sh %s %d" % (latest_dir, 0 if args.ffmpegarm else 1))
print "Done!" print("Done!")
if (not args.prep): if (not args.prep):
print "Compressing cleaned tree, please wait..." print("Compressing cleaned tree, please wait...")
os.chdir(chromium_root_dir) 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)) os.system("tar --exclude=\.svn -cf - chromium-%s | xz -9 -T 0 -f > %s" % (chromium_version, chromium_clean_xz_file))
print "Finished!" print("Finished!")

Loading…
Cancel
Save