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

Side by Side Diff: git_nav_downstream.py

Issue 955993006: Handle KeyboardInterrupt consistently in python scripts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: tweek test expectations Created 5 years, 9 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 """ 6 """
7 Checks out a downstream branch from the currently checked out branch. If there 7 Checks out a downstream branch from the currently checked out branch. If there
8 is more than one downstream branch, then this script will prompt you to select 8 is more than one downstream branch, then this script will prompt you to select
9 which branch. 9 which branch.
10 """ 10 """
(...skipping 16 matching lines...) Expand all
27 cur = current_branch() 27 cur = current_branch()
28 if cur == 'HEAD': 28 if cur == 'HEAD':
29 def _upfn(b): 29 def _upfn(b):
30 parent = upstream(b) 30 parent = upstream(b)
31 if parent: 31 if parent:
32 return hash_one(parent) 32 return hash_one(parent)
33 upfn = _upfn 33 upfn = _upfn
34 cur = hash_one(cur) 34 cur = hash_one(cur)
35 downstreams = [b for b in branches() if upfn(b) == cur] 35 downstreams = [b for b in branches() if upfn(b) == cur]
36 if not downstreams: 36 if not downstreams:
37 return "No downstream branches" 37 print "No downstream branches"
38 return 1
38 elif len(downstreams) == 1: 39 elif len(downstreams) == 1:
39 run('checkout', downstreams[0], stdout=sys.stdout, stderr=sys.stderr) 40 run('checkout', downstreams[0], stdout=sys.stdout, stderr=sys.stderr)
40 else: 41 else:
41 high = len(downstreams) - 1 42 high = len(downstreams) - 1
42 while True: 43 while True:
43 print "Please select a downstream branch" 44 print "Please select a downstream branch"
44 for i, b in enumerate(downstreams): 45 for i, b in enumerate(downstreams):
45 print " %d. %s" % (i, b) 46 print " %d. %s" % (i, b)
46 prompt = "Selection (0-%d)[0]: " % high 47 prompt = "Selection (0-%d)[0]: " % high
47 r = opts.pick 48 r = opts.pick
48 if r: 49 if r:
49 print prompt + r 50 print prompt + r
50 else: 51 else:
51 r = raw_input(prompt).strip() or '0' 52 r = raw_input(prompt).strip() or '0'
52 if not r.isdigit() or (0 > int(r) > high): 53 if not r.isdigit() or (0 > int(r) > high):
53 print "Invalid choice." 54 print "Invalid choice."
54 else: 55 else:
55 run('checkout', downstreams[int(r)], stdout=sys.stdout, 56 run('checkout', downstreams[int(r)], stdout=sys.stdout,
56 stderr=sys.stderr) 57 stderr=sys.stderr)
57 break 58 break
59 return 0
58 60
59 61
60 if __name__ == '__main__': 62 if __name__ == '__main__':
61 try: 63 try:
62 sys.exit(main(sys.argv[1:])) 64 sys.exit(main(sys.argv[1:]))
63 except KeyboardInterrupt: 65 except KeyboardInterrupt:
64 pass 66 sys.stderr.write('interrupted\n')
67 sys.exit(1)
OLDNEW
« clang_format.py ('K') | « git_mark_merge_base.py ('k') | git_new_branch.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698