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 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 logging.basicConfig(level=logging.INFO) | 1555 logging.basicConfig(level=logging.INFO) |
1556 else: | 1556 else: |
1557 logging.basicConfig(level=logging.ERROR) | 1557 logging.basicConfig(level=logging.ERROR) |
1558 | 1558 |
1559 if options.rietveld_email and options.rietveld_email_file: | 1559 if options.rietveld_email and options.rietveld_email_file: |
1560 parser.error("Only one of --rietveld_email or --rietveld_email_file " | 1560 parser.error("Only one of --rietveld_email or --rietveld_email_file " |
1561 "can be passed to this program.") | 1561 "can be passed to this program.") |
1562 if options.rietveld_private_key_file and options.rietveld_password: | 1562 if options.rietveld_private_key_file and options.rietveld_password: |
1563 parser.error("Only one of --rietveld_private_key_file or " | 1563 parser.error("Only one of --rietveld_private_key_file or " |
1564 "--rietveld_password can be passed to this program.") | 1564 "--rietveld_password can be passed to this program.") |
| 1565 |
1565 if options.rietveld_email_file: | 1566 if options.rietveld_email_file: |
1566 with open(options.rietveld_email_file, "rb") as f: | 1567 with open(options.rietveld_email_file, "rb") as f: |
1567 options.rietveld_email = f.read().strip() | 1568 options.rietveld_email = f.read().strip() |
1568 | 1569 |
1569 change_class, files = load_files(options, args) | 1570 change_class, files = load_files(options, args) |
1570 if not change_class: | 1571 if not change_class: |
1571 parser.error('For unversioned directory, <files> is not optional.') | 1572 parser.error('For unversioned directory, <files> is not optional.') |
1572 logging.info('Found %d file(s).' % len(files)) | 1573 logging.info('Found %d file(s).' % len(files)) |
1573 | 1574 |
1574 rietveld_obj = None | 1575 rietveld_obj = None |
1575 if options.rietveld_url: | 1576 if options.rietveld_url: |
1576 # The empty password is permitted: '' is not None. | 1577 # The empty password is permitted: '' is not None. |
1577 if options.rietveld_password is not None: | 1578 if options.rietveld_private_key_file: |
1578 rietveld_obj = rietveld.CachingRietveld( | |
1579 options.rietveld_url, | |
1580 options.rietveld_email, | |
1581 options.rietveld_password) | |
1582 elif options.rietveld_private_key_file: | |
1583 rietveld_obj = rietveld.JwtOAuth2Rietveld( | 1579 rietveld_obj = rietveld.JwtOAuth2Rietveld( |
1584 options.rietveld_url, | 1580 options.rietveld_url, |
1585 options.rietveld_email, | 1581 options.rietveld_email, |
1586 options.rietveld_private_key_file) | 1582 options.rietveld_private_key_file) |
1587 else: | 1583 else: |
1588 parser.error("No password or secret key has been provided for " | 1584 rietveld_obj = rietveld.CachingRietveld( |
1589 "Rietveld. Unable to connect.") | 1585 options.rietveld_url, |
| 1586 options.rietveld_email, |
| 1587 options.rietveld_password) |
1590 if options.rietveld_fetch: | 1588 if options.rietveld_fetch: |
1591 assert options.issue | 1589 assert options.issue |
1592 props = rietveld_obj.get_issue_properties(options.issue, False) | 1590 props = rietveld_obj.get_issue_properties(options.issue, False) |
1593 options.author = props['owner_email'] | 1591 options.author = props['owner_email'] |
1594 options.description = props['description'] | 1592 options.description = props['description'] |
1595 logging.info('Got author: "%s"', options.author) | 1593 logging.info('Got author: "%s"', options.author) |
1596 logging.info('Got description: """\n%s\n"""', options.description) | 1594 logging.info('Got description: """\n%s\n"""', options.description) |
1597 if options.trybot_json: | 1595 if options.trybot_json: |
1598 with open(options.trybot_json, 'w') as f: | 1596 with open(options.trybot_json, 'w') as f: |
1599 # Python's sets aren't JSON-encodable, so we convert them to lists here. | 1597 # 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 Loading... |
1644 except PresubmitFailure, e: | 1642 except PresubmitFailure, e: |
1645 print >> sys.stderr, e | 1643 print >> sys.stderr, e |
1646 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1644 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
1647 print >> sys.stderr, 'If all fails, contact maruel@' | 1645 print >> sys.stderr, 'If all fails, contact maruel@' |
1648 return 2 | 1646 return 2 |
1649 | 1647 |
1650 | 1648 |
1651 if __name__ == '__main__': | 1649 if __name__ == '__main__': |
1652 fix_encoding.fix_encoding() | 1650 fix_encoding.fix_encoding() |
1653 sys.exit(Main(None)) | 1651 sys.exit(Main(None)) |
OLD | NEW |