Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 errno | 9 import errno |
| 10 import logging | 10 import logging |
| 11 import os | 11 import os |
| 12 import pprint | 12 import pprint |
| 13 import re | 13 import re |
| 14 import stat | 14 import stat |
| 15 import subprocess | 15 import subprocess |
| 16 import sys | 16 import sys |
| 17 import time | 17 import time |
| 18 import unittest | 18 import unittest |
| 19 | 19 |
| 20 | 20 |
| 21 ## Utility functions | 21 ## Utility functions |
| 22 | 22 |
| 23 | 23 |
| 24 def addKill(): | 24 def addKill(): |
| 25 """Add kill() method to subprocess.Popen for python <2.6""" | 25 """Add kill() method to subprocess.Popen for python <2.6""" |
| 26 if getattr(subprocess.Popen, 'kill', None): | 26 if getattr(subprocess.Popen, 'kill', None): |
| 27 return | 27 return |
| 28 if sys.platform.startswith('win'): | 28 if sys.platform == 'win32': |
| 29 def kill_win(process): | 29 def kill_win(process): |
| 30 import win32process | 30 import win32process |
| 31 return win32process.TerminateProcess(process._handle, -1) | 31 return win32process.TerminateProcess(process._handle, -1) |
| 32 subprocess.kill = kill_win | 32 subprocess.Popen.kill = kill_win |
| 33 else: | 33 else: |
| 34 def kill_nix(process): | 34 def kill_nix(process): |
| 35 import signal | 35 import signal |
| 36 return os.kill(process.pid, signal.SIGKILL) | 36 return os.kill(process.pid, signal.SIGKILL) |
| 37 subprocess.kill = kill_nix | 37 subprocess.Popen.kill = kill_nix |
| 38 | 38 |
| 39 | 39 |
| 40 def rmtree(*path): | 40 def rmtree(*path): |
| 41 """Recursively removes a directory, even if it's marked read-only. | 41 """Recursively removes a directory, even if it's marked read-only. |
| 42 | 42 |
| 43 Remove the directory located at *path, if it exists. | 43 Remove the directory located at *path, if it exists. |
| 44 | 44 |
| 45 shutil.rmtree() doesn't work on Windows if any of the files or directories | 45 shutil.rmtree() doesn't work on Windows if any of the files or directories |
| 46 are read-only, which svn repositories and some .svn files are. We need to | 46 are read-only, which svn repositories and some .svn files are. We need to |
| 47 be able to force the files to be writable (i.e., deletable) as we traverse | 47 be able to force the files to be writable (i.e., deletable) as we traverse |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 | 168 |
| 169 | 169 |
| 170 def commit_svn(repo): | 170 def commit_svn(repo): |
| 171 """Commits the changes and returns the new revision number.""" | 171 """Commits the changes and returns the new revision number.""" |
| 172 # Basic parsing. | 172 # Basic parsing. |
| 173 to_add = [] | 173 to_add = [] |
| 174 to_remove = [] | 174 to_remove = [] |
| 175 for item in Popen(['svn', 'status'], | 175 for item in Popen(['svn', 'status'], |
| 176 cwd=repo).communicate()[0].splitlines(False): | 176 cwd=repo).communicate()[0].splitlines(False): |
| 177 if item[0] == '?': | 177 if item[0] == '?': |
| 178 to_add.append(item[8:]) | 178 to_add.append(item[7:].strip()) |
|
Mandeep Singh Baines
2010/06/02 01:33:01
This seems fragile. How about:
item.split()[1]
T
| |
| 179 elif item[0] == '!': | 179 elif item[0] == '!': |
| 180 to_remove.append(item[8:]) | 180 to_remove.append(item[7:].strip()) |
| 181 if to_add: | 181 if to_add: |
| 182 check_call(['svn', 'add', '--no-auto-props', '-q'] + to_add, cwd=repo) | 182 check_call(['svn', 'add', '--no-auto-props', '-q'] + to_add, cwd=repo) |
| 183 if to_remove: | 183 if to_remove: |
| 184 check_call(['svn', 'remove', '-q'] + to_remove, cwd=repo) | 184 check_call(['svn', 'remove', '-q'] + to_remove, cwd=repo) |
| 185 out = Popen(['svn', 'commit', repo, '-m', 'foo', '--non-interactive', | 185 proc = Popen(['svn', 'commit', repo, '-m', 'foo', '--non-interactive', |
| 186 '--no-auth-cache', '--username', 'user1', '--password', 'foo'], | 186 '--no-auth-cache', '--username', 'user1', '--password', 'foo'], |
| 187 cwd=repo).communicate()[0] | 187 cwd=repo) |
| 188 rev = re.search(r'revision (\d+).', out).group(1) | 188 out, err = proc.communicate() |
| 189 match = re.search(r'revision (\d+).', out) | |
| 190 if not match: | |
| 191 raise Exception('Commit failed', out, err, proc.returncode) | |
| 192 rev = match.group(1) | |
| 189 st = Popen(['svn', 'status'], cwd=repo).communicate()[0] | 193 st = Popen(['svn', 'status'], cwd=repo).communicate()[0] |
| 190 assert len(st) == 0, st | 194 assert len(st) == 0, st |
| 191 logging.debug('At revision %s' % rev) | 195 logging.debug('At revision %s' % rev) |
| 192 return rev | 196 return rev |
| 193 | 197 |
| 194 | 198 |
| 195 def commit_git(repo): | 199 def commit_git(repo): |
| 196 """Commits the changes and returns the new hash.""" | 200 """Commits the changes and returns the new hash.""" |
| 197 check_call(['git', 'add', '-A', '-f'], cwd=repo) | 201 check_call(['git', 'add', '-A', '-f'], cwd=repo) |
| 198 check_call(['git', 'commit', '-q', '--message', 'foo'], cwd=repo) | 202 check_call(['git', 'commit', '-q', '--message', 'foo'], cwd=repo) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 'password-db = passwd\n') | 312 'password-db = passwd\n') |
| 309 write(join(root, 'conf', 'passwd'), | 313 write(join(root, 'conf', 'passwd'), |
| 310 '[users]\n' | 314 '[users]\n' |
| 311 'user1 = foo\n' | 315 'user1 = foo\n' |
| 312 'user2 = bar\n') | 316 'user2 = bar\n') |
| 313 | 317 |
| 314 # Start the daemon. | 318 # Start the daemon. |
| 315 cmd = ['svnserve', '-d', '--foreground', '-r', self.repos_dir] | 319 cmd = ['svnserve', '-d', '--foreground', '-r', self.repos_dir] |
| 316 if self.HOST == '127.0.0.1': | 320 if self.HOST == '127.0.0.1': |
| 317 cmd.append('--listen-host=127.0.0.1') | 321 cmd.append('--listen-host=127.0.0.1') |
| 318 logging.debug(cmd) | |
| 319 self.svnserve = Popen(cmd, cwd=root) | 322 self.svnserve = Popen(cmd, cwd=root) |
| 320 self.populateSvn() | 323 self.populateSvn() |
| 321 | 324 |
| 322 def populateSvn(self): | 325 def populateSvn(self): |
| 323 """Creates a few revisions of changes including DEPS files.""" | 326 """Creates a few revisions of changes including DEPS files.""" |
| 324 # Repos | 327 # Repos |
| 325 check_call(['svn', 'checkout', 'svn://127.0.0.1/svn', self.svn_root, '-q', | 328 check_call(['svn', 'checkout', 'svn://127.0.0.1/svn', self.svn_root, '-q', |
| 326 '--non-interactive', '--no-auth-cache', | 329 '--non-interactive', '--no-auth-cache', |
| 327 '--username', 'user1', '--password', 'foo']) | 330 '--username', 'user1', '--password', 'foo']) |
| 328 assert os.path.isdir(join(self.svn_root, '.svn')) | 331 assert os.path.isdir(join(self.svn_root, '.svn')) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 fake.setUp() | 580 fake.setUp() |
| 578 print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.') | 581 print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.') |
| 579 sys.stdin.readline() | 582 sys.stdin.readline() |
| 580 except KeyboardInterrupt: | 583 except KeyboardInterrupt: |
| 581 fake.SHOULD_LEAK = True | 584 fake.SHOULD_LEAK = True |
| 582 return 0 | 585 return 0 |
| 583 | 586 |
| 584 | 587 |
| 585 if __name__ == '__main__': | 588 if __name__ == '__main__': |
| 586 sys.exit(main(sys.argv)) | 589 sys.exit(main(sys.argv)) |
| OLD | NEW |