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 """Applies an issue from Rietveld. | 6 """Applies an issue from Rietveld. |
7 """ | 7 """ |
8 | 8 |
9 import logging | 9 import logging |
10 import optparse | 10 import optparse |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 | 22 |
23 def main(): | 23 def main(): |
24 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 24 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
25 parser.add_option( | 25 parser.add_option( |
26 '-v', '--verbose', action='count', default=0, | 26 '-v', '--verbose', action='count', default=0, |
27 help='Prints debugging infos') | 27 help='Prints debugging infos') |
28 parser.add_option( | 28 parser.add_option( |
29 '-e', | 29 '-e', |
30 '--email', | 30 '--email', |
31 help='Email address for authenticating with Rietveld') | 31 help='IGNORED: Kept for compatibility.') |
32 parser.add_option( | 32 parser.add_option( |
33 '-i', '--issue', type='int', help='Rietveld issue number') | 33 '-i', '--issue', type='int', help='Rietveld issue number') |
34 parser.add_option( | 34 parser.add_option( |
35 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') | 35 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') |
36 parser.add_option( | 36 parser.add_option( |
37 '-r', | 37 '-r', |
38 '--root_dir', | 38 '--root_dir', |
39 default=os.getcwd(), | 39 default=os.getcwd(), |
40 help='Root directory to apply the patch') | 40 help='Root directory to apply the patch') |
41 parser.add_option( | 41 parser.add_option( |
42 '-s', | 42 '-s', |
43 '--server', | 43 '--server', |
44 default='http://codereview.chromium.org', | 44 default='http://codereview.chromium.org', |
45 help='Rietveld server') | 45 help='Rietveld server') |
46 options, args = parser.parse_args() | 46 options, args = parser.parse_args() |
47 logging.basicConfig( | 47 logging.basicConfig( |
48 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', | 48 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', |
49 level=[logging.WARNING, logging.INFO, logging.DEBUG][ | 49 level=[logging.WARNING, logging.INFO, logging.DEBUG][ |
50 min(2, options.verbose)]) | 50 min(2, options.verbose)]) |
51 if args: | 51 if args: |
52 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) | 52 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) |
53 if not options.issue: | 53 if not options.issue: |
54 parser.error('Require --issue') | 54 parser.error('Require --issue') |
55 options.server = options.server.rstrip('/') | 55 options.server = options.server.rstrip('/') |
56 if not options.server: | 56 if not options.server: |
57 parser.error('Require a valid server') | 57 parser.error('Require a valid server') |
58 | 58 |
59 # TODO(rogerta): Remove me, it's ugly. | 59 obj = rietveld.Rietveld(options.server, '', None) |
60 if options.email == '=': | 60 try: |
61 options.email = '' | 61 properties = obj.get_issue_properties(options.issue, False) |
62 | 62 except rietveld.upload.ClientLoginError: |
63 obj = rietveld.Rietveld(options.server, options.email, None) | 63 # Requires login. |
| 64 obj = rietveld.Rietveld(options.server, None, None) |
| 65 properties = obj.get_issue_properties(options.issue, False) |
64 | 66 |
65 if not options.patchset: | 67 if not options.patchset: |
66 options.patchset = obj.get_issue_properties( | 68 options.patchset = properties['patchsets'][-1] |
67 options.issue, False)['patchsets'][-1] | |
68 print('No patchset specified. Using patchset %d' % options.patchset) | 69 print('No patchset specified. Using patchset %d' % options.patchset) |
69 | 70 |
70 print('Downloading the patch.') | 71 print('Downloading the patch.') |
71 try: | 72 try: |
72 patchset = obj.get_patch(options.issue, options.patchset) | 73 patchset = obj.get_patch(options.issue, options.patchset) |
73 except urllib2.HTTPError, e: | 74 except urllib2.HTTPError, e: |
74 print >> sys.stderr, ( | 75 print >> sys.stderr, ( |
75 'Failed to fetch the patch for issue %d, patchset %d.\n' | 76 'Failed to fetch the patch for issue %d, patchset %d.\n' |
76 'Try visiting %s/%d') % ( | 77 'Try visiting %s/%d') % ( |
77 options.issue, options.patchset, | 78 options.issue, options.patchset, |
(...skipping 16 matching lines...) Expand all Loading... |
94 scm_obj.apply_patch(patchset) | 95 scm_obj.apply_patch(patchset) |
95 except checkout.PatchApplicationFailed, e: | 96 except checkout.PatchApplicationFailed, e: |
96 print >> sys.stderr, str(e) | 97 print >> sys.stderr, str(e) |
97 return 1 | 98 return 1 |
98 return 0 | 99 return 0 |
99 | 100 |
100 | 101 |
101 if __name__ == "__main__": | 102 if __name__ == "__main__": |
102 fix_encoding.fix_encoding() | 103 fix_encoding.fix_encoding() |
103 sys.exit(main()) | 104 sys.exit(main()) |
OLD | NEW |