OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright 2008 Google Inc. All Rights Reserved. | 3 # Copyright 2008 Google Inc. All Rights Reserved. |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 484 |
485 Raises: | 485 Raises: |
486 Error: An error occurred while running the svn command. | 486 Error: An error occurred while running the svn command. |
487 """ | 487 """ |
488 c = [SVN_COMMAND] | 488 c = [SVN_COMMAND] |
489 c.extend(args) | 489 c.extend(args) |
490 | 490 |
491 SubprocessCall(c, in_directory) | 491 SubprocessCall(c, in_directory) |
492 | 492 |
493 | 493 |
494 def CaptureSVN(args, in_directory): | 494 def CaptureSVN(args, in_directory=None, print_error=True): |
495 """Runs svn, capturing output sent to stdout as a string. | 495 """Runs svn, capturing output sent to stdout as a string. |
496 | 496 |
497 Args: | 497 Args: |
498 args: A sequence of command line parameters to be passed to svn. | 498 args: A sequence of command line parameters to be passed to svn. |
499 in_directory: The directory where svn is to be run. | 499 in_directory: The directory where svn is to be run. |
500 | 500 |
501 Returns: | 501 Returns: |
502 The output sent to stdout as a string. | 502 The output sent to stdout as a string. |
503 """ | 503 """ |
504 c = [SVN_COMMAND] | 504 c = [SVN_COMMAND] |
505 c.extend(args) | 505 c.extend(args) |
506 | 506 |
507 # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for | 507 # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for |
508 # the svn.exe executable, but shell=True makes subprocess on Linux fail | 508 # the svn.exe executable, but shell=True makes subprocess on Linux fail |
509 # when it's called with a list because it only tries to execute the | 509 # when it's called with a list because it only tries to execute the |
510 # first string ("svn"). | 510 # first string ("svn"). |
| 511 stderr = None |
| 512 if print_error: |
| 513 stderr = subprocess.PIPE |
511 return subprocess.Popen(c, | 514 return subprocess.Popen(c, |
512 cwd=in_directory, | 515 cwd=in_directory, |
513 shell=(sys.platform == 'win32'), | 516 shell=(sys.platform == 'win32'), |
514 stdout=subprocess.PIPE).communicate()[0] | 517 stdout=subprocess.PIPE, |
| 518 stderr=stderr).communicate()[0] |
515 | 519 |
516 | 520 |
517 def RunSVNAndGetFileList(args, in_directory, file_list): | 521 def RunSVNAndGetFileList(args, in_directory, file_list): |
518 """Runs svn checkout, update, or status, output to stdout. | 522 """Runs svn checkout, update, or status, output to stdout. |
519 | 523 |
520 The first item in args must be either "checkout", "update", or "status". | 524 The first item in args must be either "checkout", "update", or "status". |
521 | 525 |
522 svn's stdout is parsed to collect a list of files checked out or updated. | 526 svn's stdout is parsed to collect a list of files checked out or updated. |
523 These files are appended to file_list. svn's stdout is also printed to | 527 These files are appended to file_list. svn's stdout is also printed to |
524 sys.stdout as in RunSVN. | 528 sys.stdout as in RunSVN. |
(...skipping 28 matching lines...) Expand all Loading... |
553 'status': status_pattern, | 557 'status': status_pattern, |
554 'update': update_pattern, | 558 'update': update_pattern, |
555 }[args[0]] | 559 }[args[0]] |
556 | 560 |
557 SubprocessCallAndCapture(command, | 561 SubprocessCallAndCapture(command, |
558 in_directory, | 562 in_directory, |
559 pattern=pattern, | 563 pattern=pattern, |
560 capture_list=file_list) | 564 capture_list=file_list) |
561 | 565 |
562 | 566 |
563 def CaptureSVNInfo(relpath, in_directory=None): | 567 def CaptureSVNInfo(relpath, in_directory=None, print_error=True): |
564 """Returns a dictionary from the svn info output for the given file. | 568 """Returns a dictionary from the svn info output for the given file. |
565 | 569 |
566 Args: | 570 Args: |
567 relpath: The directory where the working copy resides relative to | 571 relpath: The directory where the working copy resides relative to |
568 the directory given by in_directory. | 572 the directory given by in_directory. |
569 in_directory: The directory where svn is to be run. | 573 in_directory: The directory where svn is to be run. |
570 """ | 574 """ |
571 output = CaptureSVN(["info", "--xml", relpath], in_directory) | 575 output = CaptureSVN(["info", "--xml", relpath], in_directory, print_error) |
572 dom = ParseXML(output) | 576 dom = ParseXML(output) |
573 result = {} | 577 result = {} |
574 if dom: | 578 if dom: |
575 def C(item, f): | 579 def C(item, f): |
576 if item is not None: return f(item) | 580 if item is not None: return f(item) |
577 # /info/entry/ | 581 # /info/entry/ |
578 # url | 582 # url |
579 # reposityory/(root|uuid) | 583 # reposityory/(root|uuid) |
580 # wc-info/(schedule|depth) | 584 # wc-info/(schedule|depth) |
581 # commit/(author|date) | 585 # commit/(author|date) |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 | 1713 |
1710 if "__main__" == __name__: | 1714 if "__main__" == __name__: |
1711 try: | 1715 try: |
1712 result = Main(sys.argv) | 1716 result = Main(sys.argv) |
1713 except Error, e: | 1717 except Error, e: |
1714 print >> sys.stderr, "Error: %s" % str(e) | 1718 print >> sys.stderr, "Error: %s" % str(e) |
1715 result = 1 | 1719 result = 1 |
1716 sys.exit(result) | 1720 sys.exit(result) |
1717 | 1721 |
1718 # vim: ts=2:sw=2:tw=80:et: | 1722 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |