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 |
11 import os | 11 import os |
12 import sys | 12 import sys |
| 13 import urllib2 |
13 | 14 |
14 import breakpad # pylint: disable=W0611 | 15 import breakpad # pylint: disable=W0611 |
15 | 16 |
16 import checkout | 17 import checkout |
17 import fix_encoding | 18 import fix_encoding |
18 import rietveld | 19 import rietveld |
19 import scm | 20 import scm |
20 | 21 |
21 | 22 |
22 def main(): | 23 def main(): |
(...skipping 21 matching lines...) Expand all Loading... |
44 help='Rietveld server') | 45 help='Rietveld server') |
45 options, args = parser.parse_args() | 46 options, args = parser.parse_args() |
46 logging.basicConfig( | 47 logging.basicConfig( |
47 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', | 48 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', |
48 level=[logging.WARNING, logging.INFO, logging.DEBUG][ | 49 level=[logging.WARNING, logging.INFO, logging.DEBUG][ |
49 min(2, options.verbose)]) | 50 min(2, options.verbose)]) |
50 if args: | 51 if args: |
51 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) | 52 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) |
52 if not options.issue: | 53 if not options.issue: |
53 parser.error('Require --issue') | 54 parser.error('Require --issue') |
| 55 options.server = options.server.rstrip('/') |
| 56 if not options.server: |
| 57 parser.error('Require a valid server') |
54 | 58 |
55 # TODO(rogerta): Remove me, it's ugly. | 59 # TODO(rogerta): Remove me, it's ugly. |
56 if options.email == '=': | 60 if options.email == '=': |
57 options.email = '' | 61 options.email = '' |
58 | 62 |
59 obj = rietveld.Rietveld(options.server, options.email, None) | 63 obj = rietveld.Rietveld(options.server, options.email, None) |
60 | 64 |
61 if not options.patchset: | 65 if not options.patchset: |
62 options.patchset = obj.get_issue_properties( | 66 options.patchset = obj.get_issue_properties( |
63 options.issue, False)['patchsets'][-1] | 67 options.issue, False)['patchsets'][-1] |
64 print('No patchset specified. Using patchset %d' % options.patchset) | 68 print('No patchset specified. Using patchset %d' % options.patchset) |
65 | 69 |
66 print('Downloading the patch.') | 70 print('Downloading the patch.') |
67 patchset = obj.get_patch(options.issue, options.patchset) | 71 try: |
| 72 patchset = obj.get_patch(options.issue, options.patchset) |
| 73 except urllib2.HTTPError, e: |
| 74 print >> sys.stderr, ( |
| 75 'Failed to fetch the patch for issue %d, patchset %d.\n' |
| 76 'Try visiting %s/%d') % ( |
| 77 options.issue, options.patchset, |
| 78 options.server, options.issue) |
| 79 return 1 |
68 for patch in patchset.patches: | 80 for patch in patchset.patches: |
69 print(patch) | 81 print(patch) |
70 scm_type = scm.determine_scm(options.root_dir) | 82 scm_type = scm.determine_scm(options.root_dir) |
71 if scm_type == 'svn': | 83 if scm_type == 'svn': |
72 scm_obj = checkout.SvnCheckout(options.root_dir, None, None, None, None) | 84 scm_obj = checkout.SvnCheckout(options.root_dir, None, None, None, None) |
73 elif scm_type == 'git': | 85 elif scm_type == 'git': |
74 scm_obj = checkout.GitCheckoutBase(options.root_dir, None, None) | 86 scm_obj = checkout.GitCheckoutBase(options.root_dir, None, None) |
75 elif scm_type == None: | 87 elif scm_type == None: |
76 scm_obj = checkout.RawCheckout(options.root_dir, None) | 88 scm_obj = checkout.RawCheckout(options.root_dir, None) |
77 else: | 89 else: |
78 parser.error('Couldn\'t determine the scm') | 90 parser.error('Couldn\'t determine the scm') |
79 | 91 |
80 # Apply the patch. | 92 # Apply the patch. |
81 try: | 93 try: |
82 scm_obj.apply_patch(patchset) | 94 scm_obj.apply_patch(patchset) |
83 except checkout.PatchApplicationFailed, e: | 95 except checkout.PatchApplicationFailed, e: |
84 print >> sys.stderr, str(e) | 96 print >> sys.stderr, str(e) |
85 return 1 | 97 return 1 |
86 return 0 | 98 return 0 |
87 | 99 |
88 | 100 |
89 if __name__ == "__main__": | 101 if __name__ == "__main__": |
90 fix_encoding.fix_encoding() | 102 fix_encoding.fix_encoding() |
91 sys.exit(main()) | 103 sys.exit(main()) |
OLD | NEW |