Downloads the latest Chromium browser build from http://commondatastorage.googleapis.com/chromium-browser-continuous/ using urllib2 or wget (with Python versions below 2.5) and unzips the downloaded zip file to a predefined folder.
To use a custom proxy define the HTTP_PROXY
system variable.
The script will figure out the OS but you can also pass the platform as the first parameter (one of win32, linux, linux64, mac
).
Prerequisites (!! only for Python versions below 2.5):
wget
- usually already installed on most linux systems. Windows users can get it here.unzip
- used for unpacking the archive; usually already installed on most linux systems. Windows users can get it here.
Both wget
and unzip
should be available in PATH (for Python 2.5+ native Python modules are used).
For most Linux distros this script does not make much sense since the built-in package managers do a better job of managing chromium builds and dependencies, but it still can be useful if you are using a stable Chromium build but would like to be able to test the nightly builds too.
For OSX an additional installation step will be performed using the install.sh
that is included in the OSX build. The OSX installer will copy the package to ~/Applications/Chromium
, and set some permissions that are required for Chromium to run. Running the unpacked zip without doing the installation will most likely will not work because of missing executable permissions on some files.
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 | #!/usr/bin/env python
import os
import urllib2
import urllib
import zipfile
import sys
import subprocess
import shutil
import pipes
## browser friendly pages
## http://commondatastorage.googleapis.com/chromium-browser-continuous/index.html
## http://commondatastorage.googleapis.com/chromium-browser-continuous/index.html?path=Win/
## Chrome Canary: https://tools.google.com/dlpage/chromesxs?platform=win
MBFACTOR = float(1<<20) # divisor to convert bytes to megabytes
# URL_PREFIX_CONTINUOUS = 'http://commondatastorage.googleapis.com/chromium-browser-continuous/'
# URL_PREFIX_SNAPSHOTS = 'http://commondatastorage.googleapis.com/chromium-browser-snapshots/'
# URL_PREFIX_OFFICIAL = 'http://commondatastorage.googleapis.com/chromium-browser-official/'
AVAILABLE_CHANELLS = {'continuous':'http://commondatastorage.googleapis.com/chromium-browser-continuous/',
'snapshot':'http://commondatastorage.googleapis.com/chromium-browser-snapshots/',
'official':'http://commondatastorage.googleapis.com/chromium-browser-official/'}
os_suffixes = dict(
linux2=['Linux', 'linux'],
linux64=['Linux_x64', 'linux64'],
mac=['Mac', 'mac'],
win32=['Win', 'win32']
)
def usage():
os_list = "|".join([platform_[1] for platform_ in os_suffixes.values()])
print '''Usage %s [%s] [%s]
Default channell is: continuous
''' % (os.path.basename(sys.argv[0]), os_list, '|'.join(AVAILABLE_CHANELLS.keys()))
if len(sys.argv) > 1 and sys.argv[1].lower() in ['-h', '--help', '/?']:
usage()
sys.exit(-1)
platform = len(sys.argv) > 1 and sys.argv[1] or sys.platform
if platform == 'darwin':
platform = 'mac'
channell = None
if len(sys.argv) > 2:
channell = sys.argv[2]
if channell not in AVAILABLE_CHANELLS.keys():
print '\n***ERROR***:No such channell %s' % channell
usage()
sys.exit(-1)
if not channell:
channell = 'continuous'
tmp = os.environ.get('TMP') or os.environ.get('TEMP') or '/tmp'
if sys.platform == 'win32':
apps_folder = r'd:\Program Files'
if sys.platform == 'darwin':
apps_folder = os.path.join(os.environ.get('HOME'), 'Applications')
else:
apps_folder = os.path.join(os.environ.get('HOME'), 'bin')
def _reporthook2(count, blockSize, total_size, url=None):
current_size = int(count*blockSize)
sys.stdout.write(" %.2f MB of %.2f MB \r" % (current_size/(MBFACTOR), total_size/MBFACTOR))
def download_binary_file(url, local_fname):
print '''
Downloading
%s
to
%s...\n''' % (url, local_fname),
if sys.stdout.isatty():
urllib.urlretrieve(url, local_fname,lambda nb, bs, fs, url=url: _reporthook2(nb,bs,fs,url))
sys.stdout.write('\n')
else:
urllib.urlretrieve(url, dst)
def extract_zip_file(zipFilePath, extractDir):
if not os.path.exists(extractDir):
os.mkdir(extractDir)
print '''Extracting
%s
to
%s...''' % (zipFilePath, extractDir),
zfile = zipfile.ZipFile(zipFilePath)
uncompress_size = sum((file.file_size for file in zfile.infolist()))
extracted_size = 0
print '\n'
for _file in zfile.infolist():
extracted_size += _file.file_size
sys.stdout.write(" %s%%\t\t%s\n" % (extracted_size * 100/uncompress_size, _file.filename))
zfile.extract(_file, path=extractDir)
# ORIG zip.extractall(path=extractDir)
print 'Ok'
def do_osx_install(srcdir, targetdir):
if os.path.exists(targetdir):
print 'Target dir %s already exists! Removing...'
shutil.rmtree(targetdir)
install_script = os.popen('find '+ srcdir +' -iname install.sh').read().strip()
print 'DBG install_script:', install_script
os.popen('chmod +x "%s"' % install_script)
cmd_install = '%s %s %s' % (pipes.quote(install_script), srcdir, targetdir)
print 'DBG cmd: "%s"' % cmd_install
cmd_chmod_chromium = 'find %s -name Chromium -exec chmod +x {} \;' % (targetdir)
cmd_chmod_chromium_helper = 'find %s -name Chromium\ Helper -exec chmod +x {} \;' % (targetdir)
for cmd in [cmd_install, cmd_chmod_chromium, cmd_chmod_chromium_helper]:
proc = subprocess.Popen(cmd, shell=True)
proc.wait()
if proc.returncode:
print "returncode " + str(proc.returncode)
print '''
platform:\t%s
Unpacking to dir:\t%s
''' % (platform, apps_folder)
print 'Checking for latest version...',
try:
os_suffix = os_suffixes[platform][0]
except KeyError:
print '\n\nERROR:\tFirst arg should be platform name, one of: %s' % ', '.join(os_suffixes.keys())
sys.exit(-1)
# use proxy if set as an ENV var
proxy = os.environ.get('HTTP_PROXY')
if proxy:
protocol, host = proxy.split('://')
print 'Using proxy', proxy
http_proxy_handler = urllib2.ProxyHandler({protocol:host})
opener = urllib2.build_opener(http_proxy_handler)
urllib2.install_opener(opener)
else:
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko) Chrome/19.0.1055.1 Safari/535.24')]
print 'Probing last version...',
url_last_change = AVAILABLE_CHANELLS[channell] + os_suffix + '/LAST_CHANGE'
print url_last_change
version = opener.open(url_last_change).read().strip()
print 'Current version:', version
local_fname = os.path.join(tmp, 'chrome-%s_%s.zip' % (platform, version))
need_downloading = True
if os.path.exists(local_fname):
print '\nFile %s already exists!\nRemove it? (Y/n)' % local_fname
ans = raw_input()
if ans.lower() != 'n':
print 'Deleting existing file %s' % local_fname,
os.remove(local_fname)
print 'Ok'
else:
need_downloading = False
url = AVAILABLE_CHANELLS[channell] + os_suffix + '/' + version + '/chrome-' + os_suffixes[platform][1] + '.zip'
print 'Downloading from:', url
if (sys.version_info.minor < 6):
need_downloading and os.system('wget -c %s -O %s' % (url, local_fname))
print 'Unzippping...'
cmd = 'unzip -o %s -d "%s"' % (os.path.abspath(local_fname), apps_folder)
print cmd
os.system(cmd)
else:
need_downloading and download_binary_file(url, local_fname)
extract_zip_file(local_fname, apps_folder)
if (sys.platform=='darwin'):
chrome_app_dir = os.path.join(apps_folder, 'chrome-mac')
target_dir = os.path.join(apps_folder, 'Chromium')
do_osx_install(chrome_app_dir, target_dir)
# raw_input('removing unpacked chrome folder ' + chrome_app_dir)
shutil.rmtree(chrome_app_dir)
print 'Done!'
|
Thank you sir! Why aren't the different channels documented anywhere? Is this code compiled by the Chromium team?