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,213 @@ |
| +#!/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. |
| + |
| +"""Checks out Chrome source files from SVN. |
| + |
| +Chrome release version number is required for checkout. The version number is |
| +used to obtain the revision number, which is then used to checkout files from |
| +SVN. |
| +""" |
| + |
| +import httplib |
| +import logging |
| +import os |
| +import re |
| +import socket |
| +import subprocess |
| + |
| +_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(): |
| + """Sets the logging configuration.""" |
| + log_format = '%(asctime)s - %(levelname)s : %(message)s' |
| + logging.basicConfig(level=logging.DEBUG, format=log_format) |
| + |
| + |
| +_SetConfiguration() |
| + |
| + |
| +def _GetContentAndReturnResponse(server, path): |
| + """Issues a GET requst to server and returns the response body. |
| + |
| + Args: |
| + server: Host address, in this case the SVN server. |
|
kkania
2012/06/13 16:47:01
drop 'in this case the SVN server'
nkang
2012/06/13 23:35:09
Dropped it like it was hot.
|
| + path: The URL where the file is located. |
|
kkania
2012/06/13 16:47:01
path != URL
nkang
2012/06/13 23:35:09
Replaced URL with path, so it now states, 'The pat
|
| + |
| + Returns: |
| + A string containing the response body. |
| + """ |
| + try: |
| + conn = httplib.HTTPConnection(server) |
| + headers = {'Content-type': 'text/html'} |
| + conn.request('GET', path, '', headers) |
| + response = conn.getresponse() |
| + except socket.gaierror, err: |
| + conn.close() |
| + raise socket.gaierror(err) |
|
kkania
2012/06/13 16:47:01
just do 'raise'
nkang
2012/06/13 23:35:09
Done.
|
| + if response.status != 200: |
| + conn.close() |
| + raise RuntimeError('HTTP request returned the following status code: %d' % |
| + response.status) |
| + data = response.read() |
| + conn.close() |
| + assert(data) |
|
kkania
2012/06/13 16:47:01
drop this
nkang
2012/06/13 23:35:09
Dropped it like a bad habit.
|
| + 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). |
| + """ |
| + deps = _GetContentAndReturnResponse( |
| + 'src.chromium.org', |
| + '/viewvc/chrome/releases/%s/DEPS' % version) |
| + return deps |
| + |
| + |
| +def _ParseVersion(version): |
|
kkania
2012/06/13 16:47:01
version->version_str
nkang
2012/06/13 23:35:09
Changed argument name from version to version_str.
|
| + """Parses the version number to get the different identifiers. |
| + |
| + Args: |
| + version: Chrome release version number. |
| + """ |
| + 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 |
| + raise RuntimeError('Invalid version number was specified: %r' % version) |
| + |
| + |
| +def _GetRevisionInfo(version_str, body): |
|
kkania
2012/06/13 16:47:01
i'd change var name body to deps
nkang
2012/06/13 23:35:09
Changed argument name from 'body' to 'deps'. Updat
|
| + """Gets the revision info by parsing the contents of the DEPS file. |
| + |
| + Args: |
| + version_str: A string representing the Chrome version number. |
| + body: 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 ]+'(.*?)'", 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(version_str, body, rev_type='selenium'): |
|
kkania
2012/06/13 16:47:01
body->deps
nkang
2012/06/13 23:35:09
Done. Also updated the docstring to reflect this c
|
| + """Gets selenium/pyftpdlib rev. number by parsing contents of DEPS file. |
| + |
| + Args: |
| + version_str: A string representing the Chrome build number. |
| + body: 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') |
| + version = _ParseVersion(version_str) |
|
kkania
2012/06/13 16:47:01
this doesn't look like it serves a purpose; remove
nkang
2012/06/13 23:35:09
Nice catch! This function and the one above it are
|
| + 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)) |
| + raise RuntimeError('Could not find the revision number in DEPS.') |
| + |
| + |
| +def _SvnCo(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 |
| + logging.info(cmd) |
| + assert(subprocess.Popen(cmd, shell=True).wait() == 0) |
| + |
| + |
| +def _GetPath(par, ch): |
| + return (lambda p, c: os.path.join(p, c) if p else c)(par, ch) |
| + |
| + |
| +def _IsVersionValid(ver): |
| + """Checks if the version number has the correct format. |
| + |
| + Args: |
| + ver: Version number to check. |
| + |
| + Returns: |
| + True if 'n.n.n.n' pattern is found in version number, otherwise False. |
| + """ |
| + if type(ver) == str: |
| + return re.findall('\d+\.\d+\.\d+\.\d+', ver) != [] |
| + return False |
| + |
| + |
| +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): |
| + try: |
| + os.mkdir(dest) |
| + except (OSError, IOError): |
| + raise RuntimeError('Could not create %s.\r\n%s.' % (dest, err)) |
| + deps = _GetDeps(version) |
| + rev_info = _GetRevisionInfo(version, deps) |
| + logging.info(rev_info) |
| + # If its a patch, check out 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' |
| + _SvnCo('%s/src/chrome/test/functional' % svn_url_base, |
| + rev_info['revision'], _GetPath(dest, 'functional')) |
|
kkania
2012/06/13 16:47:01
doesn't this need to be checked out under <dest>/s
nkang
2012/06/13 23:35:09
Got rid of the _GetPath method. Also updated all t
|
| + _SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base, |
| + rev_info['revision'], _GetPath(dest, 'pyautolib')) |
| + _SvnCo('%s/src/third_party/simplejson' % svn_url_base, |
| + rev_info['revision'], _GetPath(dest, 'simplejson')) |
| + _SvnCo('%s/src/third_party/tlslite' % svn_url_base, |
| + rev_info['revision'], _GetPath(dest, 'tlslite')) |
| + _SvnCo('%s/src/net/tools/testserver' % svn_url_base, |
| + rev_info['revision'], _GetPath(dest, 'testserver')) |
| + _SvnCo(_SELENIUM_URL, _GetRevision(version, deps, 'selenium'), |
| + _GetPath(dest, 'selenium')) |
| + _SvnCo(_PYFTPDLIB_URL, _GetRevision(version, deps, 'pyftpdlib'), |
| + _GetPath(dest, 'pyftpdlib')) |
| Property changes on: install_test\chrome_checkout.py |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |