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

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, 7 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
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
kkania 2012/05/30 15:41:09 wrong shebang
nkang 2012/05/30 21:42:05 Fixed.
+# 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
kkania 2012/05/30 15:41:09 order
nkang 2012/05/30 21:42:05 I'm assuming you meant put them in alphabetical or
+import socket
+import subprocess
+
+__author__ = 'laforge/nkang'
+
+class ChromeCheckout:
kkania 2012/05/30 15:41:09 I don't think you need to throw everything into a
nkang 2012/05/30 21:42:05 They were all bare functions before, in a standalo
+ """A class to check out Chrome source files based on revision number."""
+
+ def __init__(self, version, dest=None):
kkania 2012/05/30 15:41:09 add a docstring for this. As a user of this class,
nkang 2012/05/30 21:42:05 Added a docstring and a brief description for each
+ # Verify that he version has the correct format.
kkania 2012/05/30 15:41:09 the
nkang 2012/05/30 21:42:05 Done.
+ self._version = ((lambda l: str(l[0]) if len(l) > 0 else '')
kkania 2012/05/30 15:41:09 this is hard to read what is going on
nkang 2012/05/30 21:42:05 It checks to make sure the version specified has t
+ ((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 '\
kkania 2012/05/30 15:41:09 I don't like ignoring the requested dir if we can'
nkang 2012/05/30 21:42:05 We decided against deletion, as the existing direc
+ '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.
kkania 2012/05/30 15:41:09 This function doesn't have anything to do with DEP
nkang 2012/05/30 21:42:05 Actually it does have something to do with DEPS. W
+
+ 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
kkania 2012/05/30 15:41:09 Get rid of this arg. Nobody that calls this functi
nkang 2012/05/30 21:42:05 It was used by the 'request' method. I think that'
+ 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"}
kkania 2012/05/30 15:41:09 use single quotes
nkang 2012/05/30 21:42:05 Removed all double quotes and replaced them with s
+ 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:
kkania 2012/05/30 15:41:09 don't you need to conn.close() here
nkang 2012/05/30 21:42:05 Done.
+ return None
+ data = response.read()
+ buff = ''
+ for line in data:
+ buff += line
kkania 2012/05/30 15:41:09 i'm not sure I understand the point of lines 66-68
nkang 2012/05/30 21:42:05 Theoretically they should be the same, but that's
+ conn.close()
+ return buff
+
+ def _GetDeps(self, version):
+ """Returns cached version of DEPS if possible, otherwise gets its contents.
kkania 2012/05/30 15:41:09 line > 80
nkang 2012/05/30 21:42:05 It was just a couple of spaces, that's why I misse
+
+ Args:
+ version: Chrome version number (e.g. - 21.0.1136.0).
kkania 2012/05/30 15:41:09 e.g., 21.0.1136.0
nkang 2012/05/30 21:42:05 Done.
+
+ Returns:
+ string: A string buffer containing the contents of the DEPS file.
kkania 2012/05/30 15:41:09 A string containing the contents of the DEPS file
nkang 2012/05/30 21:42:05 Done.
+ """
+ if not version:
+ return None
kkania 2012/05/30 15:41:09 I'd just remove the check from 81-82
nkang 2012/05/30 21:42:05 This is also something that Anthony had added, so
+ 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.
kkania 2012/05/30 15:41:09 Type of revision number to look up: 'selenium' or
nkang 2012/05/30 21:42:05 Done.
+
+ Returns:
+ A string representing the revision no. if successful, otherwise None.
kkania 2012/05/30 15:41:09 this isn't correct
nkang 2012/05/30 21:42:05 Sorry I missed the typecast to int. It is initiall
+ """
kkania 2012/05/30 15:41:09 assert that rev_type is either selenium or pyftpdl
nkang 2012/05/30 21:42:05 Done.
+ 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"
kkania 2012/05/30 15:41:09 use single quotes, not double, here and everywhere
nkang 2012/05/30 21:42:05 Done.
+ 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

Powered by Google App Engine
This is Rietveld 408576698