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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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.
Nirnimesh 2012/07/04 00:39:19 Checks out -> Utilities for checking out
nkang 2012/07/13 23:50:50 Changed to "Utilities for checking out Chrome sour
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.
39 path: The path where the file is located.
40
41 Returns:
42 A string containing the response body.
43 """
44 try:
45 connection = httplib.HTTPConnection(server)
46 headers = {'Content-type': 'text/html'}
47 connection.request('GET', path, '', headers)
48 response = connection.getresponse()
49 except socket.gaierror, err:
50 connection.close()
51 raise err
52 if response.status != 200:
53 connection.close()
54 raise RuntimeError('HTTP request returned the following status code: %d' %
Nirnimesh 2012/07/04 00:39:19 include (server, path) in the message too
nkang 2012/07/13 23:50:50 Server and path are now included in the error mess
55 response.status)
56 data = response.read()
57 connection.close()
58 return data
59
60
61 def _GetDeps(version):
62 """Returns contents of DEPS file that corresponds with the version number.
63
64 Args:
65 version: Chrome version number (e.g., 21.0.1136.0).
66 """
67 deps = _GetContentAndReturnResponse(
68 'src.chromium.org',
69 '/viewvc/chrome/releases/%s/DEPS' % version)
70 return deps
71
72
73 def _ParseVersion(version_str):
74 """Parses the version string to get the different identifiers.
75
76 Args:
77 version_str: Chrome release version number.
78 """
79 match = re.search(r'((\d+)\.(\d+)\.(\d+)\.(\d+))', version_str)
80 if match:
81 version = {'version': match.group(1),
82 'major': int(match.group(2)),
83 'minor': int(match.group(3)),
84 'build': int(match.group(4)),
85 'patch': int(match.group(5))}
86 return version
87 raise RuntimeError('Invalid version number was specified: %r' % version_str)
88
89
90 def _GetRevisionInfo(version_str, deps):
91 """Gets the revision info by parsing the contents of the DEPS file.
92
93 Args:
94 version_str: A string representing the Chrome version number.
95 deps: A string that contains the contents of corresponding DEPS file.
96
97 Returns:
98 A string that contains pertinent information about the Chrome version.
99 """
100 version = _ParseVersion(version_str)
101 match = re.search("'src':[\n\r ]+'(.*?)'", deps)
102 if match:
103 match = re.search(r"@(\d+)", match.group(1))
104 if match:
105 version['revision'] = int(match.group(1))
106
107 match = re.search("""['"]src['"].*?:.*?['"]/branches/(.*?)/.*?,""",
108 deps, re.DOTALL | re.IGNORECASE)
109 if match:
110 version['branch'] = match.group(1)
111 else:
112 version['branch'] = 'trunk'
113 return version
114
115
116 def _GetRevision(deps, rev_type='selenium'):
117 """Gets selenium/pyftpdlib rev. number by parsing contents of DEPS file.
118
119 Args:
120 deps: A string that contains the contents of corresponding DEPS file.
121 rev_type: Type of revision number to look up: 'selenium' or 'pyftpdlib'.
122
123 Returns:
124 An integer representing the revision number that was requested.
125 """
126 assert(rev_type == 'selenium' or rev_type == 'pyftpdlib')
127 if rev_type == 'selenium':
128 m = re.search(r'http://selenium\.googlecode\.com/svn/trunk/py@(\d+)',
129 deps, re.DOTALL | re.IGNORECASE | re.MULTILINE)
130 elif rev_type == 'pyftpdlib':
131 m = re.search(r'http://pyftpdlib\.googlecode\.com/svn/trunk@(\d+)',
132 deps, re.DOTALL | re.IGNORECASE | re.MULTILINE)
133 if m:
134 return int(m.group(1))
135 raise RuntimeError('Could not find the revision number in DEPS.')
136
137
138 def _SvnCo(path, revision=None, dest=None):
139 """Does a SVN checkout on specified source files.
140
141 Args:
142 path: URL that is to be checked out.
143 revision: Revision number.
144 dest: Destination where the data will be downloaded.
145 """
146 cmd = 'svn co'
147 if revision:
148 cmd += ' --revision %d' % revision
149 cmd += ' %s' % path
150 if dest:
151 cmd += ' %s' % dest
152 logging.info(cmd)
153 assert(subprocess.Popen(cmd, shell=True).wait() == 0)
154
155
156 def _IsVersionValid(version):
157 """Checks if the version number has the correct format.
158
159 Args:
160 version: Version number to check.
161
162 Returns:
163 True if 'n.n.n.n' pattern is found in version number, otherwise False.
164 """
165 if type(version) == str:
166 return re.findall('\d+\.\d+\.\d+\.\d+', version) != []
167 return False
168
169
170 def CheckOut(version, dest):
171 """Checks out all necessary source files.
172
173 Args:
174 version: Chrome release version number (e.g., 21.0.1136.0).
175 dest: Destination where the checked out files will go.
176 """
177 if not _IsVersionValid(version):
178 raise RuntimeError('Invalid version number was specified: %r.' % version)
179 if not os.path.isdir(dest):
180 try:
181 os.mkdir(dest)
182 except (OSError, IOError):
Nirnimesh 2012/07/04 00:39:19 do not try to catch it. The default behavior is fi
nkang 2012/07/13 23:50:50 Got rid of the try/except block altogether. I supp
183 raise RuntimeError('Could not create %s.\r\n%s.' % (dest, err))
184 deps = _GetDeps(version)
185 rev_info = _GetRevisionInfo(version, deps)
186 logging.info(rev_info)
187 # If its a patch, check out the branch.
188 if rev_info['patch']:
189 svn_url_base = _BASE_SVN_URL + '/branches/%s' % rev_info['branch']
190 # If not, check out the trunk.
191 else:
192 svn_url_base = _BASE_SVN_URL + '/trunk'
193 _SvnCo('%s/src/chrome/test/functional' % svn_url_base,
Nirnimesh 2012/07/04 00:39:19 Checking out individual files like these is very h
nkang 2012/07/13 23:50:50 We deliberately decided to check out only select f
194 rev_info['revision'], os.path.join(dest, 'src', 'chrome', 'test',
195 'functional'))
196 _SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base,
197 rev_info['revision'], os.path.join(dest, 'src', 'chrome', 'test',
198 'pyautolib'))
199 _SvnCo('%s/src/third_party/simplejson' % svn_url_base,
200 rev_info['revision'], os.path.join(dest, 'src', 'third_party',
201 'simplejson'))
202 _SvnCo('%s/src/third_party/tlslite' % svn_url_base,
203 rev_info['revision'], os.path.join(dest, 'src', 'third_party',
204 'tlslite'))
205 _SvnCo('%s/src/net/tools/testserver' % svn_url_base,
206 rev_info['revision'], os.path.join(dest, 'src', 'net', 'tools',
207 'testserver'))
208 _SvnCo(_SELENIUM_URL, _GetRevision(deps, 'selenium'),
209 os.path.join(dest, 'src', 'third_party', 'webdriver', 'pylib',
210 'selenium'))
211 _SvnCo(_PYFTPDLIB_URL, _GetRevision(deps, 'pyftpdlib'),
212 os.path.join(dest, 'src', 'third_party', 'pyftpdlib'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698