12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)# found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)"""Downloads items from the Chromium continuous archive."""
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)import os
8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)import platform
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)import urllib
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochimport util
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo LiuCHROME_35_REVISION = '260135'
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)CHROME_36_REVISION = '269696'
151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciCHROME_37_REVISION = '278933'
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)_SITE = 'http://commondatastorage.googleapis.com'
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class Site(object):
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  CONTINUOUS = _SITE + '/chromium-browser-continuous'
22f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  CHROMIUM_SNAPSHOT = _SITE + '/chromium-browser-snapshots'
2346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  BLINK_SNAPSHOT = _SITE + '/chromium-webkit-snapshots'
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)def GetLatestRevision(site=Site.CONTINUOUS):
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  """Returns the latest revision (as a string) available for this platform.
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  Args:
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    site: the archive site to check against, default to the continuous one.
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  """
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  url = site + '/%s/LAST_CHANGE'
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return urllib.urlopen(url % _GetDownloadPlatform()).read()
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)def DownloadChrome(revision, dest_dir, site=Site.CONTINUOUS):
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  """Downloads the packaged Chrome from the archive to the given directory.
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Args:
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    revision: the revision of Chrome to download.
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    dest_dir: the directory to download Chrome to.
4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    site: the archive site to download from, default to the continuous one.
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Returns:
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    The path to the unzipped Chrome binary.
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  """
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  def GetZipName():
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if util.IsWindows():
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return 'chrome-win32'
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    elif util.IsMac():
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return 'chrome-mac'
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    elif util.IsLinux():
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return 'chrome-linux'
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  def GetChromePathFromPackage():
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    if util.IsWindows():
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return 'chrome.exe'
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    elif util.IsMac():
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return 'Chromium.app/Contents/MacOS/Chromium'
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    elif util.IsLinux():
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return 'chrome'
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  zip_path = os.path.join(dest_dir, 'chrome-%s.zip' % revision)
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if not os.path.exists(zip_path):
6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    url = site + '/%s/%s/%s.zip' % (_GetDownloadPlatform(), revision,
6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                    GetZipName())
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    print 'Downloading', url, '...'
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    urllib.urlretrieve(url, zip_path)
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  util.Unzip(zip_path, dest_dir)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return os.path.join(dest_dir, GetZipName(), GetChromePathFromPackage())
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)def _GetDownloadPlatform():
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  """Returns the name for this platform on the archive site."""
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if util.IsWindows():
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return 'Win'
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  elif util.IsMac():
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return 'Mac'
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  elif util.IsLinux():
78a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    if platform.architecture()[0] == '64bit':
79a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      return 'Linux_x64'
80a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    else:
81a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      return 'Linux'
82f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
83f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)def GetLatestSnapshotVersion():
84f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  """Returns the latest revision of snapshot build."""
85f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return GetLatestRevision(GetSnapshotDownloadSite())
86f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
87f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)def GetSnapshotDownloadSite():
88f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  """Returns the site to download snapshot build according to the platform.
89f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
90f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  For Linux 32-bit, it is chromium snapshot build.
91f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  For other platform, it is blink snapshot build.
92f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  Because there is no linux32 blink snapshot build.
93f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  """
94116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if _GetDownloadPlatform() in ('Linux', 'Linux_x64', 'Mac'):
95f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return Site.CHROMIUM_SNAPSHOT
96f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  else:
97f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return Site.BLINK_SNAPSHOT
98