Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Unified Diff: install_test/chrome_checkout.py

Issue 10384104: Chrome updater test framework (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | install_test/chrome_installer.py » ('j') | install_test/chrome_installer.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: install_test/chrome_checkout.py
===================================================================
--- install_test/chrome_checkout.py (revision 0)
+++ install_test/chrome_checkout.py (revision 0)
@@ -0,0 +1,209 @@
+#!/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. 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.
+ path: The path where the file is located.
+
+ Returns:
+ A string containing the response body.
+ """
+ try:
+ connection = httplib.HTTPConnection(server)
+ headers = {'Content-type': 'text/html'}
+ connection.request('GET', path, '', headers)
+ response = connection.getresponse()
+ except socket.gaierror, err:
+ connection.close()
+ raise err
+ if response.status != 200:
+ connection.close()
+ raise RuntimeError('%s/%s returned the following status code: %d' %
+ (server, path, response.status))
+ data = response.read()
+ connection.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).
+ """
+ deps = _GetContentAndReturnResponse(
+ 'src.chromium.org',
+ '/viewvc/chrome/releases/%s/DEPS' % version)
+ 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)
+ if match:
+ match = re.search(r"@(\d+)", match.group(1))
+ if match:
+ version['revision'] = int(match.group(1))
+
+ 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='selenium'):
+ """Gets selenium/pyftpdlib rev. 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':
+ m = re.search(r'http://selenium\.googlecode\.com/svn/trunk/py@(\d+)',
+ deps, re.DOTALL | re.IGNORECASE | re.MULTILINE)
+ elif rev_type == 'pyftpdlib':
+ m = re.search(r'http://pyftpdlib\.googlecode\.com/svn/trunk@(\d+)',
+ deps, 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 _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:
+ return re.findall('\d+\.\d+\.\d+\.\d+', version) != []
+ 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):
+ os.mkdir(dest)
+ 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'], 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
« no previous file with comments | « no previous file | install_test/chrome_installer.py » ('j') | install_test/chrome_installer.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698