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

Side by Side Diff: apply_issue.py

Issue 10913026: Handle when a patchset doesn't exist instead of printing a stack trace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 """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
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())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698