Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / chromedriver / archive.py
blob7929b8bb5653d4817adaac50779467893a7a8982
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.
5 """Downloads items from the Chromium continuous archive."""
7 import os
8 import platform
9 import urllib
11 import util
13 CHROME_43_REVISION = '323865'
14 CHROME_44_REVISION = '330231'
15 CHROME_45_REVISION = '338390'
17 _SITE = 'http://commondatastorage.googleapis.com'
20 class Site(object):
21 CONTINUOUS = _SITE + '/chromium-browser-continuous'
22 CHROMIUM_SNAPSHOT = _SITE + '/chromium-browser-snapshots'
23 BLINK_SNAPSHOT = _SITE + '/chromium-webkit-snapshots'
26 def GetLatestRevision(site=Site.CONTINUOUS):
27 """Returns the latest revision (as a string) available for this platform.
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()
36 def DownloadChrome(revision, dest_dir, site=Site.CONTINUOUS):
37 """Downloads the packaged Chrome from the archive to the given directory.
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.
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-wrapper'
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())
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'
83 def GetLatestSnapshotVersion():
84 """Returns the latest revision of snapshot build."""
85 return GetLatestRevision(GetSnapshotDownloadSite())
87 def GetSnapshotDownloadSite():
88 """Returns the site to download snapshot build according to the platform."""
89 return Site.CHROMIUM_SNAPSHOT