OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 """Enables directory-specific presubmit checks to run at upload and/or commit. | 6 """Enables directory-specific presubmit checks to run at upload and/or commit. |
7 """ | 7 """ |
8 | 8 |
9 __version__ = '1.3.1' | 9 __version__ = '1.3.1' |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 output_stream: Where to write | 84 output_stream: Where to write |
85 | 85 |
86 Returns: | 86 Returns: |
87 True if execution may continue, False otherwise. | 87 True if execution may continue, False otherwise. |
88 """ | 88 """ |
89 output_stream.write(self._message) | 89 output_stream.write(self._message) |
90 output_stream.write('\n') | 90 output_stream.write('\n') |
91 for item in self._items: | 91 for item in self._items: |
92 output_stream.write(' %s\n' % item) | 92 output_stream.write(' %s\n' % item) |
93 if self._long_text: | 93 if self._long_text: |
94 output_stream.write('\n***************\n%s\n***************\n\n' % | 94 output_stream.write('\n***************\n%s\n***************\n' % |
95 self._long_text) | 95 self._long_text) |
96 | 96 |
97 if self.ShouldPrompt() and may_prompt: | 97 if self.ShouldPrompt() and may_prompt: |
98 output_stream.write('Are you sure you want to continue? (y/N): ') | 98 output_stream.write('Are you sure you want to continue? (y/N): ') |
99 response = input_stream.readline() | 99 response = input_stream.readline() |
100 if response.strip().lower() != 'y': | 100 if response.strip().lower() != 'y': |
101 return False | 101 return False |
102 | 102 |
103 return not self.IsFatal() | 103 return not self.IsFatal() |
104 | 104 |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 result = () # no error since the script doesn't care about current event. | 687 result = () # no error since the script doesn't care about current event. |
688 | 688 |
689 return result | 689 return result |
690 | 690 |
691 | 691 |
692 def DoPresubmitChecks(change_info, | 692 def DoPresubmitChecks(change_info, |
693 committing, | 693 committing, |
694 verbose, | 694 verbose, |
695 output_stream, | 695 output_stream, |
696 input_stream, | 696 input_stream, |
697 default_presubmit): | 697 default_presubmit, |
| 698 may_prompt): |
698 """Runs all presubmit checks that apply to the files in the change. | 699 """Runs all presubmit checks that apply to the files in the change. |
699 | 700 |
700 This finds all PRESUBMIT.py files in directories enclosing the files in the | 701 This finds all PRESUBMIT.py files in directories enclosing the files in the |
701 change (up to the repository root) and calls the relevant entrypoint function | 702 change (up to the repository root) and calls the relevant entrypoint function |
702 depending on whether the change is being committed or uploaded. | 703 depending on whether the change is being committed or uploaded. |
703 | 704 |
704 Prints errors, warnings and notifications. Prompts the user for warnings | 705 Prints errors, warnings and notifications. Prompts the user for warnings |
705 when needed. | 706 when needed. |
706 | 707 |
707 Args: | 708 Args: |
708 change_info: The ChangeInfo object for the change. | 709 change_info: The ChangeInfo object for the change. |
709 committing: True if 'gcl commit' is running, False if 'gcl upload' is. | 710 committing: True if 'gcl commit' is running, False if 'gcl upload' is. |
710 verbose: Prints debug info. | 711 verbose: Prints debug info. |
711 output_stream: A stream to write output from presubmit tests to. | 712 output_stream: A stream to write output from presubmit tests to. |
712 input_stream: A stream to read input from the user. | 713 input_stream: A stream to read input from the user. |
713 default_presubmit: A default presubmit script to execute in any case. | 714 default_presubmit: A default presubmit script to execute in any case. |
| 715 may_prompt: Enable (y/n) questions on warning or error. |
714 | 716 |
715 Return: | 717 Return: |
716 True if execution can continue, False if not. | 718 True if execution can continue, False if not. |
717 """ | 719 """ |
718 checkout_root = gcl.GetRepositoryRoot() | 720 checkout_root = gcl.GetRepositoryRoot() |
719 presubmit_files = ListRelevantPresubmitFiles(change_info.FileList(), | 721 presubmit_files = ListRelevantPresubmitFiles(change_info.FileList(), |
720 checkout_root) | 722 checkout_root) |
721 if not presubmit_files and verbose: | 723 if not presubmit_files and verbose: |
722 output_stream.write("Warning, no presubmit.py found.\n") | 724 output_stream.write("Warning, no presubmit.py found.\n") |
723 results = [] | 725 results = [] |
(...skipping 20 matching lines...) Expand all Loading... |
744 elif result.ShouldPrompt(): | 746 elif result.ShouldPrompt(): |
745 warnings.append(result) | 747 warnings.append(result) |
746 else: | 748 else: |
747 errors.append(result) | 749 errors.append(result) |
748 | 750 |
749 error_count = 0 | 751 error_count = 0 |
750 for name, items in (('Messages', notifications), | 752 for name, items in (('Messages', notifications), |
751 ('Warnings', warnings), | 753 ('Warnings', warnings), |
752 ('ERRORS', errors)): | 754 ('ERRORS', errors)): |
753 if items: | 755 if items: |
754 output_stream.write('\n** Presubmit %s **\n\n' % name) | 756 output_stream.write('** Presubmit %s **\n' % name) |
755 for item in items: | 757 for item in items: |
756 if not item._Handle(output_stream, input_stream, | 758 if not item._Handle(output_stream, input_stream, |
757 may_prompt=False): | 759 may_prompt=False): |
758 error_count += 1 | 760 error_count += 1 |
759 output_stream.write('\n') | 761 output_stream.write('\n') |
760 if not errors and warnings: | 762 if not errors and warnings: |
761 output_stream.write( | 763 output_stream.write( |
762 'There were presubmit warnings. Sure you want to continue? (y/N): ') | 764 'There were presubmit warnings. Sure you want to continue? (y/N): ') |
763 response = input_stream.readline() | 765 response = input_stream.readline() |
764 if response.strip().lower() != 'y': | 766 if response.strip().lower() != 'y': |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 help="Verbose output") | 800 help="Verbose output") |
799 options, args = parser.parse_args(argv[1:]) | 801 options, args = parser.parse_args(argv[1:]) |
800 files = ParseFiles(args, options.recursive) | 802 files = ParseFiles(args, options.recursive) |
801 if options.verbose: | 803 if options.verbose: |
802 print "Found %d files." % len(files) | 804 print "Found %d files." % len(files) |
803 return not DoPresubmitChecks(gcl.ChangeInfo('No name', 0, 0, '', files), | 805 return not DoPresubmitChecks(gcl.ChangeInfo('No name', 0, 0, '', files), |
804 options.commit, | 806 options.commit, |
805 options.verbose, | 807 options.verbose, |
806 sys.stdout, | 808 sys.stdout, |
807 sys.stdin, | 809 sys.stdin, |
808 default_presubmit=None) | 810 None, |
| 811 False) |
809 | 812 |
810 | 813 |
811 if __name__ == '__main__': | 814 if __name__ == '__main__': |
812 sys.exit(Main(sys.argv)) | 815 sys.exit(Main(sys.argv)) |
OLD | NEW |