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

Side by Side Diff: gclient.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, 10 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
« clang_format.py ('K') | « gcl.py ('k') | git_auto_svn.py » ('j') | 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 """Meta checkout manager supporting both Subversion and GIT.""" 6 """Meta checkout manager supporting both Subversion and GIT."""
7 # Files 7 # Files
8 # .gclient : Current client configuration, written by 'config' command. 8 # .gclient : Current client configuration, written by 'config' command.
9 # Format is a Python script defining 'solutions', a list whose 9 # Format is a Python script defining 'solutions', a list whose
10 # entries each are maps binding the strings "name" and "url" 10 # entries each are maps binding the strings "name" and "url"
(...skipping 2248 matching lines...) Expand 10 before | Expand all | Expand 10 after
2259 2259
2260 2260
2261 def disable_buffering(): 2261 def disable_buffering():
2262 # Make stdout auto-flush so buildbot doesn't kill us during lengthy 2262 # Make stdout auto-flush so buildbot doesn't kill us during lengthy
2263 # operations. Python as a strong tendency to buffer sys.stdout. 2263 # operations. Python as a strong tendency to buffer sys.stdout.
2264 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) 2264 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
2265 # Make stdout annotated with the thread ids. 2265 # Make stdout annotated with the thread ids.
2266 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout) 2266 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout)
2267 2267
2268 2268
2269 def Main(argv): 2269 def main(argv):
2270 """Doesn't parse the arguments here, just find the right subcommand to 2270 """Doesn't parse the arguments here, just find the right subcommand to
2271 execute.""" 2271 execute."""
2272 if sys.hexversion < 0x02060000: 2272 if sys.hexversion < 0x02060000:
2273 print >> sys.stderr, ( 2273 print >> sys.stderr, (
2274 '\nYour python version %s is unsupported, please upgrade.\n' % 2274 '\nYour python version %s is unsupported, please upgrade.\n' %
2275 sys.version.split(' ', 1)[0]) 2275 sys.version.split(' ', 1)[0])
2276 return 2 2276 return 2
2277 if not sys.executable: 2277 if not sys.executable:
2278 print >> sys.stderr, ( 2278 print >> sys.stderr, (
2279 '\nPython cannot find the location of it\'s own executable.\n') 2279 '\nPython cannot find the location of it\'s own executable.\n')
2280 return 2 2280 return 2
2281 fix_encoding.fix_encoding() 2281 fix_encoding.fix_encoding()
2282 disable_buffering() 2282 disable_buffering()
2283 colorama.init() 2283 colorama.init()
2284 dispatcher = subcommand.CommandDispatcher(__name__) 2284 dispatcher = subcommand.CommandDispatcher(__name__)
2285 try: 2285 try:
2286 return dispatcher.execute(OptionParser(), argv) 2286 return dispatcher.execute(OptionParser(), argv)
2287 except KeyboardInterrupt: 2287 except KeyboardInterrupt:
2288 gclient_utils.GClientChildren.KillAllRemainingChildren() 2288 gclient_utils.GClientChildren.KillAllRemainingChildren()
2289 raise 2289 raise
2290 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 2290 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
2291 print >> sys.stderr, 'Error: %s' % str(e) 2291 print >> sys.stderr, 'Error: %s' % str(e)
2292 return 1 2292 return 1
2293 finally: 2293 finally:
2294 gclient_utils.PrintWarnings() 2294 gclient_utils.PrintWarnings()
2295 return 0
2295 2296
2296 2297
2297 if '__main__' == __name__: 2298 if '__main__' == __name__:
2298 sys.exit(Main(sys.argv[1:])) 2299 try:
2300 sys.exit(main(sys.argv[1:]))
2301 except KeyboardInterrupt:
2302 sys.stderr.write('interrupted\n')
2303 sys.exit(1)
2299 2304
2300 # vim: ts=2:sw=2:tw=80:et: 2305 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« clang_format.py ('K') | « gcl.py ('k') | git_auto_svn.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698