1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 """Downloads items from the Chromium continuous archive.""" 6 7 import os 8 import platform 9 import urllib 10 11 import util 12 13 CHROME_35_REVISION = '260135' 14 CHROME_36_REVISION = '269696' 15 CHROME_37_REVISION = '278933' 16 17 _SITE = 'http://commondatastorage.googleapis.com' 18 19 20 class Site(object): 21 CONTINUOUS = _SITE + '/chromium-browser-continuous' 22 CHROMIUM_SNAPSHOT = _SITE + '/chromium-browser-snapshots' 23 BLINK_SNAPSHOT = _SITE + '/chromium-webkit-snapshots' 24 25 26 def GetLatestRevision(site=Site.CONTINUOUS): 27 """Returns the latest revision (as a string) available for this platform. 28 29 Args: 30 site: the archive site to check against, default to the continuous one. 31 """ 32 url = site + '/%s/LAST_CHANGE' 33 return urllib.urlopen(url % _GetDownloadPlatform()).read() 34 35 36 def DownloadChrome(revision, dest_dir, site=Site.CONTINUOUS): 37 """Downloads the packaged Chrome from the archive to the given directory. 38 39 Args: 40 revision: the revision of Chrome to download. 41 dest_dir: the directory to download Chrome to. 42 site: the archive site to download from, default to the continuous one. 43 44 Returns: 45 The path to the unzipped Chrome binary. 46 """ 47 def GetZipName(): 48 if util.IsWindows(): 49 return 'chrome-win32' 50 elif util.IsMac(): 51 return 'chrome-mac' 52 elif util.IsLinux(): 53 return 'chrome-linux' 54 def GetChromePathFromPackage(): 55 if util.IsWindows(): 56 return 'chrome.exe' 57 elif util.IsMac(): 58 return 'Chromium.app/Contents/MacOS/Chromium' 59 elif util.IsLinux(): 60 return 'chrome' 61 zip_path = os.path.join(dest_dir, 'chrome-%s.zip' % revision) 62 if not os.path.exists(zip_path): 63 url = site + '/%s/%s/%s.zip' % (_GetDownloadPlatform(), revision, 64 GetZipName()) 65 print 'Downloading', url, '...' 66 urllib.urlretrieve(url, zip_path) 67 util.Unzip(zip_path, dest_dir) 68 return os.path.join(dest_dir, GetZipName(), GetChromePathFromPackage()) 69 70 71 def _GetDownloadPlatform(): 72 """Returns the name for this platform on the archive site.""" 73 if util.IsWindows(): 74 return 'Win' 75 elif util.IsMac(): 76 return 'Mac' 77 elif util.IsLinux(): 78 if platform.architecture()[0] == '64bit': 79 return 'Linux_x64' 80 else: 81 return 'Linux' 82 83 def GetLatestSnapshotVersion(): 84 """Returns the latest revision of snapshot build.""" 85 return GetLatestRevision(GetSnapshotDownloadSite()) 86 87 def GetSnapshotDownloadSite(): 88 """Returns the site to download snapshot build according to the platform. 89 90 For Linux 32-bit, it is chromium snapshot build. 91 For other platform, it is blink snapshot build. 92 Because there is no linux32 blink snapshot build. 93 """ 94 if _GetDownloadPlatform() in ('Linux', 'Linux_x64', 'Mac'): 95 return Site.CHROMIUM_SNAPSHOT 96 else: 97 return Site.BLINK_SNAPSHOT 98