| OLD | NEW |
| 1 # coding=utf8 | 1 # coding=utf8 |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 """Manages a project checkout. | 5 """Manages a project checkout. |
| 6 | 6 |
| 7 Includes support for svn, git-svn and git. | 7 Includes support for svn, git-svn and git. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import ConfigParser | 10 import ConfigParser |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if os.path.isfile(filepath): | 197 if os.path.isfile(filepath): |
| 198 raise PatchApplicationFailed( | 198 raise PatchApplicationFailed( |
| 199 p, 'File exist but was about to be overwriten') | 199 p, 'File exist but was about to be overwriten') |
| 200 shutil.copy2( | 200 shutil.copy2( |
| 201 os.path.join(self.project_path, p.source_filename), filepath) | 201 os.path.join(self.project_path, p.source_filename), filepath) |
| 202 stdout.append('Copied %s -> %s' % (p.source_filename, p.filename)) | 202 stdout.append('Copied %s -> %s' % (p.source_filename, p.filename)) |
| 203 if p.diff_hunks: | 203 if p.diff_hunks: |
| 204 cmd = ['patch', '-u', '--binary', '-p%s' % p.patchlevel] | 204 cmd = ['patch', '-u', '--binary', '-p%s' % p.patchlevel] |
| 205 if verbose: | 205 if verbose: |
| 206 cmd.append('--verbose') | 206 cmd.append('--verbose') |
| 207 stdout.append( | 207 env = os.environ.copy() |
| 208 subprocess2.check_output( | 208 env['TMPDIR'] = tempfile.mkdtemp(prefix='crpatch') |
| 209 cmd, | 209 try: |
| 210 stdin=p.get(False), | 210 stdout.append( |
| 211 stderr=subprocess2.STDOUT, | 211 subprocess2.check_output( |
| 212 cwd=self.project_path, | 212 cmd, |
| 213 timeout=GLOBAL_TIMEOUT)) | 213 stdin=p.get(False), |
| 214 stderr=subprocess2.STDOUT, |
| 215 cwd=self.project_path, |
| 216 timeout=GLOBAL_TIMEOUT, |
| 217 env=env)) |
| 218 finally: |
| 219 shutil.rmtree(env['TMPDIR']) |
| 214 elif p.is_new and not os.path.exists(filepath): | 220 elif p.is_new and not os.path.exists(filepath): |
| 215 # There is only a header. Just create the file. | 221 # There is only a header. Just create the file. |
| 216 open(filepath, 'w').close() | 222 open(filepath, 'w').close() |
| 217 stdout.append('Created an empty file.') | 223 stdout.append('Created an empty file.') |
| 218 for post in post_processors: | 224 for post in post_processors: |
| 219 post(self, p) | 225 post(self, p) |
| 220 if verbose: | 226 if verbose: |
| 221 print p.filename | 227 print p.filename |
| 222 print align_stdout(stdout) | 228 print align_stdout(stdout) |
| 223 except OSError, e: | 229 except OSError, e: |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 ['copy', p.source_filename, p.filename])) | 399 ['copy', p.source_filename, p.filename])) |
| 394 stdout.append('Copied %s -> %s' % (p.source_filename, p.filename)) | 400 stdout.append('Copied %s -> %s' % (p.source_filename, p.filename)) |
| 395 if p.diff_hunks: | 401 if p.diff_hunks: |
| 396 cmd = [ | 402 cmd = [ |
| 397 'patch', | 403 'patch', |
| 398 '-p%s' % p.patchlevel, | 404 '-p%s' % p.patchlevel, |
| 399 '--forward', | 405 '--forward', |
| 400 '--force', | 406 '--force', |
| 401 '--no-backup-if-mismatch', | 407 '--no-backup-if-mismatch', |
| 402 ] | 408 ] |
| 403 stdout.append( | 409 env = os.environ.copy() |
| 404 subprocess2.check_output( | 410 env['TMPDIR'] = tempfile.mkdtemp(prefix='crpatch') |
| 405 cmd, | 411 try: |
| 406 stdin=p.get(False), | 412 stdout.append( |
| 407 cwd=self.project_path, | 413 subprocess2.check_output( |
| 408 timeout=GLOBAL_TIMEOUT)) | 414 cmd, |
| 415 stdin=p.get(False), |
| 416 cwd=self.project_path, |
| 417 timeout=GLOBAL_TIMEOUT, |
| 418 env=env)) |
| 419 finally: |
| 420 shutil.rmtree(env['TMPDIR']) |
| 421 |
| 409 elif p.is_new and not os.path.exists(filepath): | 422 elif p.is_new and not os.path.exists(filepath): |
| 410 # There is only a header. Just create the file if it doesn't | 423 # There is only a header. Just create the file if it doesn't |
| 411 # exist. | 424 # exist. |
| 412 open(filepath, 'w').close() | 425 open(filepath, 'w').close() |
| 413 stdout.append('Created an empty file.') | 426 stdout.append('Created an empty file.') |
| 414 if p.is_new and not p.source_filename: | 427 if p.is_new and not p.source_filename: |
| 415 # Do not run it if p.source_filename is defined, since svn copy was | 428 # Do not run it if p.source_filename is defined, since svn copy was |
| 416 # using above. | 429 # using above. |
| 417 stdout.append( | 430 stdout.append( |
| 418 self._check_output_svn( | 431 self._check_output_svn( |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 def revisions(self, rev1, rev2): | 764 def revisions(self, rev1, rev2): |
| 752 return self.checkout.revisions(rev1, rev2) | 765 return self.checkout.revisions(rev1, rev2) |
| 753 | 766 |
| 754 @property | 767 @property |
| 755 def project_name(self): | 768 def project_name(self): |
| 756 return self.checkout.project_name | 769 return self.checkout.project_name |
| 757 | 770 |
| 758 @property | 771 @property |
| 759 def project_path(self): | 772 def project_path(self): |
| 760 return self.checkout.project_path | 773 return self.checkout.project_path |
| OLD | NEW |