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 """Utilities for checking out Chrome source files from SVN. | |
| 7 | |
| 8 Chrome release version number is required for checkout. Version number is used | |
| 9 to lookup the corresponding DEPS file from Chrome releases. DEPS file contains | |
| 10 the dependencies, revision number, and other pertinent information about that | |
| 11 particular build. It also specifies whether its a branch or a trunk release | |
| 12 and contains a corresponding revision number. The revision number, which is | |
| 13 needed to checkout files from SVN, is obtained by parsing the contents of the | |
| 14 DEPS file. | |
| 15 """ | |
| 16 | |
| 17 import httplib | |
| 18 import logging | |
| 19 import os | |
| 20 import re | |
| 21 import socket | |
| 22 import subprocess | |
| 23 import urllib2 | |
| 24 | |
| 25 _BASE_SVN_URL = 'svn://svn.chromium.org/chrome' | |
| 26 _SELENIUM_URL = 'http://selenium.googlecode.com/svn/trunk/py' | |
| 27 _PYFTPDLIB_URL = 'http://pyftpdlib.googlecode.com/svn/trunk' | |
| 28 | |
| 29 | |
| 30 def _SetConfiguration(): | |
|
Nirnimesh
2012/08/22 07:06:35
rename -> _SetupLogging
nkang
2012/08/24 22:45:26
Done.
| |
| 31 """Sets the logging configuration.""" | |
| 32 log_format = '%(asctime)s - %(levelname)s : %(message)s' | |
| 33 logging.basicConfig(level=logging.DEBUG, format=log_format) | |
| 34 | |
| 35 | |
| 36 _SetConfiguration() | |
| 37 | |
| 38 | |
| 39 def _GetContentAndReturnResponse(url): | |
| 40 """Gets contents of the file at the specified url. | |
| 41 | |
| 42 Args: | |
| 43 url: The path where the file is located. | |
| 44 | |
| 45 Returns: | |
| 46 A string containing the file contents. | |
| 47 """ | |
| 48 url_opener = urllib2.urlopen(url) | |
| 49 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.
| |
| 50 url_opener.close() | |
| 51 return buff | |
| 52 | |
| 53 | |
| 54 def _GetDeps(version): | |
| 55 """Returns contents of DEPS file that corresponds with the version number. | |
| 56 | |
| 57 Args: | |
| 58 version: Chrome version number (e.g., 21.0.1136.0). | |
| 59 """ | |
| 60 deps = _GetContentAndReturnResponse( | |
| 61 '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
| |
| 62 return deps | |
| 63 | |
| 64 | |
| 65 def _ParseVersion(version_str): | |
| 66 """Parses the version string to get the different identifiers. | |
| 67 | |
| 68 Args: | |
| 69 version_str: Chrome release version number. | |
| 70 """ | |
| 71 match = re.search(r'((\d+)\.(\d+)\.(\d+)\.(\d+))', version_str) | |
| 72 if match: | |
| 73 version = {'version': match.group(1), | |
| 74 'major': int(match.group(2)), | |
| 75 'minor': int(match.group(3)), | |
| 76 'build': int(match.group(4)), | |
| 77 'patch': int(match.group(5))} | |
| 78 return version | |
| 79 raise RuntimeError('Invalid version number was specified: %r' % version_str) | |
| 80 | |
| 81 | |
| 82 def _GetRevisionInfo(version_str, deps): | |
| 83 """Gets the revision info by parsing the contents of the DEPS file. | |
| 84 | |
| 85 Args: | |
| 86 version_str: A string representing the Chrome version number. | |
| 87 deps: A string that contains the contents of corresponding DEPS file. | |
| 88 | |
| 89 Returns: | |
| 90 A string that contains pertinent information about the Chrome version. | |
| 91 """ | |
| 92 version = _ParseVersion(version_str) | |
| 93 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
| |
| 94 if match: | |
| 95 match = re.search(r'@(\d+)', match.group(1)) | |
| 96 if match: | |
| 97 version['revision'] = int(match.group(1)) | |
| 98 | |
| 99 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
| |
| 100 deps, re.DOTALL | re.IGNORECASE) | |
| 101 if match: | |
| 102 version['branch'] = match.group(1) | |
| 103 else: | |
| 104 version['branch'] = 'trunk' | |
| 105 return version | |
| 106 | |
| 107 | |
| 108 def _GetRevision(deps, rev_type): | |
| 109 """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.
| |
| 110 | |
| 111 Args: | |
| 112 deps: A string that contains the contents of corresponding DEPS file. | |
| 113 rev_type: Type of revision number to look up: 'selenium' or 'pyftpdlib'. | |
| 114 | |
| 115 Returns: | |
| 116 An integer representing the revision number that was requested. | |
| 117 """ | |
| 118 assert rev_type == 'selenium' or rev_type == 'pyftpdlib' | |
| 119 if rev_type == 'selenium': | |
| 120 match = re.search(r'http://selenium\.googlecode\.com/svn/trunk/py@(\d+)', | |
| 121 deps, re.DOTALL | re.IGNORECASE | re.MULTILINE) | |
| 122 elif rev_type == 'pyftpdlib': | |
| 123 match = re.search(r'http://pyftpdlib\.googlecode\.com/svn/trunk@(\d+)', | |
| 124 deps, re.DOTALL | re.IGNORECASE | re.MULTILINE) | |
| 125 if match: | |
| 126 return int(match.group(1)) | |
| 127 raise RuntimeError('Could not find the revision number in DEPS.') | |
| 128 | |
| 129 | |
| 130 def _SvnCo(path, revision=None, dest=None): | |
|
Nirnimesh
2012/08/22 07:06:35
_SvnCheckout
nkang
2012/08/24 22:45:26
Done.
| |
| 131 """Does a SVN checkout on specified source files. | |
| 132 | |
| 133 Args: | |
| 134 path: URL that is to be checked out. | |
| 135 revision: Revision number. | |
| 136 dest: Destination where the data will be downloaded. | |
| 137 """ | |
| 138 cmd = 'svn co' | |
|
Nirnimesh
2012/08/22 07:06:35
co -> checkout
nkang
2012/08/24 22:45:26
Done.
| |
| 139 if revision: | |
| 140 cmd += ' --revision %d' % revision | |
| 141 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
| |
| 142 if dest: | |
| 143 cmd += ' %s' % dest | |
|
Nirnimesh
2012/08/22 07:06:35
ditto
nkang
2012/08/24 22:45:26
See response above.
| |
| 144 logging.info(cmd) | |
| 145 subprocess.check_call([cmd], shell=True) | |
| 146 | |
| 147 | |
| 148 def _IsVersionValid(version): | |
| 149 """Checks if the version number has the correct format. | |
| 150 | |
| 151 Args: | |
| 152 version: Version number to check. | |
| 153 | |
| 154 Returns: | |
| 155 True if 'n.n.n.n' pattern is found in version number, otherwise False. | |
| 156 """ | |
| 157 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
| |
| 158 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
| |
| 159 if match: | |
| 160 return True | |
| 161 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
| |
| 162 | |
| 163 | |
| 164 def CheckOut(version, dest): | |
| 165 """Checks out all necessary source files. | |
| 166 | |
| 167 Args: | |
| 168 version: Chrome release version number (e.g., 21.0.1136.0). | |
| 169 dest: Destination where the checked out files will go. | |
| 170 """ | |
| 171 if not _IsVersionValid(version): | |
| 172 raise RuntimeError('Invalid version number was specified: %r.' % version) | |
| 173 if not os.path.isdir(dest): | |
| 174 os.mkdir(dest) | |
| 175 deps = _GetDeps(version) | |
| 176 rev_info = _GetRevisionInfo(version, deps) | |
| 177 logging.info(rev_info) | |
| 178 # 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.
| |
| 179 if rev_info['patch']: | |
| 180 svn_url_base = _BASE_SVN_URL + '/branches/%s' % rev_info['branch'] | |
| 181 # If not, check out the trunk. | |
| 182 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.
| |
| 183 svn_url_base = _BASE_SVN_URL + '/trunk' | |
| 184 _SvnCo('%s/src/chrome/test/functional' % svn_url_base, | |
| 185 rev_info['revision'], os.path.join(dest, 'src', 'chrome', 'test', | |
| 186 'functional')) | |
| 187 _SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base, | |
| 188 rev_info['revision'], os.path.join(dest, 'src', 'chrome', 'test', | |
| 189 'pyautolib')) | |
| 190 _SvnCo('%s/src/third_party/simplejson' % svn_url_base, | |
| 191 rev_info['revision'], os.path.join(dest, 'src', 'third_party', | |
| 192 'simplejson')) | |
| 193 _SvnCo('%s/src/third_party/tlslite' % svn_url_base, | |
| 194 rev_info['revision'], os.path.join(dest, 'src', 'third_party', | |
| 195 'tlslite')) | |
| 196 _SvnCo('%s/src/net/tools/testserver' % svn_url_base, | |
| 197 rev_info['revision'], os.path.join(dest, 'src', 'net', 'tools', | |
| 198 'testserver')) | |
| 199 _SvnCo(_SELENIUM_URL, _GetRevision(deps, 'selenium'), | |
| 200 os.path.join(dest, 'src', 'third_party', 'webdriver', 'pylib', | |
| 201 'selenium')) | |
| 202 _SvnCo(_PYFTPDLIB_URL, _GetRevision(deps, 'pyftpdlib'), | |
| 203 os.path.join(dest, 'src', 'third_party', 'pyftpdlib')) | |
| OLD | NEW |