Skip to content

Instantly share code, notes, and snippets.

@zerok
Created January 10, 2010 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerok/273661 to your computer and use it in GitHub Desktop.
Save zerok/273661 to your computer and use it in GitHub Desktop.
from __future__ import with_statement
import shutil, plistlib, urllib2, re, tempfile
from os.path import join, exists, expanduser
from subprocess import call
SEARCH_FOLDERS = ('/Applications', '~/Applications')
BASE_URL = "http://build.chromium.org/buildbot/snapshots/chromium-rel-mac/"
DOWNLOAD_FORMAT = BASE_URL + "%s/chrome-mac.zip"
DEFAULT_INSTALLATION_PATH = '/Applications'
def get_version(path):
infofile = join(path, "Contents", "Info.plist")
return int(plistlib.readPlist(infofile)['SVNRevision'])
def get_latest_version():
line_re = re.compile(r'<a href="(\d+)\/">.*<\/a>')
rev = None
for line in urllib2.urlopen(BASE_URL):
mo = line_re.search(line)
if mo is not None:
rev = int(mo.group(1))
return rev
chromium_app = None
install_path = None
previous_version = None
latest_version = None
for path in SEARCH_FOLDERS:
cpath = expanduser(join(path, 'Chromium.app'))
if exists(cpath):
chromium_app = cpath
install_path = path
previous_version = get_version(cpath)
if install_path is None:
install_path = DEFAULT_INSTALLATION_PATH
latest_version = get_latest_version()
if latest_version is None:
raise RuntimeError, "Couldn't determine latest revision from the server"
if previous_version is None or previous_version < latest_version:
print "New revision to be installed: %d" % (latest_version,)
url = DOWNLOAD_FORMAT % (latest_version,)
tempdir = tempfile.mkdtemp()
print "Downloading %s into %s" % (url, tempdir,)
try:
call('curl %(url)s > %(tempdir)s/chrome-mac.zip && cd %(tempdir)s && unzip chrome-mac.zip' % {
'tempdir': tempdir, 'url': url
}, shell=True)
if (chromium_app is not None):
shutil.rmtree(chromium_app)
shutil.move('%s/chrome-mac/Chromium.app' % tempdir, install_path)
finally:
shutil.rmtree(tempdir)
else:
print "You're already up-to-date"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment