| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 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 | 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.8.0' | 9 __version__ = '1.8.0' |
| 10 | 10 |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 # Matches key/value (or "tag") lines in changelist descriptions. | 787 # Matches key/value (or "tag") lines in changelist descriptions. |
| 788 TAG_LINE_RE = re.compile( | 788 TAG_LINE_RE = re.compile( |
| 789 '^[ \t]*(?P<key>[A-Z][A-Z_0-9]*)[ \t]*=[ \t]*(?P<value>.*?)[ \t]*$') | 789 '^[ \t]*(?P<key>[A-Z][A-Z_0-9]*)[ \t]*=[ \t]*(?P<value>.*?)[ \t]*$') |
| 790 scm = '' | 790 scm = '' |
| 791 | 791 |
| 792 def __init__( | 792 def __init__( |
| 793 self, name, description, local_root, files, issue, patchset, author): | 793 self, name, description, local_root, files, issue, patchset, author): |
| 794 if files is None: | 794 if files is None: |
| 795 files = [] | 795 files = [] |
| 796 self._name = name | 796 self._name = name |
| 797 self._full_description = description | |
| 798 # Convert root into an absolute path. | 797 # Convert root into an absolute path. |
| 799 self._local_root = os.path.abspath(local_root) | 798 self._local_root = os.path.abspath(local_root) |
| 800 self.issue = issue | 799 self.issue = issue |
| 801 self.patchset = patchset | 800 self.patchset = patchset |
| 802 self.author_email = author | 801 self.author_email = author |
| 803 | 802 |
| 804 # From the description text, build up a dictionary of key/value pairs | 803 self._full_description = '' |
| 805 # plus the description minus all key/value or "tag" lines. | |
| 806 description_without_tags = [] | |
| 807 self.tags = {} | 804 self.tags = {} |
| 808 for line in self._full_description.splitlines(): | 805 self._description_without_tags = '' |
| 809 m = self.TAG_LINE_RE.match(line) | 806 self.SetDescriptionText(description) |
| 810 if m: | |
| 811 self.tags[m.group('key')] = m.group('value') | |
| 812 else: | |
| 813 description_without_tags.append(line) | |
| 814 | |
| 815 # Change back to text and remove whitespace at end. | |
| 816 self._description_without_tags = ( | |
| 817 '\n'.join(description_without_tags).rstrip()) | |
| 818 | 807 |
| 819 assert all( | 808 assert all( |
| 820 (isinstance(f, (list, tuple)) and len(f) == 2) for f in files), files | 809 (isinstance(f, (list, tuple)) and len(f) == 2) for f in files), files |
| 821 | 810 |
| 822 diff_cache = self._AFFECTED_FILES.DIFF_CACHE() | 811 diff_cache = self._AFFECTED_FILES.DIFF_CACHE() |
| 823 self._affected_files = [ | 812 self._affected_files = [ |
| 824 self._AFFECTED_FILES(path, action.strip(), self._local_root, diff_cache) | 813 self._AFFECTED_FILES(path, action.strip(), self._local_root, diff_cache) |
| 825 for action, path in files | 814 for action, path in files |
| 826 ] | 815 ] |
| 827 | 816 |
| 828 def Name(self): | 817 def Name(self): |
| 829 """Returns the change name.""" | 818 """Returns the change name.""" |
| 830 return self._name | 819 return self._name |
| 831 | 820 |
| 832 def DescriptionText(self): | 821 def DescriptionText(self): |
| 833 """Returns the user-entered changelist description, minus tags. | 822 """Returns the user-entered changelist description, minus tags. |
| 834 | 823 |
| 835 Any line in the user-provided description starting with e.g. "FOO=" | 824 Any line in the user-provided description starting with e.g. "FOO=" |
| 836 (whitespace permitted before and around) is considered a tag line. Such | 825 (whitespace permitted before and around) is considered a tag line. Such |
| 837 lines are stripped out of the description this function returns. | 826 lines are stripped out of the description this function returns. |
| 838 """ | 827 """ |
| 839 return self._description_without_tags | 828 return self._description_without_tags |
| 840 | 829 |
| 841 def FullDescriptionText(self): | 830 def FullDescriptionText(self): |
| 842 """Returns the complete changelist description including tags.""" | 831 """Returns the complete changelist description including tags.""" |
| 843 return self._full_description | 832 return self._full_description |
| 844 | 833 |
| 834 def SetDescriptionText(self, description): |
| 835 """Sets the full description text (including tags) to |description|. |
| 836 |
| 837 Also updates the list of tags.""" |
| 838 self._full_description = description |
| 839 |
| 840 # From the description text, build up a dictionary of key/value pairs |
| 841 # plus the description minus all key/value or "tag" lines. |
| 842 description_without_tags = [] |
| 843 self.tags = {} |
| 844 for line in self._full_description.splitlines(): |
| 845 m = self.TAG_LINE_RE.match(line) |
| 846 if m: |
| 847 self.tags[m.group('key')] = m.group('value') |
| 848 else: |
| 849 description_without_tags.append(line) |
| 850 |
| 851 # Change back to text and remove whitespace at end. |
| 852 self._description_without_tags = ( |
| 853 '\n'.join(description_without_tags).rstrip()) |
| 854 |
| 845 def RepositoryRoot(self): | 855 def RepositoryRoot(self): |
| 846 """Returns the repository (checkout) root directory for this change, | 856 """Returns the repository (checkout) root directory for this change, |
| 847 as an absolute path. | 857 as an absolute path. |
| 848 """ | 858 """ |
| 849 return self._local_root | 859 return self._local_root |
| 850 | 860 |
| 851 def __getattr__(self, attr): | 861 def __getattr__(self, attr): |
| 852 """Return tags directly as attributes on the object.""" | 862 """Return tags directly as attributes on the object.""" |
| 853 if not re.match(r"^[A-Z_]*$", attr): | 863 if not re.match(r"^[A-Z_]*$", attr): |
| 854 raise AttributeError(self, attr) | 864 raise AttributeError(self, attr) |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1607 except PresubmitFailure, e: | 1617 except PresubmitFailure, e: |
| 1608 print >> sys.stderr, e | 1618 print >> sys.stderr, e |
| 1609 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1619 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
| 1610 print >> sys.stderr, 'If all fails, contact maruel@' | 1620 print >> sys.stderr, 'If all fails, contact maruel@' |
| 1611 return 2 | 1621 return 2 |
| 1612 | 1622 |
| 1613 | 1623 |
| 1614 if __name__ == '__main__': | 1624 if __name__ == '__main__': |
| 1615 fix_encoding.fix_encoding() | 1625 fix_encoding.fix_encoding() |
| 1616 sys.exit(Main(None)) | 1626 sys.exit(Main(None)) |
| OLD | NEW |