Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / test / chromedriver / archive.py
blobe203c36d0da8c3fbeb40f10bd8ed8807133769f9
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_30_REVISION = '217281'
14 CHROME_31_REVISION = '225096'
15 CHROME_32_REVISION = '232870'
17 _SITE = 'http://commondatastorage.googleapis.com'
20 class Site(object):
21 CONTINUOUS = _SITE + '/chromium-browser-continuous'
22 SNAPSHOT = _SITE + '/chromium-browser-snapshots'
25 def GetLatestRevision(site=Site.CONTINUOUS):
26 """Returns the latest revision (as a string) available for this platform.
28 Args:
29 site: the archive site to check against, default to the continuous one.
30 """
31 url = site + '/%s/LAST_CHANGE'
32 return urllib.urlopen(url % _GetDownloadPlatform()).read()
35 def DownloadChrome(revision, dest_dir, site=Site.CONTINUOUS):
36 """Downloads the packaged Chrome from the archive to the given directory.
38 Args:
39 revision: the revision of Chrome to download.
40 dest_dir: the directory to download Chrome to.
41 site: the archive site to download from, default to the continuous one.
43 Returns:
44 The path to the unzipped Chrome binary.
45 """
46 def GetZipName():
47 if util.IsWindows():
48 return 'chrome-win32'
49 elif util.IsMac():
50 return 'chrome-mac'
51 elif util.IsLinux():
52 return 'chrome-linux'
53 def GetChromePathFromPackage():
54 if util.IsWindows():
55 return 'chrome.exe'
56 elif util.IsMac():
57 return 'Chromium.app/Contents/MacOS/Chromium'
58 elif util.IsLinux():
59 return 'chrome'
60 zip_path = os.path.join(dest_dir, 'chrome-%s.zip' % revision)
61 if not os.path.exists(zip_path):
62 url = site + '/%s/%s/%s.zip' % (_GetDownloadPlatform(), revision,
63 GetZipName())
64 print 'Downloading', url, '...'
65 urllib.urlretrieve(url, zip_path)
66 util.Unzip(zip_path, dest_dir)
67 return os.path.join(dest_dir, GetZipName(), GetChromePathFromPackage())
70 def _GetDownloadPlatform():
71 """Returns the name for this platform on the archive site."""
72 if util.IsWindows():
73 return 'Win'
74 elif util.IsMac():
75 return 'Mac'
76 elif util.IsLinux():
77 if platform.architecture()[0] == '64bit':
78 return 'Linux_x64'
79 else:
80 return 'Linux'