| Index: install_test/chrome_checkout.py
|
| ===================================================================
|
| --- install_test/chrome_checkout.py (revision 0)
|
| +++ install_test/chrome_checkout.py (revision 0)
|
| @@ -0,0 +1,200 @@
|
| +#!/usr/bin/python
|
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import httplib
|
| +import optparse
|
| +import os
|
| +import re
|
| +import sys
|
| +import socket
|
| +import subprocess
|
| +
|
| +__author__ = 'laforge/nkang'
|
| +
|
| +class ChromeCheckout:
|
| + """A class to check out Chrome source files based on revision number."""
|
| +
|
| + def __init__(self, version, dest=None):
|
| + # Verify that he version has the correct format.
|
| + self._version = ((lambda l: str(l[0]) if len(l) > 0 else '')
|
| + ((lambda v: re.findall('\S+\.\S+\.\S+\.\S+', v)
|
| + if(type(v) == str) else [])(version)))
|
| + self._dest = dest
|
| + self._base_svn_url = 'svn://svn.chromium.org/chrome'
|
| + self._selenium_url = 'http://selenium.googlecode.com/svn/trunk/py'
|
| + self._pyftpdlib_url = 'http://pyftpdlib.googlecode.com/svn/trunk'
|
| + self._deps_cache = {}
|
| + self._GetPath = (lambda par, ch: os.path.join(par, ch) if par else ch)
|
| + # By default the destination is the CWD, but if a different directory was
|
| + # specified, make sure it exists. If not, create it.
|
| + if self._dest:
|
| + if not os.path.isdir(self._dest):
|
| + try:
|
| + os.mkdir(self._dest)
|
| + # Failed to create test directory, CWD will be used for checkout.
|
| + except(OSError, IOError), err:
|
| + print 'ChromeCheckout.__init__: Failed to create %s. Checkout '\
|
| + 'will be done in the current working directory.' % self._dest
|
| + self._dest = None
|
| +
|
| + def _GetContentAndReturnResponse(self, server, path, content):
|
| + """Gets contents of DEPS, which contains info about source files needed.
|
| +
|
| + Args:
|
| + server: Host address, in this case the SVN server.
|
| + path: The URL where the file is located.
|
| + content: A string of data to send after the headers are finished. By
|
| + default its an empty string and should be left that way.
|
| +
|
| + Returns:
|
| + A string containing the file's contents if successful, otherwise None.
|
| + """
|
| + try:
|
| + conn = httplib.HTTPConnection(server)
|
| + headers = {"Content-type": "text/html"}
|
| + conn.request('GET', path, content, headers)
|
| + response = conn.getresponse()
|
| + except socket.gaierror, err:
|
| + print 'ChromeCheckout._GetContentAndReturnResponse: %s' % err
|
| + conn.close()
|
| + return None
|
| + if response.status != 200:
|
| + return None
|
| + data = response.read()
|
| + buff = ''
|
| + for line in data:
|
| + buff += line
|
| + conn.close()
|
| + return buff
|
| +
|
| + def _GetDeps(self, version):
|
| + """Returns cached version of DEPS if possible, otherwise gets its contents.
|
| +
|
| + Args:
|
| + version: Chrome version number (e.g. - 21.0.1136.0).
|
| +
|
| + Returns:
|
| + string: A string buffer containing the contents of the DEPS file.
|
| + """
|
| + if not version:
|
| + return None
|
| + if version in self._deps_cache:
|
| + return self._deps_cache[version]
|
| + deps = self._GetContentAndReturnResponse('src.chromium.org',
|
| + '/viewvc/chrome/releases/%s/DEPS'
|
| + % version, '')
|
| + self._deps_cache[version] = deps
|
| + return deps
|
| +
|
| + def _ParseVersion(self, version):
|
| + """Parses the version number to get the different identifiers."""
|
| + match = re.search(r'((\d+)\.(\d+)\.(\d+)\.(\d+))', version)
|
| + if match:
|
| + version = {'version': match.group(1),
|
| + 'major': int(match.group(2)),
|
| + 'minor': int(match.group(3)),
|
| + 'build': int(match.group(4)),
|
| + 'patch': int(match.group(5))}
|
| + return version
|
| + return {}
|
| +
|
| + def _GetRevisionInfo(self, version_str):
|
| + """Gets the revision info by parsing the contents of the DEPS file.
|
| +
|
| + Args:
|
| + version_str: A string representing the Chrome version number.
|
| +
|
| + Returns:
|
| + A string that contains pertinent information about the Chrome version.
|
| + """
|
| + version = self._ParseVersion(version_str)
|
| + if version:
|
| + body = self._GetDeps(version['version'])
|
| + if body:
|
| + match = re.search("'src':[\n\r ]+'(.*?)'", body)
|
| + if match:
|
| + match = re.search(r"@(\d+)", match.group(1))
|
| + if match:
|
| + version['revision'] = int(match.group(1))
|
| +
|
| + match = re.search("""['"]src['"].*?:.*?['"]/branches/(.*?)/.*?,""",
|
| + body, re.DOTALL | re.IGNORECASE)
|
| + if match:
|
| + version['branch'] = match.group(1)
|
| + else:
|
| + version['branch'] = 'trunk'
|
| + return version
|
| +
|
| + def _GetRevision(self, version_str, rev_type='selenium'):
|
| + """Gets selenium/pyftpdlib rev. number by parsing contents of DEPS file.
|
| +
|
| + Args:
|
| + version_str: A string representing the Chrome build number.
|
| + rev_type: Type of revision number to look up - Selenium or Pyftpdlib.
|
| +
|
| + Returns:
|
| + A string representing the revision no. if successful, otherwise None.
|
| + """
|
| + version = self._ParseVersion(version_str)
|
| + if version:
|
| + body = self._GetDeps(version_str)
|
| + if body:
|
| + if rev_type == 'selenium':
|
| + m = re.search(r"http://selenium\.googlecode\.com/svn/trunk/py@(\d+)",
|
| + body, re.DOTALL | re.IGNORECASE | re.MULTILINE)
|
| + elif rev_type == 'pyftpdlib':
|
| + m = re.search(r"http://pyftpdlib\.googlecode\.com/svn/trunk@(\d+)",
|
| + body, re.DOTALL | re.IGNORECASE | re.MULTILINE)
|
| + if m:
|
| + return int(m.group(1))
|
| + return None
|
| +
|
| + def _SvnCo(self, path, revision=None, dest=None):
|
| + """Does a SVN checkout on specified source files.
|
| +
|
| + Args:
|
| + path: URL that is to be checked out.
|
| + revision: Revision number.
|
| + dest: Destination where the data will be downloaded.
|
| + """
|
| + cmd = "svn co"
|
| + if revision:
|
| + cmd += " --revision %d" % revision
|
| + cmd += " %s" % path
|
| + if dest:
|
| + cmd += " %s" % dest
|
| + print cmd
|
| + return subprocess.Popen.wait(subprocess.Popen(cmd, shell=True))
|
| +
|
| + def CheckOut(self):
|
| + """Checks out all necessary source files."""
|
| + # No version was specified.
|
| + if not self._version:
|
| + print 'Please specify a Chrome version to checkout.'
|
| + return -1
|
| + rev_info = self._GetRevisionInfo(self._version)
|
| + print rev_info
|
| + # If its a patch, check out the branch.
|
| + if rev_info['patch']:
|
| + svn_url_base = self._base_svn_url + '/branches/%s' % rev_info['branch']
|
| + # If not, check out the trunk.
|
| + else:
|
| + svn_url_base = self._base_svn_url + '/trunk'
|
| + self._SvnCo('%s/src/chrome/test/functional' % svn_url_base,
|
| + rev_info['revision'], self._GetPath(self._dest, 'functional'))
|
| + self._SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base,
|
| + rev_info['revision'], self._GetPath(self._dest, 'pyautolib'))
|
| + self._SvnCo('%s/src/third_party/simplejson' % svn_url_base,
|
| + rev_info['revision'], self._GetPath(self._dest, 'simplejson'))
|
| + self._SvnCo('%s/src/third_party/tlslite' % svn_url_base,
|
| + rev_info['revision'], self._GetPath(self._dest, 'tlslite'))
|
| + self._SvnCo('%s/src/net/tools/testserver' % svn_url_base,
|
| + rev_info['revision'], self._GetPath(self._dest, 'testserver'))
|
| + self._SvnCo(self._selenium_url, self._GetRevision(
|
| + self._version, 'selenium'), self._GetPath(self._dest, 'selenium'))
|
| + self._SvnCo(self._pyftpdlib_url, self._GetRevision(
|
| + self._version, 'pyftpdlib'), self._GetPath(self._dest, 'pyftpdlib'))
|
| + return 0
|
| +
|
|
|
| Property changes on: install_test\chrome_checkout.py
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|