Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Checks out Chrome source files from SVN. | |
| 7 | |
| 8 Chrome release version number is required for checkout. The version number is | |
| 9 used to obtain the revision number, which is then used to checkout files from | |
| 10 SVN. | |
| 11 """ | |
| 12 | |
| 13 import httplib | |
| 14 import logging | |
| 15 import os | |
| 16 import re | |
| 17 import socket | |
| 18 import subprocess | |
| 19 | |
| 20 _BASE_SVN_URL = 'svn://svn.chromium.org/chrome' | |
| 21 _SELENIUM_URL = 'http://selenium.googlecode.com/svn/trunk/py' | |
| 22 _PYFTPDLIB_URL = 'http://pyftpdlib.googlecode.com/svn/trunk' | |
| 23 | |
| 24 | |
| 25 def _SetConfiguration(): | |
| 26 """Sets the logging configuration.""" | |
| 27 log_format = '%(asctime)s - %(levelname)s : %(message)s' | |
| 28 logging.basicConfig(level=logging.DEBUG, format=log_format) | |
| 29 | |
| 30 | |
| 31 _SetConfiguration() | |
| 32 | |
| 33 | |
| 34 def _GetContentAndReturnResponse(server, path): | |
| 35 """Issues a GET requst to server and returns the response body. | |
| 36 | |
| 37 Args: | |
| 38 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.
| |
| 39 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
| |
| 40 | |
| 41 Returns: | |
| 42 A string containing the response body. | |
| 43 """ | |
| 44 try: | |
| 45 conn = httplib.HTTPConnection(server) | |
| 46 headers = {'Content-type': 'text/html'} | |
| 47 conn.request('GET', path, '', headers) | |
| 48 response = conn.getresponse() | |
| 49 except socket.gaierror, err: | |
| 50 conn.close() | |
| 51 raise socket.gaierror(err) | |
|
kkania
2012/06/13 16:47:01
just do 'raise'
nkang
2012/06/13 23:35:09
Done.
| |
| 52 if response.status != 200: | |
| 53 conn.close() | |
| 54 raise RuntimeError('HTTP request returned the following status code: %d' % | |
| 55 response.status) | |
| 56 data = response.read() | |
| 57 conn.close() | |
| 58 assert(data) | |
|
kkania
2012/06/13 16:47:01
drop this
nkang
2012/06/13 23:35:09
Dropped it like a bad habit.
| |
| 59 return data | |
| 60 | |
| 61 | |
| 62 def _GetDeps(version): | |
| 63 """Returns contents of DEPS file that corresponds with the version number. | |
| 64 | |
| 65 Args: | |
| 66 version: Chrome version number (e.g., 21.0.1136.0). | |
| 67 """ | |
| 68 deps = _GetContentAndReturnResponse( | |
| 69 'src.chromium.org', | |
| 70 '/viewvc/chrome/releases/%s/DEPS' % version) | |
| 71 return deps | |
| 72 | |
| 73 | |
| 74 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.
| |
| 75 """Parses the version number to get the different identifiers. | |
| 76 | |
| 77 Args: | |
| 78 version: Chrome release version number. | |
| 79 """ | |
| 80 match = re.search(r'((\d+)\.(\d+)\.(\d+)\.(\d+))', version) | |
| 81 if match: | |
| 82 version = {'version': match.group(1), | |
| 83 'major': int(match.group(2)), | |
| 84 'minor': int(match.group(3)), | |
| 85 'build': int(match.group(4)), | |
| 86 'patch': int(match.group(5))} | |
| 87 return version | |
| 88 raise RuntimeError('Invalid version number was specified: %r' % version) | |
| 89 | |
| 90 | |
| 91 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
| |
| 92 """Gets the revision info by parsing the contents of the DEPS file. | |
| 93 | |
| 94 Args: | |
| 95 version_str: A string representing the Chrome version number. | |
| 96 body: A string that contains the contents of corresponding DEPS file. | |
| 97 | |
| 98 Returns: | |
| 99 A string that contains pertinent information about the Chrome version. | |
| 100 """ | |
| 101 version = _ParseVersion(version_str) | |
| 102 match = re.search("'src':[\n\r ]+'(.*?)'", body) | |
| 103 if match: | |
| 104 match = re.search(r"@(\d+)", match.group(1)) | |
| 105 if match: | |
| 106 version['revision'] = int(match.group(1)) | |
| 107 | |
| 108 match = re.search("""['"]src['"].*?:.*?['"]/branches/(.*?)/.*?,""", | |
| 109 body, re.DOTALL | re.IGNORECASE) | |
| 110 if match: | |
| 111 version['branch'] = match.group(1) | |
| 112 else: | |
| 113 version['branch'] = 'trunk' | |
| 114 return version | |
| 115 | |
| 116 | |
| 117 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
| |
| 118 """Gets selenium/pyftpdlib rev. number by parsing contents of DEPS file. | |
| 119 | |
| 120 Args: | |
| 121 version_str: A string representing the Chrome build number. | |
| 122 body: A string that contains the contents of corresponding DEPS file. | |
| 123 rev_type: Type of revision number to look up: 'selenium' or 'pyftpdlib'. | |
| 124 | |
| 125 Returns: | |
| 126 An integer representing the revision number that was requested. | |
| 127 """ | |
| 128 assert(rev_type == 'selenium' or rev_type == 'pyftpdlib') | |
| 129 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
| |
| 130 if rev_type == 'selenium': | |
| 131 m = re.search(r'http://selenium\.googlecode\.com/svn/trunk/py@(\d+)', | |
| 132 body, re.DOTALL | re.IGNORECASE | re.MULTILINE) | |
| 133 elif rev_type == 'pyftpdlib': | |
| 134 m = re.search(r'http://pyftpdlib\.googlecode\.com/svn/trunk@(\d+)', | |
| 135 body, re.DOTALL | re.IGNORECASE | re.MULTILINE) | |
| 136 if m: | |
| 137 return int(m.group(1)) | |
| 138 raise RuntimeError('Could not find the revision number in DEPS.') | |
| 139 | |
| 140 | |
| 141 def _SvnCo(path, revision=None, dest=None): | |
| 142 """Does a SVN checkout on specified source files. | |
| 143 | |
| 144 Args: | |
| 145 path: URL that is to be checked out. | |
| 146 revision: Revision number. | |
| 147 dest: Destination where the data will be downloaded. | |
| 148 """ | |
| 149 cmd = 'svn co' | |
| 150 if revision: | |
| 151 cmd += ' --revision %d' % revision | |
| 152 cmd += ' %s' % path | |
| 153 if dest: | |
| 154 cmd += ' %s' % dest | |
| 155 logging.info(cmd) | |
| 156 assert(subprocess.Popen(cmd, shell=True).wait() == 0) | |
| 157 | |
| 158 | |
| 159 def _GetPath(par, ch): | |
| 160 return (lambda p, c: os.path.join(p, c) if p else c)(par, ch) | |
| 161 | |
| 162 | |
| 163 def _IsVersionValid(ver): | |
| 164 """Checks if the version number has the correct format. | |
| 165 | |
| 166 Args: | |
| 167 ver: Version number to check. | |
| 168 | |
| 169 Returns: | |
| 170 True if 'n.n.n.n' pattern is found in version number, otherwise False. | |
| 171 """ | |
| 172 if type(ver) == str: | |
| 173 return re.findall('\d+\.\d+\.\d+\.\d+', ver) != [] | |
| 174 return False | |
| 175 | |
| 176 | |
| 177 def CheckOut(version, dest): | |
| 178 """Checks out all necessary source files. | |
| 179 | |
| 180 Args: | |
| 181 version: Chrome release version number (e.g., 21.0.1136.0). | |
| 182 dest: Destination where the checked out files will go. | |
| 183 """ | |
| 184 if not _IsVersionValid(version): | |
| 185 raise RuntimeError('Invalid version number was specified: %r.' % version) | |
| 186 if not os.path.isdir(dest): | |
| 187 try: | |
| 188 os.mkdir(dest) | |
| 189 except (OSError, IOError): | |
| 190 raise RuntimeError('Could not create %s.\r\n%s.' % (dest, err)) | |
| 191 deps = _GetDeps(version) | |
| 192 rev_info = _GetRevisionInfo(version, deps) | |
| 193 logging.info(rev_info) | |
| 194 # If its a patch, check out the branch. | |
| 195 if rev_info['patch']: | |
| 196 svn_url_base = _BASE_SVN_URL + '/branches/%s' % rev_info['branch'] | |
| 197 # If not, check out the trunk. | |
| 198 else: | |
| 199 svn_url_base = _BASE_SVN_URL + '/trunk' | |
| 200 _SvnCo('%s/src/chrome/test/functional' % svn_url_base, | |
| 201 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
| |
| 202 _SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base, | |
| 203 rev_info['revision'], _GetPath(dest, 'pyautolib')) | |
| 204 _SvnCo('%s/src/third_party/simplejson' % svn_url_base, | |
| 205 rev_info['revision'], _GetPath(dest, 'simplejson')) | |
| 206 _SvnCo('%s/src/third_party/tlslite' % svn_url_base, | |
| 207 rev_info['revision'], _GetPath(dest, 'tlslite')) | |
| 208 _SvnCo('%s/src/net/tools/testserver' % svn_url_base, | |
| 209 rev_info['revision'], _GetPath(dest, 'testserver')) | |
| 210 _SvnCo(_SELENIUM_URL, _GetRevision(version, deps, 'selenium'), | |
| 211 _GetPath(dest, 'selenium')) | |
| 212 _SvnCo(_PYFTPDLIB_URL, _GetRevision(version, deps, 'pyftpdlib'), | |
| 213 _GetPath(dest, 'pyftpdlib')) | |
| OLD | NEW |