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 getpass | 9 import getpass |
10 import logging | 10 import logging |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import sys | 13 import sys |
14 import urllib2 | 14 import urllib2 |
15 | 15 |
16 import breakpad # pylint: disable=W0611 | 16 import breakpad # pylint: disable=W0611 |
17 | 17 |
18 import checkout | 18 import checkout |
19 import fix_encoding | 19 import fix_encoding |
20 import rietveld | 20 import rietveld |
21 import scm | 21 import scm |
22 | 22 |
23 | 23 |
24 def main(): | 24 def main(): |
25 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 25 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
26 parser.add_option( | 26 parser.add_option( |
27 '-v', '--verbose', action='count', default=0, | 27 '-v', '--verbose', action='count', default=0, |
28 help='Prints debugging infos') | 28 help='Prints debugging infos') |
29 parser.add_option( | 29 parser.add_option( |
30 '-e', | 30 '-e', '--email', default='', |
31 '--email', | 31 help='Email address to access rietveld. If not specified, anonymous ' |
32 help='IGNORED: Kept for compatibility.') | 32 'access will be used.') |
| 33 parser.add_option( |
| 34 '-w', '--password', default=None, help='Password for email addressed.') |
33 parser.add_option( | 35 parser.add_option( |
34 '-i', '--issue', type='int', help='Rietveld issue number') | 36 '-i', '--issue', type='int', help='Rietveld issue number') |
35 parser.add_option( | 37 parser.add_option( |
36 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') | 38 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') |
37 parser.add_option( | 39 parser.add_option( |
38 '-r', | 40 '-r', |
39 '--root_dir', | 41 '--root_dir', |
40 default=os.getcwd(), | 42 default=os.getcwd(), |
41 help='Root directory to apply the patch') | 43 help='Root directory to apply the patch') |
42 parser.add_option( | 44 parser.add_option( |
43 '-s', | 45 '-s', |
44 '--server', | 46 '--server', |
45 default='http://codereview.chromium.org', | 47 default='http://codereview.chromium.org', |
46 help='Rietveld server') | 48 help='Rietveld server') |
47 options, args = parser.parse_args() | 49 options, args = parser.parse_args() |
48 logging.basicConfig( | 50 logging.basicConfig( |
49 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', | 51 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', |
50 level=[logging.WARNING, logging.INFO, logging.DEBUG][ | 52 level=[logging.WARNING, logging.INFO, logging.DEBUG][ |
51 min(2, options.verbose)]) | 53 min(2, options.verbose)]) |
52 if args: | 54 if args: |
53 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) | 55 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) |
54 if not options.issue: | 56 if not options.issue: |
55 parser.error('Require --issue') | 57 parser.error('Require --issue') |
56 options.server = options.server.rstrip('/') | 58 options.server = options.server.rstrip('/') |
57 if not options.server: | 59 if not options.server: |
58 parser.error('Require a valid server') | 60 parser.error('Require a valid server') |
59 | 61 |
60 obj = rietveld.Rietveld(options.server, '', None) | 62 obj = rietveld.Rietveld(options.server, options.email, options.password) |
61 try: | 63 try: |
62 properties = obj.get_issue_properties(options.issue, False) | 64 properties = obj.get_issue_properties(options.issue, False) |
63 except rietveld.upload.ClientLoginError, e: | 65 except rietveld.upload.ClientLoginError, e: |
64 if sys.stdout.closed: | 66 if sys.stdout.closed: |
65 print >> sys.stderr, 'Accessing the issue requires login.' | 67 print >> sys.stderr, 'Accessing the issue requires login.' |
66 return 1 | 68 return 1 |
67 print('Accessing the issue requires login.') | 69 print('Accessing the issue requires login.') |
68 obj = rietveld.Rietveld(options.server, None, None) | 70 obj = rietveld.Rietveld(options.server, None, None) |
69 properties = obj.get_issue_properties(options.issue, False) | 71 properties = obj.get_issue_properties(options.issue, False) |
70 | 72 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 scm_obj.apply_patch(patchset) | 110 scm_obj.apply_patch(patchset) |
109 except checkout.PatchApplicationFailed, e: | 111 except checkout.PatchApplicationFailed, e: |
110 print >> sys.stderr, str(e) | 112 print >> sys.stderr, str(e) |
111 return 1 | 113 return 1 |
112 return 0 | 114 return 0 |
113 | 115 |
114 | 116 |
115 if __name__ == "__main__": | 117 if __name__ == "__main__": |
116 fix_encoding.fix_encoding() | 118 fix_encoding.fix_encoding() |
117 sys.exit(main()) | 119 sys.exit(main()) |
OLD | NEW |