OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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.5' | 9 __version__ = '1.3.5' |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 # Statement seems to have no effect | 44 # Statement seems to have no effect |
45 # pylint: disable=W0104 | 45 # pylint: disable=W0104 |
46 json.loads | 46 json.loads |
47 except (ImportError, AttributeError): | 47 except (ImportError, AttributeError): |
48 # Import the one included in depot_tools. | 48 # Import the one included in depot_tools. |
49 sys.path.append(os.path.join(os.path.dirname(__file__), 'third_party')) | 49 sys.path.append(os.path.join(os.path.dirname(__file__), 'third_party')) |
50 import simplejson as json | 50 import simplejson as json |
51 | 51 |
52 # Local imports. | 52 # Local imports. |
53 import gclient_utils | 53 import gclient_utils |
| 54 import owners |
54 import presubmit_canned_checks | 55 import presubmit_canned_checks |
55 import scm | 56 import scm |
56 | 57 |
57 | 58 |
58 # Ask for feedback only once in program lifetime. | 59 # Ask for feedback only once in program lifetime. |
59 _ASKED_FOR_FEEDBACK = False | 60 _ASKED_FOR_FEEDBACK = False |
60 | 61 |
61 | 62 |
62 class NotImplementedException(Exception): | 63 class NotImplementedException(Exception): |
63 """We're leaving placeholders in a bunch of places to remind us of the | 64 """We're leaving placeholders in a bunch of places to remind us of the |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 249 |
249 # InputApi.platform is the platform you're currently running on. | 250 # InputApi.platform is the platform you're currently running on. |
250 self.platform = sys.platform | 251 self.platform = sys.platform |
251 | 252 |
252 # The local path of the currently-being-processed presubmit script. | 253 # The local path of the currently-being-processed presubmit script. |
253 self._current_presubmit_path = os.path.dirname(presubmit_path) | 254 self._current_presubmit_path = os.path.dirname(presubmit_path) |
254 | 255 |
255 # We carry the canned checks so presubmit scripts can easily use them. | 256 # We carry the canned checks so presubmit scripts can easily use them. |
256 self.canned_checks = presubmit_canned_checks | 257 self.canned_checks = presubmit_canned_checks |
257 | 258 |
| 259 # TODO(dpranke): figure out a list of all approved owners for a repo |
| 260 # in order to be able to handle wildcard OWNERS files? |
| 261 self.owners_db = owners.Database(change.RepositoryRoot(), |
| 262 fopen=file, os_path=self.os_path) |
| 263 |
258 def PresubmitLocalPath(self): | 264 def PresubmitLocalPath(self): |
259 """Returns the local path of the presubmit script currently being run. | 265 """Returns the local path of the presubmit script currently being run. |
260 | 266 |
261 This is useful if you don't want to hard-code absolute paths in the | 267 This is useful if you don't want to hard-code absolute paths in the |
262 presubmit script. For example, It can be used to find another file | 268 presubmit script. For example, It can be used to find another file |
263 relative to the PRESUBMIT.py script, so the whole tree can be branched and | 269 relative to the PRESUBMIT.py script, so the whole tree can be branched and |
264 the presubmit script still works, without editing its content. | 270 the presubmit script still works, without editing its content. |
265 """ | 271 """ |
266 return self._current_presubmit_path | 272 return self._current_presubmit_path |
267 | 273 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 633 |
628 def __init__(self, name, description, local_root, files, issue, patchset): | 634 def __init__(self, name, description, local_root, files, issue, patchset): |
629 if files is None: | 635 if files is None: |
630 files = [] | 636 files = [] |
631 self._name = name | 637 self._name = name |
632 self._full_description = description | 638 self._full_description = description |
633 # Convert root into an absolute path. | 639 # Convert root into an absolute path. |
634 self._local_root = os.path.abspath(local_root) | 640 self._local_root = os.path.abspath(local_root) |
635 self.issue = issue | 641 self.issue = issue |
636 self.patchset = patchset | 642 self.patchset = patchset |
| 643 |
| 644 # TODO(dpranke): implement - get from the patchset? |
| 645 self.approvers = set() |
| 646 |
637 self.scm = '' | 647 self.scm = '' |
638 | 648 |
639 # From the description text, build up a dictionary of key/value pairs | 649 # From the description text, build up a dictionary of key/value pairs |
640 # plus the description minus all key/value or "tag" lines. | 650 # plus the description minus all key/value or "tag" lines. |
641 description_without_tags = [] | 651 description_without_tags = [] |
642 self.tags = {} | 652 self.tags = {} |
643 for line in self._full_description.splitlines(): | 653 for line in self._full_description.splitlines(): |
644 m = self._TAG_LINE_RE.match(line) | 654 m = self._TAG_LINE_RE.match(line) |
645 if m: | 655 if m: |
646 self.tags[m.group('key')] = m.group('value') | 656 self.tags[m.group('key')] = m.group('value') |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 options.commit, | 1168 options.commit, |
1159 options.verbose, | 1169 options.verbose, |
1160 sys.stdout, | 1170 sys.stdout, |
1161 sys.stdin, | 1171 sys.stdin, |
1162 options.default_presubmit, | 1172 options.default_presubmit, |
1163 options.may_prompt) | 1173 options.may_prompt) |
1164 | 1174 |
1165 | 1175 |
1166 if __name__ == '__main__': | 1176 if __name__ == '__main__': |
1167 sys.exit(Main(sys.argv)) | 1177 sys.exit(Main(sys.argv)) |
OLD | NEW |