Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(614)

Side by Side Diff: presubmit_support.py

Issue 236093002: Added POST capability to oauth Rietveld (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Style fixes Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | rietveld.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 lines are stripped out of the description this function returns. 826 lines are stripped out of the description this function returns.
827 """ 827 """
828 return self._description_without_tags 828 return self._description_without_tags
829 829
830 def FullDescriptionText(self): 830 def FullDescriptionText(self):
831 """Returns the complete changelist description including tags.""" 831 """Returns the complete changelist description including tags."""
832 return self._full_description 832 return self._full_description
833 833
834 def SetDescriptionText(self, description): 834 def SetDescriptionText(self, description):
835 """Sets the full description text (including tags) to |description|. 835 """Sets the full description text (including tags) to |description|.
836 836
837 Also updates the list of tags.""" 837 Also updates the list of tags."""
838 self._full_description = description 838 self._full_description = description
839 839
840 # From the description text, build up a dictionary of key/value pairs 840 # From the description text, build up a dictionary of key/value pairs
841 # plus the description minus all key/value or "tag" lines. 841 # plus the description minus all key/value or "tag" lines.
842 description_without_tags = [] 842 description_without_tags = []
843 self.tags = {} 843 self.tags = {}
844 for line in self._full_description.splitlines(): 844 for line in self._full_description.splitlines():
845 m = self.TAG_LINE_RE.match(line) 845 m = self.TAG_LINE_RE.match(line)
846 if m: 846 if m:
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 results.append(p) 1011 results.append(p)
1012 1012
1013 logging.debug('Presubmit files: %s' % ','.join(results)) 1013 logging.debug('Presubmit files: %s' % ','.join(results))
1014 return results 1014 return results
1015 1015
1016 1016
1017 class GetTrySlavesExecuter(object): 1017 class GetTrySlavesExecuter(object):
1018 @staticmethod 1018 @staticmethod
1019 def ExecPresubmitScript(script_text, presubmit_path, project, change): 1019 def ExecPresubmitScript(script_text, presubmit_path, project, change):
1020 """Executes GetPreferredTrySlaves() from a single presubmit script. 1020 """Executes GetPreferredTrySlaves() from a single presubmit script.
1021 1021
1022 This will soon be deprecated and replaced by GetPreferredTryMasters(). 1022 This will soon be deprecated and replaced by GetPreferredTryMasters().
1023 1023
1024 Args: 1024 Args:
1025 script_text: The text of the presubmit script. 1025 script_text: The text of the presubmit script.
1026 presubmit_path: Project script to run. 1026 presubmit_path: Project script to run.
1027 project: Project name to pass to presubmit script for bot selection. 1027 project: Project name to pass to presubmit script for bot selection.
1028 1028
1029 Return: 1029 Return:
1030 A list of try slaves. 1030 A list of try slaves.
1031 """ 1031 """
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 parser.add_option("--may_prompt", action='store_true', default=False) 1534 parser.add_option("--may_prompt", action='store_true', default=False)
1535 parser.add_option("--skip_canned", action='append', default=[], 1535 parser.add_option("--skip_canned", action='append', default=[],
1536 help="A list of checks to skip which appear in " 1536 help="A list of checks to skip which appear in "
1537 "presubmit_canned_checks. Can be provided multiple times " 1537 "presubmit_canned_checks. Can be provided multiple times "
1538 "to skip multiple canned checks.") 1538 "to skip multiple canned checks.")
1539 parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP) 1539 parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP)
1540 parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP) 1540 parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP)
1541 parser.add_option("--rietveld_password", help=optparse.SUPPRESS_HELP) 1541 parser.add_option("--rietveld_password", help=optparse.SUPPRESS_HELP)
1542 parser.add_option("--rietveld_fetch", action='store_true', default=False, 1542 parser.add_option("--rietveld_fetch", action='store_true', default=False,
1543 help=optparse.SUPPRESS_HELP) 1543 help=optparse.SUPPRESS_HELP)
1544 # These are for OAuth2 authentication for bots. See also apply_issue.py
1545 parser.add_option("--rietveld_email_file", help=optparse.SUPPRESS_HELP)
1546 parser.add_option("--rietveld_private_key_file", help=optparse.SUPPRESS_HELP)
1547
1544 parser.add_option("--trybot-json", 1548 parser.add_option("--trybot-json",
1545 help="Output trybot information to the file specified.") 1549 help="Output trybot information to the file specified.")
1546 options, args = parser.parse_args(argv) 1550 options, args = parser.parse_args(argv)
1551
1547 if options.verbose >= 2: 1552 if options.verbose >= 2:
1548 logging.basicConfig(level=logging.DEBUG) 1553 logging.basicConfig(level=logging.DEBUG)
1549 elif options.verbose: 1554 elif options.verbose:
1550 logging.basicConfig(level=logging.INFO) 1555 logging.basicConfig(level=logging.INFO)
1551 else: 1556 else:
1552 logging.basicConfig(level=logging.ERROR) 1557 logging.basicConfig(level=logging.ERROR)
1558
1559 if options.rietveld_email and options.rietveld_email_file:
1560 parser.error("Only one of --rietveld_email or --rietveld_email_file "
1561 "can be passed to this program.")
1562 if options.rietveld_private_key_file and options.rietveld_password:
1563 parser.error("Only one of --rietveld_private_key_file or "
1564 "--rietveld_password can be passed to this program.")
1565 if options.rietveld_email_file:
1566 with open(options.rietveld_email_file, "rb") as f:
1567 options.rietveld_email = f.read().strip()
1568
1553 change_class, files = load_files(options, args) 1569 change_class, files = load_files(options, args)
1554 if not change_class: 1570 if not change_class:
1555 parser.error('For unversioned directory, <files> is not optional.') 1571 parser.error('For unversioned directory, <files> is not optional.')
1556 logging.info('Found %d file(s).' % len(files)) 1572 logging.info('Found %d file(s).' % len(files))
1573
1557 rietveld_obj = None 1574 rietveld_obj = None
1558 if options.rietveld_url: 1575 if options.rietveld_url:
1559 rietveld_obj = rietveld.CachingRietveld( 1576 # The empty password is permitted: '' is not None.
1577 if options.rietveld_password is not None:
1578 rietveld_obj = rietveld.CachingRietveld(
1560 options.rietveld_url, 1579 options.rietveld_url,
1561 options.rietveld_email, 1580 options.rietveld_email,
1562 options.rietveld_password) 1581 options.rietveld_password)
1582 elif options.rietveld_private_key_file:
1583 rietveld_obj = rietveld.JwtOAuth2Rietveld(
1584 options.rietveld_url,
1585 options.rietveld_email,
1586 options.rietveld_private_key_file)
1587 else:
1588 parser.error("No password or secret key has been provided for "
1589 "Rietveld. Unable to connect.")
1563 if options.rietveld_fetch: 1590 if options.rietveld_fetch:
1564 assert options.issue 1591 assert options.issue
1565 props = rietveld_obj.get_issue_properties(options.issue, False) 1592 props = rietveld_obj.get_issue_properties(options.issue, False)
1566 options.author = props['owner_email'] 1593 options.author = props['owner_email']
1567 options.description = props['description'] 1594 options.description = props['description']
1568 logging.info('Got author: "%s"', options.author) 1595 logging.info('Got author: "%s"', options.author)
1569 logging.info('Got description: """\n%s\n"""', options.description) 1596 logging.info('Got description: """\n%s\n"""', options.description)
1570 if options.trybot_json: 1597 if options.trybot_json:
1571 with open(options.trybot_json, 'w') as f: 1598 with open(options.trybot_json, 'w') as f:
1572 # Python's sets aren't JSON-encodable, so we convert them to lists here. 1599 # Python's sets aren't JSON-encodable, so we convert them to lists here.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 except PresubmitFailure, e: 1644 except PresubmitFailure, e:
1618 print >> sys.stderr, e 1645 print >> sys.stderr, e
1619 print >> sys.stderr, 'Maybe your depot_tools is out of date?' 1646 print >> sys.stderr, 'Maybe your depot_tools is out of date?'
1620 print >> sys.stderr, 'If all fails, contact maruel@' 1647 print >> sys.stderr, 'If all fails, contact maruel@'
1621 return 2 1648 return 2
1622 1649
1623 1650
1624 if __name__ == '__main__': 1651 if __name__ == '__main__':
1625 fix_encoding.fix_encoding() 1652 fix_encoding.fix_encoding()
1626 sys.exit(Main(None)) 1653 sys.exit(Main(None))
OLDNEW
« no previous file with comments | « no previous file | rietveld.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698