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

Side by Side Diff: tests/fake_repos.py

Issue 6690034: Add more python 2.5 compatibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Don't force python 2.5 anymore (to be done in a separate change) Created 9 years, 8 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/env python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generate fake repositories for testing.""" 6 """Generate fake repositories for testing."""
7 7
8 import atexit 8 import atexit
9 import datetime 9 import datetime
10 import errno 10 import errno
11 import logging 11 import logging
12 import os 12 import os
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 time.sleep(0.1) 180 time.sleep(0.1)
181 181
182 try: 182 try:
183 start = datetime.datetime.utcnow() 183 start = datetime.datetime.utcnow()
184 maxdelay = datetime.timedelta(seconds=30) 184 maxdelay = datetime.timedelta(seconds=30)
185 while (datetime.datetime.utcnow() - start) < maxdelay: 185 while (datetime.datetime.utcnow() - start) < maxdelay:
186 try: 186 try:
187 sock.connect((host, port)) 187 sock.connect((host, port))
188 logging.debug('%d is now bound' % port) 188 logging.debug('%d is now bound' % port)
189 return 189 return
190 except EnvironmentError: 190 except (socket.error, EnvironmentError):
191 pass 191 pass
192 logging.debug('%d is still not bound' % port) 192 logging.debug('%d is still not bound' % port)
193 finally: 193 finally:
194 sock.close() 194 sock.close()
195 # The process failed to bind. Kill it and dump its ouput. 195 # The process failed to bind. Kill it and dump its ouput.
196 process.kill() 196 process.kill()
197 logging.error('%s' % process.communicate()[0]) 197 logging.error('%s' % process.communicate()[0])
198 assert False, '%d is still not bound' % port 198 assert False, '%d is still not bound' % port
199 199
200 200
201 def wait_for_port_to_free(host, port): 201 def wait_for_port_to_free(host, port):
202 start = datetime.datetime.utcnow() 202 start = datetime.datetime.utcnow()
203 maxdelay = datetime.timedelta(seconds=30) 203 maxdelay = datetime.timedelta(seconds=30)
204 while (datetime.datetime.utcnow() - start) < maxdelay: 204 while (datetime.datetime.utcnow() - start) < maxdelay:
205 try: 205 try:
206 sock = socket.socket() 206 sock = socket.socket()
207 sock.connect((host, port)) 207 sock.connect((host, port))
208 logging.debug('%d was bound, waiting to free' % port) 208 logging.debug('%d was bound, waiting to free' % port)
209 except EnvironmentError: 209 except (socket.error, EnvironmentError):
210 logging.debug('%d now free' % port) 210 logging.debug('%d now free' % port)
211 return 211 return
212 finally: 212 finally:
213 sock.close() 213 sock.close()
214 assert False, '%d is still bound' % port 214 assert False, '%d is still bound' % port
215 215
216 216
217 _FAKE_LOADED = False 217 _FAKE_LOADED = False
218 218
219 class FakeReposBase(object): 219 class FakeReposBase(object):
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 else: 357 else:
358 write(join(root, k), v) 358 write(join(root, k), v)
359 359
360 def set_up_svn(self): 360 def set_up_svn(self):
361 """Creates subversion repositories and start the servers.""" 361 """Creates subversion repositories and start the servers."""
362 self.set_up() 362 self.set_up()
363 if self.svnserve: 363 if self.svnserve:
364 return True 364 return True
365 try: 365 try:
366 check_call(['svnadmin', 'create', self.svn_repo]) 366 check_call(['svnadmin', 'create', self.svn_repo])
367 except OSError: 367 except OSError, e:
368 logging.debug('Failed with : %s' % e)
368 return False 369 return False
369 write(join(self.svn_repo, 'conf', 'svnserve.conf'), 370 write(join(self.svn_repo, 'conf', 'svnserve.conf'),
370 '[general]\n' 371 '[general]\n'
371 'anon-access = read\n' 372 'anon-access = read\n'
372 'auth-access = write\n' 373 'auth-access = write\n'
373 'password-db = passwd\n') 374 'password-db = passwd\n')
374 text = '[users]\n' 375 text = '[users]\n'
375 text += ''.join('%s = %s\n' % (usr, pwd) for usr, pwd in self.USERS) 376 text += ''.join('%s = %s\n' % (usr, pwd) for usr, pwd in self.USERS)
376 write(join(self.svn_repo, 'conf', 'passwd'), text) 377 write(join(self.svn_repo, 'conf', 'passwd'), text)
377 378
378 # Mac 10.6 ships with a buggy subversion build and we need this line 379 # Mac 10.6 ships with a buggy subversion build and we need this line
379 # to work around the bug. 380 # to work around the bug.
380 write(join(self.svn_repo, 'db', 'fsfs.conf'), 381 write(join(self.svn_repo, 'db', 'fsfs.conf'),
381 '[rep-sharing]\n' 382 '[rep-sharing]\n'
382 'enable-rep-sharing = false\n') 383 'enable-rep-sharing = false\n')
383 384
384 # Start the daemon. 385 # Start the daemon.
385 self.svn_port = find_free_port(self.host, 10000) 386 self.svn_port = find_free_port(self.host, 10000)
387 logging.debug('Using port %d' % self.svn_port)
386 cmd = ['svnserve', '-d', '--foreground', '-r', self.root_dir, 388 cmd = ['svnserve', '-d', '--foreground', '-r', self.root_dir,
387 '--listen-port=%d' % self.svn_port] 389 '--listen-port=%d' % self.svn_port]
388 if self.host == '127.0.0.1': 390 if self.host == '127.0.0.1':
389 cmd.append('--listen-host=' + self.host) 391 cmd.append('--listen-host=' + self.host)
390 self.check_port_is_free(self.svn_port) 392 self.check_port_is_free(self.svn_port)
391 self.svnserve = Popen(cmd, cwd=self.svn_repo) 393 self.svnserve = Popen(cmd, cwd=self.svn_repo)
392 wait_for_port_to_bind(self.host, self.svn_port, self.svnserve) 394 wait_for_port_to_bind(self.host, self.svn_port, self.svnserve)
393 self.svn_base = 'svn://%s:%d/svn/' % (self.host, self.svn_port) 395 self.svn_base = 'svn://%s:%d/svn/' % (self.host, self.svn_port)
394 self.populateSvn() 396 self.populateSvn()
395 self.svn_dirty = False 397 self.svn_dirty = False
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 else: 447 else:
446 new_tree = tree.copy() 448 new_tree = tree.copy()
447 self.git_hashes[repo].append((commit_hash, new_tree)) 449 self.git_hashes[repo].append((commit_hash, new_tree))
448 450
449 def check_port_is_free(self, port): 451 def check_port_is_free(self, port):
450 sock = socket.socket() 452 sock = socket.socket()
451 try: 453 try:
452 sock.connect((self.host, port)) 454 sock.connect((self.host, port))
453 # It worked, throw. 455 # It worked, throw.
454 assert False, '%d shouldn\'t be bound' % port 456 assert False, '%d shouldn\'t be bound' % port
455 except EnvironmentError: 457 except (socket.error, EnvironmentError):
456 pass 458 pass
457 finally: 459 finally:
458 sock.close() 460 sock.close()
459 461
460 def populateSvn(self): 462 def populateSvn(self):
461 raise NotImplementedError() 463 raise NotImplementedError()
462 464
463 def populateGit(self): 465 def populateGit(self):
464 raise NotImplementedError() 466 raise NotImplementedError()
465 467
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 fake.set_up_git() 777 fake.set_up_git()
776 print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.') 778 print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.')
777 sys.stdin.readline() 779 sys.stdin.readline()
778 except KeyboardInterrupt: 780 except KeyboardInterrupt:
779 trial_dir.TrialDir.SHOULD_LEAK.leak = True 781 trial_dir.TrialDir.SHOULD_LEAK.leak = True
780 return 0 782 return 0
781 783
782 784
783 if __name__ == '__main__': 785 if __name__ == '__main__':
784 sys.exit(main(sys.argv)) 786 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « subprocess2.py ('k') | tests/filesystem_mock.py » ('j') | tests/owners_unittest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698