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

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, 4 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
« no previous file with comments | « no previous file | install_test/chrome_installer.py » ('j') | install_test/chrome_installer.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 """Utilities for checking 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
Nirnimesh 2012/08/09 21:32:48 describe how "The version number is used to obtain
nkang 2012/08/16 23:46:24 Changed the text so its more descriptive.
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):
Nirnimesh 2012/08/09 21:32:48 why not just use urllib?
nkang 2012/08/16 23:46:24 I thought about that, as well. But part of this sc
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:
Nirnimesh 2012/08/09 21:32:48 all this try/catch seems unncessary to me. Remove
nkang 2012/08/16 23:46:24 Got rid of the try/except block. Also, this method
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('%s/%s returned the following status code: %d' %
55 (server, path, 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)
Nirnimesh 2012/08/09 21:32:48 use ' for the outer quotes
nkang 2012/08/16 23:46:24 The reason we (Anthony LaForge originally added th
102 if match:
103 match = re.search(r"@(\d+)", match.group(1))
Nirnimesh 2012/08/09 21:32:48 use '
nkang 2012/08/16 23:46:24 Changed to single quotes.
104 if match:
105 version['revision'] = int(match.group(1))
106
107 match = re.search("""['"]src['"].*?:.*?['"]/branches/(.*?)/.*?,""",
Nirnimesh 2012/08/09 21:32:48 this is very confusing. give an example of what it
nkang 2012/08/16 23:46:24 Branch releases have the branch number listed in t
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'):
Nirnimesh 2012/08/09 21:32:48 do not provide default arg
nkang 2012/08/16 23:46:24 Got rid of the default argument.
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')
Nirnimesh 2012/08/09 21:32:48 remove parens
nkang 2012/08/16 23:46:24 Got rid of the parenthesis.
127 if rev_type == 'selenium':
128 m = re.search(r'http://selenium\.googlecode\.com/svn/trunk/py@(\d+)',
Nirnimesh 2012/08/09 21:32:48 m -> match
nkang 2012/08/16 23:46:24 d -> done!
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'
Nirnimesh 2012/08/09 21:32:48 make cmd a list, and then remove shell=True from l
nkang 2012/08/16 23:46:24 Changed cmd to a list. However, removing shell=Tru
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)
Nirnimesh 2012/08/09 21:32:48 remove outer parens
Nirnimesh 2012/08/09 21:32:48 remove assert. use subprocess.check_call instead
nkang 2012/08/16 23:46:24 Got rid of the assert and replaced it with subproc
nkang 2012/08/16 23:46:24 Got rid of the assert, so this no longer applies.
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) != []
Nirnimesh 2012/08/09 21:32:48 use re.match()
nkang 2012/08/16 23:46:24 Changed re.findall to re.match.
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 os.mkdir(dest)
181 deps = _GetDeps(version)
182 rev_info = _GetRevisionInfo(version, deps)
183 logging.info(rev_info)
184 # If its a patch, check out the branch.
185 if rev_info['patch']:
186 svn_url_base = _BASE_SVN_URL + '/branches/%s' % rev_info['branch']
187 # If not, check out the trunk.
188 else:
189 svn_url_base = _BASE_SVN_URL + '/trunk'
190 _SvnCo('%s/src/chrome/test/functional' % svn_url_base,
Nirnimesh 2012/08/09 21:32:48 This seems too fragile. if pyauto requires additio
nkang 2012/08/16 23:46:24 Checked with Ken about this and he was adamant tha
191 rev_info['revision'], os.path.join(dest, 'src', 'chrome', 'test',
Nirnimesh 2012/08/09 21:32:48 how do you plan to handle internal deps?
nkang 2012/08/16 23:46:24 Checked with Anantha about this, and she told me t
192 'functional'))
193 _SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base,
194 rev_info['revision'], os.path.join(dest, 'src', 'chrome', 'test',
195 'pyautolib'))
196 _SvnCo('%s/src/third_party/simplejson' % svn_url_base,
197 rev_info['revision'], os.path.join(dest, 'src', 'third_party',
198 'simplejson'))
199 _SvnCo('%s/src/third_party/tlslite' % svn_url_base,
200 rev_info['revision'], os.path.join(dest, 'src', 'third_party',
201 'tlslite'))
202 _SvnCo('%s/src/net/tools/testserver' % svn_url_base,
203 rev_info['revision'], os.path.join(dest, 'src', 'net', 'tools',
204 'testserver'))
205 _SvnCo(_SELENIUM_URL, _GetRevision(deps, 'selenium'),
206 os.path.join(dest, 'src', 'third_party', 'webdriver', 'pylib',
207 'selenium'))
208 _SvnCo(_PYFTPDLIB_URL, _GetRevision(deps, 'pyftpdlib'),
209 os.path.join(dest, 'src', 'third_party', 'pyftpdlib'))
OLDNEW
« no previous file with comments | « no previous file | install_test/chrome_installer.py » ('j') | install_test/chrome_installer.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698