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

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, 6 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/python
kkania 2012/05/30 15:41:09 wrong shebang
nkang 2012/05/30 21:42:05 Fixed.
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 import httplib
7 import optparse
8 import os
9 import re
10 import sys
kkania 2012/05/30 15:41:09 order
nkang 2012/05/30 21:42:05 I'm assuming you meant put them in alphabetical or
11 import socket
12 import subprocess
13
14 __author__ = 'laforge/nkang'
15
16 class ChromeCheckout:
kkania 2012/05/30 15:41:09 I don't think you need to throw everything into a
nkang 2012/05/30 21:42:05 They were all bare functions before, in a standalo
17 """A class to check out Chrome source files based on revision number."""
18
19 def __init__(self, version, dest=None):
kkania 2012/05/30 15:41:09 add a docstring for this. As a user of this class,
nkang 2012/05/30 21:42:05 Added a docstring and a brief description for each
20 # Verify that he version has the correct format.
kkania 2012/05/30 15:41:09 the
nkang 2012/05/30 21:42:05 Done.
21 self._version = ((lambda l: str(l[0]) if len(l) > 0 else '')
kkania 2012/05/30 15:41:09 this is hard to read what is going on
nkang 2012/05/30 21:42:05 It checks to make sure the version specified has t
22 ((lambda v: re.findall('\S+\.\S+\.\S+\.\S+', v)
23 if(type(v) == str) else [])(version)))
24 self._dest = dest
25 self._base_svn_url = 'svn://svn.chromium.org/chrome'
26 self._selenium_url = 'http://selenium.googlecode.com/svn/trunk/py'
27 self._pyftpdlib_url = 'http://pyftpdlib.googlecode.com/svn/trunk'
28 self._deps_cache = {}
29 self._GetPath = (lambda par, ch: os.path.join(par, ch) if par else ch)
30 # By default the destination is the CWD, but if a different directory was
31 # specified, make sure it exists. If not, create it.
32 if self._dest:
33 if not os.path.isdir(self._dest):
34 try:
35 os.mkdir(self._dest)
36 # Failed to create test directory, CWD will be used for checkout.
37 except(OSError, IOError), err:
38 print 'ChromeCheckout.__init__: Failed to create %s. Checkout '\
kkania 2012/05/30 15:41:09 I don't like ignoring the requested dir if we can'
nkang 2012/05/30 21:42:05 We decided against deletion, as the existing direc
39 'will be done in the current working directory.' % self._dest
40 self._dest = None
41
42 def _GetContentAndReturnResponse(self, server, path, content):
43 """Gets contents of DEPS, which contains info about source files needed.
kkania 2012/05/30 15:41:09 This function doesn't have anything to do with DEP
nkang 2012/05/30 21:42:05 Actually it does have something to do with DEPS. W
44
45 Args:
46 server: Host address, in this case the SVN server.
47 path: The URL where the file is located.
48 content: A string of data to send after the headers are finished. By
kkania 2012/05/30 15:41:09 Get rid of this arg. Nobody that calls this functi
nkang 2012/05/30 21:42:05 It was used by the 'request' method. I think that'
49 default its an empty string and should be left that way.
50
51 Returns:
52 A string containing the file's contents if successful, otherwise None.
53 """
54 try:
55 conn = httplib.HTTPConnection(server)
56 headers = {"Content-type": "text/html"}
kkania 2012/05/30 15:41:09 use single quotes
nkang 2012/05/30 21:42:05 Removed all double quotes and replaced them with s
57 conn.request('GET', path, content, headers)
58 response = conn.getresponse()
59 except socket.gaierror, err:
60 print 'ChromeCheckout._GetContentAndReturnResponse: %s' % err
61 conn.close()
62 return None
63 if response.status != 200:
kkania 2012/05/30 15:41:09 don't you need to conn.close() here
nkang 2012/05/30 21:42:05 Done.
64 return None
65 data = response.read()
66 buff = ''
67 for line in data:
68 buff += line
kkania 2012/05/30 15:41:09 i'm not sure I understand the point of lines 66-68
nkang 2012/05/30 21:42:05 Theoretically they should be the same, but that's
69 conn.close()
70 return buff
71
72 def _GetDeps(self, version):
73 """Returns cached version of DEPS if possible, otherwise gets its contents.
kkania 2012/05/30 15:41:09 line > 80
nkang 2012/05/30 21:42:05 It was just a couple of spaces, that's why I misse
74
75 Args:
76 version: Chrome version number (e.g. - 21.0.1136.0).
kkania 2012/05/30 15:41:09 e.g., 21.0.1136.0
nkang 2012/05/30 21:42:05 Done.
77
78 Returns:
79 string: A string buffer containing the contents of the DEPS file.
kkania 2012/05/30 15:41:09 A string containing the contents of the DEPS file
nkang 2012/05/30 21:42:05 Done.
80 """
81 if not version:
82 return None
kkania 2012/05/30 15:41:09 I'd just remove the check from 81-82
nkang 2012/05/30 21:42:05 This is also something that Anthony had added, so
83 if version in self._deps_cache:
84 return self._deps_cache[version]
85 deps = self._GetContentAndReturnResponse('src.chromium.org',
86 '/viewvc/chrome/releases/%s/DEPS'
87 % version, '')
88 self._deps_cache[version] = deps
89 return deps
90
91 def _ParseVersion(self, version):
92 """Parses the version number to get the different identifiers."""
93 match = re.search(r'((\d+)\.(\d+)\.(\d+)\.(\d+))', version)
94 if match:
95 version = {'version': match.group(1),
96 'major': int(match.group(2)),
97 'minor': int(match.group(3)),
98 'build': int(match.group(4)),
99 'patch': int(match.group(5))}
100 return version
101 return {}
102
103 def _GetRevisionInfo(self, version_str):
104 """Gets the revision info by parsing the contents of the DEPS file.
105
106 Args:
107 version_str: A string representing the Chrome version number.
108
109 Returns:
110 A string that contains pertinent information about the Chrome version.
111 """
112 version = self._ParseVersion(version_str)
113 if version:
114 body = self._GetDeps(version['version'])
115 if body:
116 match = re.search("'src':[\n\r ]+'(.*?)'", body)
117 if match:
118 match = re.search(r"@(\d+)", match.group(1))
119 if match:
120 version['revision'] = int(match.group(1))
121
122 match = re.search("""['"]src['"].*?:.*?['"]/branches/(.*?)/.*?,""",
123 body, re.DOTALL | re.IGNORECASE)
124 if match:
125 version['branch'] = match.group(1)
126 else:
127 version['branch'] = 'trunk'
128 return version
129
130 def _GetRevision(self, version_str, rev_type='selenium'):
131 """Gets selenium/pyftpdlib rev. number by parsing contents of DEPS file.
132
133 Args:
134 version_str: A string representing the Chrome build number.
135 rev_type: Type of revision number to look up - Selenium or Pyftpdlib.
kkania 2012/05/30 15:41:09 Type of revision number to look up: 'selenium' or
nkang 2012/05/30 21:42:05 Done.
136
137 Returns:
138 A string representing the revision no. if successful, otherwise None.
kkania 2012/05/30 15:41:09 this isn't correct
nkang 2012/05/30 21:42:05 Sorry I missed the typecast to int. It is initiall
139 """
kkania 2012/05/30 15:41:09 assert that rev_type is either selenium or pyftpdl
nkang 2012/05/30 21:42:05 Done.
140 version = self._ParseVersion(version_str)
141 if version:
142 body = self._GetDeps(version_str)
143 if body:
144 if rev_type == 'selenium':
145 m = re.search(r"http://selenium\.googlecode\.com/svn/trunk/py@(\d+)",
146 body, re.DOTALL | re.IGNORECASE | re.MULTILINE)
147 elif rev_type == 'pyftpdlib':
148 m = re.search(r"http://pyftpdlib\.googlecode\.com/svn/trunk@(\d+)",
149 body, re.DOTALL | re.IGNORECASE | re.MULTILINE)
150 if m:
151 return int(m.group(1))
152 return None
153
154 def _SvnCo(self, path, revision=None, dest=None):
155 """Does a SVN checkout on specified source files.
156
157 Args:
158 path: URL that is to be checked out.
159 revision: Revision number.
160 dest: Destination where the data will be downloaded.
161 """
162 cmd = "svn co"
kkania 2012/05/30 15:41:09 use single quotes, not double, here and everywhere
nkang 2012/05/30 21:42:05 Done.
163 if revision:
164 cmd += " --revision %d" % revision
165 cmd += " %s" % path
166 if dest:
167 cmd += " %s" % dest
168 print cmd
169 return subprocess.Popen.wait(subprocess.Popen(cmd, shell=True))
170
171 def CheckOut(self):
172 """Checks out all necessary source files."""
173 # No version was specified.
174 if not self._version:
175 print 'Please specify a Chrome version to checkout.'
176 return -1
177 rev_info = self._GetRevisionInfo(self._version)
178 print rev_info
179 # If its a patch, check out the branch.
180 if rev_info['patch']:
181 svn_url_base = self._base_svn_url + '/branches/%s' % rev_info['branch']
182 # If not, check out the trunk.
183 else:
184 svn_url_base = self._base_svn_url + '/trunk'
185 self._SvnCo('%s/src/chrome/test/functional' % svn_url_base,
186 rev_info['revision'], self._GetPath(self._dest, 'functional'))
187 self._SvnCo('%s/src/chrome/test/pyautolib' % svn_url_base,
188 rev_info['revision'], self._GetPath(self._dest, 'pyautolib'))
189 self._SvnCo('%s/src/third_party/simplejson' % svn_url_base,
190 rev_info['revision'], self._GetPath(self._dest, 'simplejson'))
191 self._SvnCo('%s/src/third_party/tlslite' % svn_url_base,
192 rev_info['revision'], self._GetPath(self._dest, 'tlslite'))
193 self._SvnCo('%s/src/net/tools/testserver' % svn_url_base,
194 rev_info['revision'], self._GetPath(self._dest, 'testserver'))
195 self._SvnCo(self._selenium_url, self._GetRevision(
196 self._version, 'selenium'), self._GetPath(self._dest, 'selenium'))
197 self._SvnCo(self._pyftpdlib_url, self._GetRevision(
198 self._version, 'pyftpdlib'), self._GetPath(self._dest, 'pyftpdlib'))
199 return 0
200
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698