Chromium Code Reviews| Index: install_test/chrome_checkout.py |
| =================================================================== |
| --- install_test/chrome_checkout.py (revision 0) |
| +++ install_test/chrome_checkout.py (revision 0) |
| @@ -0,0 +1,203 @@ |
| +#!/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' |
| + |
| + |
| +def _SetConfiguration(): |
|
Nirnimesh
2012/08/22 07:06:35
rename -> _SetupLogging
nkang
2012/08/24 22:45:26
Done.
|
| + """Sets the logging configuration.""" |
| + log_format = '%(asctime)s - %(levelname)s : %(message)s' |
| + logging.basicConfig(level=logging.DEBUG, format=log_format) |
| + |
| + |
| +_SetConfiguration() |
| + |
| + |
| +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) |
| + buff = url_opener.read() |
|
Nirnimesh
2012/08/22 07:06:35
Don't use cryptic var names.
buff -> data
nkang
2012/08/24 22:45:26
Done.
|
| + url_opener.close() |
| + return buff |
| + |
| + |
| +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). |
| + """ |
| + deps = _GetContentAndReturnResponse( |
| + 'http://src.chromium.org/viewvc/chrome/releases/%s/DEPS' % version) |
|
Nirnimesh
2012/08/22 07:06:35
shouldn't part of this URL also be declared as a c
nkang
2012/08/24 22:45:26
Created a new constant called _CHROME_URL and upda
|
| + 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 = re.search('\'src\':[\n\r ]+\'(.*?)\'', deps) |
|
Nirnimesh
2012/08/22 07:06:35
Give an example of the pattern you're trying to ma
nkang
2012/08/24 22:45:26
Added a comment that specifies what this statement
|
| + if match: |
| + match = re.search(r'@(\d+)', match.group(1)) |
| + if match: |
| + version['revision'] = int(match.group(1)) |
| + |
| + match = re.search("""['"]src['"].*?:.*?['"]/branches/(.*?)/.*?,""", |
|
Nirnimesh
2012/08/22 07:06:35
ditto
nkang
2012/08/24 22:45:26
Added a comment that specifies what this statement
|
| + 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 rev. number by parsing contents of DEPS file. |
|
Nirnimesh
2012/08/22 07:06:35
rev. -> revision
nkang
2012/08/24 22:45:26
Done.
|
| + |
| + 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 _SvnCo(path, revision=None, dest=None): |
|
Nirnimesh
2012/08/22 07:06:35
_SvnCheckout
nkang
2012/08/24 22:45:26
Done.
|
| + """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' |
|
Nirnimesh
2012/08/22 07:06:35
co -> checkout
nkang
2012/08/24 22:45:26
Done.
|
| + if revision: |
| + cmd += ' --revision %d' % revision |
| + cmd += ' %s' % path |
|
Nirnimesh
2012/08/22 07:06:35
remove %s. It's redundant
nkang
2012/08/24 22:45:26
We need to add a space between the strings we're c
|
| + if dest: |
| + cmd += ' %s' % dest |
|
Nirnimesh
2012/08/22 07:06:35
ditto
nkang
2012/08/24 22:45:26
See response above.
|
| + 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. |
| + """ |
| + if type(version) == str: |
|
Nirnimesh
2012/08/22 07:06:35
isinstance(version, basestring)
nkang
2012/08/24 22:45:26
Rewrote the method as:
return isinstance(...) and
|
| + match = re.match('\d+\.\d+\.\d+\.\d+', version) |
|
Nirnimesh
2012/08/22 07:06:35
remove the match var. and move the if on this line
nkang
2012/08/24 22:45:26
Rewrote the method as:
return isinstance(...) and
|
| + if match: |
| + return True |
| + return False |
|
Nirnimesh
2012/08/22 07:06:35
This whole function can be written as:
return isi
nkang
2012/08/24 22:45:26
Rewrote the method as:
return isinstance(...) and
|
| + |
| + |
| +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 its a patch, check out the branch. |
|
Nirnimesh
2012/08/22 07:06:35
its -> it's
Nirnimesh
2012/08/22 07:06:35
check out -> checkout
nkang
2012/08/24 22:45:26
Done.
nkang
2012/08/24 22:45:26
Done.
|
| + if rev_info['patch']: |
| + svn_url_base = _BASE_SVN_URL + '/branches/%s' % rev_info['branch'] |
| + # If not, check out the trunk. |
| + else: |
|
Nirnimesh
2012/08/22 07:06:35
I don't like this. But whatever.
nkang
2012/08/24 22:45:26
Maybe we can change this in the next CL.
|
| + svn_url_base = _BASE_SVN_URL + '/trunk' |
| + _SvnCo('%s/src/chrome/test/functional' % svn_url_base, |
| + rev_info['revision'], os.path.join(dest, 'src', 'chrome', 'test', |
| + 'functional')) |
| + _SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base, |
| + rev_info['revision'], os.path.join(dest, 'src', 'chrome', 'test', |
| + 'pyautolib')) |
| + _SvnCo('%s/src/third_party/simplejson' % svn_url_base, |
| + rev_info['revision'], os.path.join(dest, 'src', 'third_party', |
| + 'simplejson')) |
| + _SvnCo('%s/src/third_party/tlslite' % svn_url_base, |
| + rev_info['revision'], os.path.join(dest, 'src', 'third_party', |
| + 'tlslite')) |
| + _SvnCo('%s/src/net/tools/testserver' % svn_url_base, |
| + rev_info['revision'], os.path.join(dest, 'src', 'net', 'tools', |
| + 'testserver')) |
| + _SvnCo(_SELENIUM_URL, _GetRevision(deps, 'selenium'), |
| + os.path.join(dest, 'src', 'third_party', 'webdriver', 'pylib', |
| + 'selenium')) |
| + _SvnCo(_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 |