| Index: install_test/chrome_checkout.py
|
| ===================================================================
|
| --- install_test/chrome_checkout.py (revision 0)
|
| +++ install_test/chrome_checkout.py (revision 0)
|
| @@ -0,0 +1,206 @@
|
| +#!/usr/bin/env 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.
|
| +
|
| +"""Utilities for checking out Chrome source files from SVN.
|
| +
|
| +Chrome release version number is required for checkout. Version number is used
|
| +to lookup the corresponding DEPS file from Chrome releases. DEPS file contains
|
| +the dependencies, revision number, and other pertinent information about that
|
| +particular build. It also specifies whether its a branch or a trunk release
|
| +and contains a corresponding revision number. The revision number, which is
|
| +needed to checkout files from SVN, is obtained by parsing the contents of the
|
| +DEPS file.
|
| +"""
|
| +
|
| +import httplib
|
| +import logging
|
| +import os
|
| +import re
|
| +import socket
|
| +import subprocess
|
| +import urllib2
|
| +
|
| +_BASE_SVN_URL = 'svn://svn.chromium.org/chrome'
|
| +_SELENIUM_URL = 'http://selenium.googlecode.com/svn/trunk/py'
|
| +_PYFTPDLIB_URL = 'http://pyftpdlib.googlecode.com/svn/trunk'
|
| +_CHROME_URL = 'http://src.chromium.org/viewvc/chrome/releases'
|
| +
|
| +
|
| +def _SetupLogging():
|
| + """Sets the logging configuration."""
|
| + log_format = '%(asctime)s - %(levelname)s : %(message)s'
|
| + logging.basicConfig(level=logging.DEBUG, format=log_format)
|
| +
|
| +
|
| +_SetupLogging()
|
| +
|
| +
|
| +def _GetContentAndReturnResponse(url):
|
| + """Gets contents of the file at the specified url.
|
| +
|
| + Args:
|
| + url: The path where the file is located.
|
| +
|
| + Returns:
|
| + A string containing the file contents.
|
| + """
|
| + url_opener = urllib2.urlopen(url)
|
| + data = url_opener.read()
|
| + url_opener.close()
|
| + return data
|
| +
|
| +
|
| +def _GetDeps(version):
|
| + """Returns contents of DEPS file that corresponds with the version number.
|
| +
|
| + Args:
|
| + version: Chrome version number (e.g., 21.0.1136.0).
|
| + """
|
| + url = '%s/%s/DEPS' % (_CHROME_URL, version)
|
| + deps = _GetContentAndReturnResponse(url)
|
| + return deps
|
| +
|
| +
|
| +def _ParseVersion(version_str):
|
| + """Parses the version string to get the different identifiers.
|
| +
|
| + Args:
|
| + version_str: Chrome release version number.
|
| + """
|
| + match = re.search(r'((\d+)\.(\d+)\.(\d+)\.(\d+))', version_str)
|
| + 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
|
| + raise RuntimeError('Invalid version number was specified: %r' % version_str)
|
| +
|
| +
|
| +def _GetRevisionInfo(version_str, deps):
|
| + """Gets the revision info by parsing the contents of the DEPS file.
|
| +
|
| + Args:
|
| + version_str: A string representing the Chrome version number.
|
| + deps: A string that contains the contents of corresponding DEPS file.
|
| +
|
| + Returns:
|
| + A string that contains pertinent information about the Chrome version.
|
| + """
|
| + version = _ParseVersion(version_str)
|
| + # Match 'src:' followed by a line break in deps. This is where the revision
|
| + # number is located.
|
| + match = re.search('\'src\':[\n\r ]+\'(.*?)\'', deps)
|
| + if match:
|
| + # If matched, look for the revision number which follows the @ symbol.
|
| + match = re.search(r'@(\d+)', match.group(1))
|
| + if match:
|
| + version['revision'] = int(match.group(1))
|
| + # Parse the matching string to see if it contains a branch number. If
|
| + # there is a branch number, it will follow the word 'branches'.
|
| + match = re.search("""['"]src['"].*?:.*?['"]/branches/(.*?)/.*?,""",
|
| + deps, re.DOTALL | re.IGNORECASE)
|
| + if match:
|
| + version['branch'] = match.group(1)
|
| + else:
|
| + version['branch'] = 'trunk'
|
| + return version
|
| +
|
| +
|
| +def _GetRevision(deps, rev_type):
|
| + """Gets selenium/pyftpdlib revision number by parsing contents of DEPS file.
|
| +
|
| + Args:
|
| + deps: A string that contains the contents of corresponding DEPS file.
|
| + rev_type: Type of revision number to look up: 'selenium' or 'pyftpdlib'.
|
| +
|
| + Returns:
|
| + An integer representing the revision number that was requested.
|
| + """
|
| + assert rev_type == 'selenium' or rev_type == 'pyftpdlib'
|
| + if rev_type == 'selenium':
|
| + match = re.search(r'http://selenium\.googlecode\.com/svn/trunk/py@(\d+)',
|
| + deps, re.DOTALL | re.IGNORECASE | re.MULTILINE)
|
| + elif rev_type == 'pyftpdlib':
|
| + match = re.search(r'http://pyftpdlib\.googlecode\.com/svn/trunk@(\d+)',
|
| + deps, re.DOTALL | re.IGNORECASE | re.MULTILINE)
|
| + if match:
|
| + return int(match.group(1))
|
| + raise RuntimeError('Could not find the revision number in DEPS.')
|
| +
|
| +
|
| +def _SvnCheckout(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 checkout'
|
| + if revision:
|
| + cmd += ' --revision %d' % revision
|
| + cmd += ' %s' % path
|
| + if dest:
|
| + cmd += ' %s' % dest
|
| + logging.info(cmd)
|
| + subprocess.check_call([cmd], shell=True)
|
| +
|
| +
|
| +def _IsVersionValid(version):
|
| + """Checks if the version number has the correct format.
|
| +
|
| + Args:
|
| + version: Version number to check.
|
| +
|
| + Returns:
|
| + True if 'n.n.n.n' pattern is found in version number, otherwise False.
|
| + """
|
| + return isinstance(version, basestring) and re.match('\d+\.\d+\.\d+\.\d+',
|
| + version)
|
| +
|
| +
|
| +def CheckOut(version, dest):
|
| + """Checks out all necessary source files.
|
| +
|
| + Args:
|
| + version: Chrome release version number (e.g., 21.0.1136.0).
|
| + dest: Destination where the checked out files will go.
|
| + """
|
| + if not _IsVersionValid(version):
|
| + raise RuntimeError('Invalid version number was specified: %r.' % version)
|
| + if not os.path.isdir(dest):
|
| + os.mkdir(dest)
|
| + deps = _GetDeps(version)
|
| + rev_info = _GetRevisionInfo(version, deps)
|
| + logging.info(rev_info)
|
| + # If it's a patch, checkout the branch.
|
| + if rev_info['patch']:
|
| + svn_url_base = _BASE_SVN_URL + '/branches/%s' % rev_info['branch']
|
| + # If not, check out the trunk.
|
| + else:
|
| + svn_url_base = _BASE_SVN_URL + '/trunk'
|
| + _SvnCheckout('%s/src/chrome/test/functional' % svn_url_base,
|
| + rev_info['revision'], os.path.join(dest, 'src',
|
| + 'chrome', 'test',
|
| + 'functional'))
|
| + _SvnCheckout('%s/src/chrome/test/pyautolib' % svn_url_base,
|
| + rev_info['revision'], os.path.join(dest, 'src', 'chrome',
|
| + 'test', 'pyautolib'))
|
| + _SvnCheckout('%s/src/third_party/simplejson' % svn_url_base,
|
| + rev_info['revision'], os.path.join(dest, 'src', 'third_party',
|
| + 'simplejson'))
|
| + _SvnCheckout('%s/src/third_party/tlslite' % svn_url_base,
|
| + rev_info['revision'], os.path.join(dest, 'src', 'third_party',
|
| + 'tlslite'))
|
| + _SvnCheckout('%s/src/net/tools/testserver' % svn_url_base,
|
| + rev_info['revision'], os.path.join(dest, 'src', 'net', 'tools',
|
| + 'testserver'))
|
| + _SvnCheckout(_SELENIUM_URL, _GetRevision(deps, 'selenium'),
|
| + os.path.join(dest, 'src', 'third_party', 'webdriver', 'pylib',
|
| + 'selenium'))
|
| + _SvnCheckout(_PYFTPDLIB_URL, _GetRevision(deps, 'pyftpdlib'),
|
| + os.path.join(dest, 'src', 'third_party', 'pyftpdlib'))
|
|
|
| Property changes on: install_test\chrome_checkout.py
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|