OLD | NEW |
1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Breakpad for Python. | 5 """Breakpad for Python. |
6 | 6 |
7 Sends a notification when a process stops on an exception.""" | 7 Sends a notification when a process stops on an exception.""" |
8 | 8 |
9 import atexit | 9 import atexit |
10 import getpass | 10 import getpass |
11 import urllib | 11 import urllib |
12 import traceback | 12 import traceback |
13 import socket | 13 import socket |
14 import sys | 14 import sys |
15 | 15 |
16 | 16 |
17 def SendStack(stack, url='http://chromium-status.appspot.com/breakpad'): | 17 def SendStack(stack, url='http://chromium-status.appspot.com/breakpad'): |
18 print 'Do you want to send a crash report [y/N]? ', | |
19 if sys.stdin.read(1).lower() != 'y': | |
20 return | |
21 print 'Sending crash report ...' | 18 print 'Sending crash report ...' |
22 try: | 19 try: |
23 params = { | 20 params = { |
24 'args': sys.argv, | 21 'args': sys.argv, |
25 'stack': stack, | 22 'stack': stack, |
26 'user': getpass.getuser(), | 23 'user': getpass.getuser(), |
27 } | 24 } |
28 request = urllib.urlopen(url, urllib.urlencode(params)) | 25 request = urllib.urlopen(url, urllib.urlencode(params)) |
29 print request.read() | 26 print request.read() |
30 request.close() | 27 request.close() |
31 except IOError: | 28 except IOError: |
32 print('There was a failure while trying to send the stack trace. Too bad.') | 29 print('There was a failure while trying to send the stack trace. Too bad.') |
33 | 30 |
34 | 31 |
35 def CheckForException(): | 32 def CheckForException(): |
36 last_tb = getattr(sys, 'last_traceback', None) | 33 last_tb = getattr(sys, 'last_traceback', None) |
37 if last_tb and sys.last_type is not KeyboardInterrupt: | 34 if last_tb and sys.last_type is not KeyboardInterrupt: |
38 SendStack(''.join(traceback.format_tb(last_tb))) | 35 SendStack(''.join(traceback.format_tb(last_tb))) |
39 | 36 |
40 | 37 |
41 if (not 'test' in sys.modules['__main__'].__file__ and | 38 if (not 'test' in sys.modules['__main__'].__file__ and |
42 socket.gethostname().endswith('.google.com')): | 39 socket.gethostname().endswith('.google.com')): |
43 # Skip unit tests and we don't want anything from non-googler. | 40 # Skip unit tests and we don't want anything from non-googler. |
44 atexit.register(CheckForException) | 41 atexit.register(CheckForException) |
OLD | NEW |