| OLD | NEW |
| 1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """SCM-specific utility classes.""" | 5 """SCM-specific utility classes.""" |
| 6 | 6 |
| 7 import cStringIO | 7 import cStringIO |
| 8 import glob | 8 import glob |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 if not m: | 114 if not m: |
| 115 raise Exception("status currently unsupported: %s" % statusline) | 115 raise Exception("status currently unsupported: %s" % statusline) |
| 116 results.append(('%s ' % m.group(1), m.group(2))) | 116 results.append(('%s ' % m.group(1), m.group(2))) |
| 117 return results | 117 return results |
| 118 | 118 |
| 119 @staticmethod | 119 @staticmethod |
| 120 def RunAndFilterOutput(args, | 120 def RunAndFilterOutput(args, |
| 121 in_directory, | 121 in_directory, |
| 122 print_messages, | 122 print_messages, |
| 123 print_stdout, | 123 print_stdout, |
| 124 filter_fn): | 124 filter_fn, |
| 125 stdout=None): |
| 125 """Runs a command, optionally outputting to stdout. | 126 """Runs a command, optionally outputting to stdout. |
| 126 | 127 |
| 127 stdout is passed line-by-line to the given filter_fn function. If | 128 stdout is passed line-by-line to the given filter_fn function. If |
| 128 print_stdout is true, it is also printed to sys.stdout as in Run. | 129 print_stdout is true, it is also printed to sys.stdout as in Run. |
| 129 | 130 |
| 130 Args: | 131 Args: |
| 131 args: A sequence of command line parameters to be passed. | 132 args: A sequence of command line parameters to be passed. |
| 132 in_directory: The directory where git is to be run. | 133 in_directory: The directory where git is to be run. |
| 133 print_messages: Whether to print status messages to stdout about | 134 print_messages: Whether to print status messages to stdout about |
| 134 which commands are being run. | 135 which commands are being run. |
| 135 print_stdout: Whether to forward program's output to stdout. | 136 print_stdout: Whether to forward program's output to stdout. |
| 136 filter_fn: A function taking one argument (a string) which will be | 137 filter_fn: A function taking one argument (a string) which will be |
| 137 passed each line (with the ending newline character removed) of | 138 passed each line (with the ending newline character removed) of |
| 138 program's output for filtering. | 139 program's output for filtering. |
| 139 | 140 |
| 140 Raises: | 141 Raises: |
| 141 gclient_utils.Error: An error occurred while running the command. | 142 gclient_utils.Error: An error occurred while running the command. |
| 142 """ | 143 """ |
| 143 command = [GIT.COMMAND] | 144 command = [GIT.COMMAND] |
| 144 command.extend(args) | 145 command.extend(args) |
| 145 gclient_utils.SubprocessCallAndFilter(command, | 146 gclient_utils.SubprocessCallAndFilter(command, |
| 146 in_directory, | 147 in_directory, |
| 147 print_messages, | 148 print_messages, |
| 148 print_stdout, | 149 print_stdout, |
| 149 filter_fn=filter_fn) | 150 filter_fn=filter_fn, |
| 151 stdout=stdout) |
| 150 | 152 |
| 151 @staticmethod | 153 @staticmethod |
| 152 def GetEmail(repo_root): | 154 def GetEmail(repo_root): |
| 153 """Retrieves the user email address if known.""" | 155 """Retrieves the user email address if known.""" |
| 154 # We could want to look at the svn cred when it has a svn remote but it | 156 # We could want to look at the svn cred when it has a svn remote but it |
| 155 # should be fine for now, users should simply configure their git settings. | 157 # should be fine for now, users should simply configure their git settings. |
| 156 return GIT.Capture(['config', 'user.email'], | 158 return GIT.Capture(['config', 'user.email'], |
| 157 repo_root, error_ok=True)[0].strip() | 159 repo_root, error_ok=True)[0].strip() |
| 158 | 160 |
| 159 @staticmethod | 161 @staticmethod |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 """ | 373 """ |
| 372 c = [SVN.COMMAND] | 374 c = [SVN.COMMAND] |
| 373 c.extend(args) | 375 c.extend(args) |
| 374 stderr = None | 376 stderr = None |
| 375 if not print_error: | 377 if not print_error: |
| 376 stderr = subprocess.PIPE | 378 stderr = subprocess.PIPE |
| 377 return gclient_utils.Popen(c, cwd=in_directory, stdout=subprocess.PIPE, | 379 return gclient_utils.Popen(c, cwd=in_directory, stdout=subprocess.PIPE, |
| 378 stderr=stderr).communicate()[0] | 380 stderr=stderr).communicate()[0] |
| 379 | 381 |
| 380 @staticmethod | 382 @staticmethod |
| 381 def RunAndGetFileList(verbose, args, in_directory, file_list): | 383 def RunAndGetFileList(verbose, args, in_directory, file_list, stdout=None): |
| 382 """Runs svn checkout, update, or status, output to stdout. | 384 """Runs svn checkout, update, or status, output to stdout. |
| 383 | 385 |
| 384 The first item in args must be either "checkout", "update", or "status". | 386 The first item in args must be either "checkout", "update", or "status". |
| 385 | 387 |
| 386 svn's stdout is parsed to collect a list of files checked out or updated. | 388 svn's stdout is parsed to collect a list of files checked out or updated. |
| 387 These files are appended to file_list. svn's stdout is also printed to | 389 These files are appended to file_list. svn's stdout is also printed to |
| 388 sys.stdout as in Run. | 390 sys.stdout as in Run. |
| 389 | 391 |
| 390 Args: | 392 Args: |
| 391 verbose: If True, uses verbose output | 393 verbose: If True, uses verbose output |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 if match: | 431 if match: |
| 430 file_list.append(match.group(1)) | 432 file_list.append(match.group(1)) |
| 431 if line.startswith('svn: '): | 433 if line.startswith('svn: '): |
| 432 failure.append(line) | 434 failure.append(line) |
| 433 | 435 |
| 434 try: | 436 try: |
| 435 SVN.RunAndFilterOutput(args, | 437 SVN.RunAndFilterOutput(args, |
| 436 in_directory, | 438 in_directory, |
| 437 verbose, | 439 verbose, |
| 438 True, | 440 True, |
| 439 CaptureMatchingLines) | 441 CaptureMatchingLines, |
| 442 stdout=stdout) |
| 440 except gclient_utils.Error: | 443 except gclient_utils.Error: |
| 441 def IsKnownFailure(): | 444 def IsKnownFailure(): |
| 442 for x in failure: | 445 for x in failure: |
| 443 if (x.startswith('svn: OPTIONS of') or | 446 if (x.startswith('svn: OPTIONS of') or |
| 444 x.startswith('svn: PROPFIND of') or | 447 x.startswith('svn: PROPFIND of') or |
| 445 x.startswith('svn: REPORT of') or | 448 x.startswith('svn: REPORT of') or |
| 446 x.startswith('svn: Unknown hostname') or | 449 x.startswith('svn: Unknown hostname') or |
| 447 x.startswith('svn: Server sent unexpected return value')): | 450 x.startswith('svn: Server sent unexpected return value')): |
| 448 return True | 451 return True |
| 449 return False | 452 return False |
| (...skipping 25 matching lines...) Expand all Loading... |
| 475 print "Sleeping 15 seconds and retrying...." | 478 print "Sleeping 15 seconds and retrying...." |
| 476 time.sleep(15) | 479 time.sleep(15) |
| 477 continue | 480 continue |
| 478 break | 481 break |
| 479 | 482 |
| 480 @staticmethod | 483 @staticmethod |
| 481 def RunAndFilterOutput(args, | 484 def RunAndFilterOutput(args, |
| 482 in_directory, | 485 in_directory, |
| 483 print_messages, | 486 print_messages, |
| 484 print_stdout, | 487 print_stdout, |
| 485 filter_fn): | 488 filter_fn, |
| 489 stdout=None): |
| 486 """Runs a command, optionally outputting to stdout. | 490 """Runs a command, optionally outputting to stdout. |
| 487 | 491 |
| 488 stdout is passed line-by-line to the given filter_fn function. If | 492 stdout is passed line-by-line to the given filter_fn function. If |
| 489 print_stdout is true, it is also printed to sys.stdout as in Run. | 493 print_stdout is true, it is also printed to sys.stdout as in Run. |
| 490 | 494 |
| 491 Args: | 495 Args: |
| 492 args: A sequence of command line parameters to be passed. | 496 args: A sequence of command line parameters to be passed. |
| 493 in_directory: The directory where svn is to be run. | 497 in_directory: The directory where svn is to be run. |
| 494 print_messages: Whether to print status messages to stdout about | 498 print_messages: Whether to print status messages to stdout about |
| 495 which commands are being run. | 499 which commands are being run. |
| 496 print_stdout: Whether to forward program's output to stdout. | 500 print_stdout: Whether to forward program's output to stdout. |
| 497 filter_fn: A function taking one argument (a string) which will be | 501 filter_fn: A function taking one argument (a string) which will be |
| 498 passed each line (with the ending newline character removed) of | 502 passed each line (with the ending newline character removed) of |
| 499 program's output for filtering. | 503 program's output for filtering. |
| 500 | 504 |
| 501 Raises: | 505 Raises: |
| 502 gclient_utils.Error: An error occurred while running the command. | 506 gclient_utils.Error: An error occurred while running the command. |
| 503 """ | 507 """ |
| 504 command = [SVN.COMMAND] | 508 command = [SVN.COMMAND] |
| 505 command.extend(args) | 509 command.extend(args) |
| 506 gclient_utils.SubprocessCallAndFilter(command, | 510 gclient_utils.SubprocessCallAndFilter(command, |
| 507 in_directory, | 511 in_directory, |
| 508 print_messages, | 512 print_messages, |
| 509 print_stdout, | 513 print_stdout, |
| 510 filter_fn=filter_fn) | 514 filter_fn=filter_fn, |
| 515 stdout=stdout) |
| 511 | 516 |
| 512 @staticmethod | 517 @staticmethod |
| 513 def CaptureInfo(relpath, in_directory=None, print_error=True): | 518 def CaptureInfo(relpath, in_directory=None, print_error=True): |
| 514 """Returns a dictionary from the svn info output for the given file. | 519 """Returns a dictionary from the svn info output for the given file. |
| 515 | 520 |
| 516 Args: | 521 Args: |
| 517 relpath: The directory where the working copy resides relative to | 522 relpath: The directory where the working copy resides relative to |
| 518 the directory given by in_directory. | 523 the directory given by in_directory. |
| 519 in_directory: The directory where svn is to be run. | 524 in_directory: The directory where svn is to be run. |
| 520 """ | 525 """ |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 if not SVN.current_version: | 934 if not SVN.current_version: |
| 930 SVN.current_version = SVN.Capture(['--version']).split()[2] | 935 SVN.current_version = SVN.Capture(['--version']).split()[2] |
| 931 current_version_list = map(only_int, SVN.current_version.split('.')) | 936 current_version_list = map(only_int, SVN.current_version.split('.')) |
| 932 for min_ver in map(int, min_version.split('.')): | 937 for min_ver in map(int, min_version.split('.')): |
| 933 ver = current_version_list.pop(0) | 938 ver = current_version_list.pop(0) |
| 934 if ver < min_ver: | 939 if ver < min_ver: |
| 935 return (False, SVN.current_version) | 940 return (False, SVN.current_version) |
| 936 elif ver > min_ver: | 941 elif ver > min_ver: |
| 937 return (True, SVN.current_version) | 942 return (True, SVN.current_version) |
| 938 return (True, SVN.current_version) | 943 return (True, SVN.current_version) |
| OLD | NEW |