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 | |
|
kkania
2012/06/09 00:06:10
have a description of this module
nkang
2012/06/12 23:48:33
Added a brief description.
| |
| 6 import httplib | |
| 7 import optparse | |
| 8 import os | |
| 9 import re | |
| 10 import socket | |
| 11 import subprocess | |
| 12 import sys | |
| 13 | |
| 14 _BASE_SVN_URL = 'svn://svn.chromium.org/chrome' | |
| 15 _SELENIUM_URL = 'http://selenium.googlecode.com/svn/trunk/py' | |
| 16 _PYFTPDLIB_URL = 'http://pyftpdlib.googlecode.com/svn/trunk' | |
| 17 _DEPS_CACHE = {} | |
| 18 | |
| 19 def _GetContentAndReturnResponse(server, path): | |
|
kkania
2012/06/09 00:06:10
two newlines between module-level definitions, in
nkang
2012/06/12 23:48:33
Added two blank lines, where needed.
| |
| 20 """Returns contents of DEPS file, which contains info about source files | |
|
kkania
2012/06/09 00:06:10
This func may be involved with the process of gett
nkang
2012/06/12 23:48:33
I don't dispute that you could get the latest news
| |
| 21 | |
| 22 needed. | |
| 23 | |
| 24 Args: | |
| 25 server: Host address, in this case the SVN server. | |
| 26 path: The URL where the file is located. | |
| 27 | |
| 28 Returns: | |
| 29 A string containing the file's contents if successful, otherwise None. | |
| 30 """ | |
| 31 try: | |
| 32 conn = httplib.HTTPConnection(server) | |
| 33 headers = {'Content-type': 'text/html'} | |
| 34 conn.request('GET', path, '', headers) | |
| 35 response = conn.getresponse() | |
| 36 except socket.gaierror, err: | |
| 37 print 'ChromeCheckout._GetContentAndReturnResponse: %s' % err | |
|
kkania
2012/06/09 00:06:10
either
1) catch this exception, do conn.close() an
nkang
2012/06/12 23:48:33
Got rid of the print statement. I now catch socket
| |
| 38 conn.close() | |
| 39 return None | |
| 40 if response.status != 200: | |
| 41 conn.close() | |
| 42 return None | |
|
kkania
2012/06/09 00:06:10
throw an exception here instead of returning None,
nkang
2012/06/12 23:48:33
RuntimeError is now raised if status code in not 2
| |
| 43 data = response.read() | |
| 44 conn.close() | |
| 45 return data | |
| 46 | |
| 47 def _GetDeps(version): | |
| 48 """Returns cached version of DEPS if possible, otherwise gets its contents. | |
| 49 | |
| 50 Args: | |
| 51 version: Chrome version number (e.g., 21.0.1136.0). | |
| 52 | |
| 53 Returns: | |
| 54 string: A string containing the contents of the DEPS file. | |
| 55 """ | |
| 56 if version in _DEPS_CACHE: | |
|
kkania
2012/06/09 00:06:10
get rid of the cache, and call getdeps in checkout
nkang
2012/06/12 23:48:33
Updated _GetDeps and got rid of _DEPS_CACHE. _GetD
| |
| 57 return _DEPS_CACHE[version] | |
| 58 deps = _GetContentAndReturnResponse('src.chromium.org', | |
| 59 '/viewvc/chrome/releases/%s/DEPS' | |
| 60 % version) | |
|
kkania
2012/06/09 00:06:10
This would be more readable:
deps = _GetContentAnd
nkang
2012/06/12 23:48:33
Done and done!
| |
| 61 _DEPS_CACHE[version] = deps | |
| 62 return deps | |
| 63 | |
| 64 def _ParseVersion(version): | |
| 65 """Parses the version number to get the different identifiers.""" | |
| 66 match = re.search(r'((\d+)\.(\d+)\.(\d+)\.(\d+))', version) | |
| 67 if match: | |
| 68 version = {'version': match.group(1), | |
| 69 'major': int(match.group(2)), | |
| 70 'minor': int(match.group(3)), | |
| 71 'build': int(match.group(4)), | |
| 72 'patch': int(match.group(5))} | |
| 73 return version | |
| 74 return {} | |
|
kkania
2012/06/09 00:06:10
throw
nkang
2012/06/12 23:48:33
Instead of returning an empty dictionary, the meth
| |
| 75 | |
| 76 def _GetRevisionInfo(version_str): | |
| 77 """Gets the revision info by parsing the contents of the DEPS file. | |
| 78 | |
| 79 Args: | |
| 80 version_str: A string representing the Chrome version number. | |
| 81 | |
| 82 Returns: | |
| 83 A string that contains pertinent information about the Chrome version. | |
| 84 """ | |
| 85 version = _ParseVersion(version_str) | |
| 86 if version: | |
| 87 body = _GetDeps(version['version']) | |
| 88 if body: | |
| 89 match = re.search("'src':[\n\r ]+'(.*?)'", body) | |
| 90 if match: | |
| 91 match = re.search(r"@(\d+)", match.group(1)) | |
| 92 if match: | |
| 93 version['revision'] = int(match.group(1)) | |
| 94 | |
| 95 match = re.search("""['"]src['"].*?:.*?['"]/branches/(.*?)/.*?,""", | |
| 96 body, re.DOTALL | re.IGNORECASE) | |
| 97 if match: | |
| 98 version['branch'] = match.group(1) | |
| 99 else: | |
| 100 version['branch'] = 'trunk' | |
| 101 return version | |
| 102 | |
| 103 def _GetRevision(version_str, rev_type='selenium'): | |
| 104 """Gets selenium/pyftpdlib rev. number by parsing contents of DEPS file. | |
| 105 | |
| 106 Args: | |
| 107 version_str: A string representing the Chrome build number. | |
| 108 rev_type: Type of revision number to look up: 'selenium' or 'pyftpdlib'. | |
| 109 | |
| 110 Returns: | |
| 111 An integer representing the revision no. if successful, otherwise None. | |
| 112 """ | |
| 113 assert(rev_type == 'selenium' or rev_type == 'pyftpdlib') | |
| 114 version = _ParseVersion(version_str) | |
| 115 if version: | |
| 116 body = _GetDeps(version_str) | |
| 117 if body: | |
| 118 if rev_type == 'selenium': | |
| 119 m = re.search(r'http://selenium\.googlecode\.com/svn/trunk/py@(\d+)', | |
| 120 body, re.DOTALL | re.IGNORECASE | re.MULTILINE) | |
| 121 elif rev_type == 'pyftpdlib': | |
| 122 m = re.search(r'http://pyftpdlib\.googlecode\.com/svn/trunk@(\d+)', | |
| 123 body, re.DOTALL | re.IGNORECASE | re.MULTILINE) | |
| 124 if m: | |
| 125 return int(m.group(1)) | |
| 126 return None | |
|
kkania
2012/06/09 00:06:10
throw and change doc
nkang
2012/06/12 23:48:33
This method now raises a RuntimeError, instead of
| |
| 127 | |
| 128 def _SvnCo(path, revision=None, dest=None): | |
| 129 """Does a SVN checkout on specified source files. | |
| 130 | |
| 131 Args: | |
| 132 path: URL that is to be checked out. | |
| 133 revision: Revision number. | |
| 134 dest: Destination where the data will be downloaded. | |
| 135 """ | |
| 136 cmd = 'svn co' | |
| 137 if revision: | |
| 138 cmd += ' --revision %d' % revision | |
| 139 cmd += ' %s' % path | |
| 140 if dest: | |
| 141 cmd += ' %s' % dest | |
| 142 print cmd | |
|
kkania
2012/06/09 00:06:10
use logging module or drop
nkang
2012/06/12 23:48:33
I have replaced all the print statements with logg
| |
| 143 return subprocess.Popen.wait(subprocess.Popen(cmd, shell=True)) | |
|
kkania
2012/06/09 00:06:10
can you just do subprocess.Popen(cmd, shell=True).
nkang
2012/06/12 23:48:33
Done.
| |
| 144 | |
| 145 def _GetPath(par, ch): | |
| 146 return (lambda p, c: os.path.join(p, c) if p else c)(par, ch) | |
| 147 | |
| 148 def _IsVersionValid(ver): | |
| 149 return ((lambda v: True if(type(v) == str and re.findall | |
|
kkania
2012/06/09 00:06:10
Make this more readable.
nkang
2012/06/12 23:48:33
Very readable now.
| |
| 150 ('\d+\.\d+\.\d+\.\d+', v) != []) else False)(ver)) | |
| 151 | |
| 152 def CheckOut(version, dest): | |
| 153 """Checks out all necessary source files.""" | |
|
kkania
2012/06/09 00:06:10
Args:
nkang
2012/06/12 23:48:33
Added description about 'Args'.
| |
| 154 if not _IsVersionValid(version): | |
| 155 print 'Invalid version no. was specified.' | |
|
kkania
2012/06/09 00:06:10
throw instead
nkang
2012/06/12 23:48:33
Thrown.
| |
| 156 return -1 | |
| 157 if not os.path.isdir(dest): | |
| 158 try: | |
| 159 os.mkdir(dest) | |
| 160 except (OSError, IOError): | |
| 161 raise RuntimeError('Could not create %s.\r\n%s.' % (dest, err)) | |
| 162 rev_info = _GetRevisionInfo(version) | |
| 163 print rev_info | |
|
kkania
2012/06/09 00:06:10
take a look at the logging module instead, or just
nkang
2012/06/12 23:48:33
See response I left on the logging comment above.
| |
| 164 # If its a patch, check out the branch. | |
| 165 if rev_info['patch']: | |
| 166 svn_url_base = _BASE_SVN_URL + '/branches/%s' % rev_info['branch'] | |
| 167 # If not, check out the trunk. | |
| 168 else: | |
| 169 svn_url_base = _BASE_SVN_URL + '/trunk' | |
| 170 _SvnCo('%s/src/chrome/test/functional' % svn_url_base, | |
| 171 rev_info['revision'], _GetPath(dest, 'functional')) | |
| 172 _SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base, | |
| 173 rev_info['revision'], _GetPath(dest, 'pyautolib')) | |
| 174 _SvnCo('%s/src/third_party/simplejson' % svn_url_base, | |
| 175 rev_info['revision'], _GetPath(dest, 'simplejson')) | |
| 176 _SvnCo('%s/src/third_party/tlslite' % svn_url_base, | |
| 177 rev_info['revision'], _GetPath(dest, 'tlslite')) | |
| 178 _SvnCo('%s/src/net/tools/testserver' % svn_url_base, | |
| 179 rev_info['revision'], _GetPath(dest, 'testserver')) | |
| 180 _SvnCo(_SELENIUM_URL, _GetRevision(version, 'selenium'), | |
| 181 _GetPath(dest, 'selenium')) | |
| 182 _SvnCo(_PYFTPDLIB_URL, _GetRevision(version, 'pyftpdlib'), | |
| 183 _GetPath(dest, 'pyftpdlib')) | |
| 184 return 0 | |
|
kkania
2012/06/09 00:06:10
don't return anything
nkang
2012/06/12 23:48:33
The return has been returned. Also updated install
| |
| OLD | NEW |