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 It is only enabled when all these conditions are met: | 9 It is only enabled when all these conditions are met: |
10 1. hostname finishes with '.google.com' | 10 1. hostname finishes with '.google.com' |
(...skipping 21 matching lines...) Expand all Loading... |
32 if not url: | 32 if not url: |
33 url = DEFAULT_URL | 33 url = DEFAULT_URL |
34 print 'Sending crash report ...' | 34 print 'Sending crash report ...' |
35 try: | 35 try: |
36 params = { | 36 params = { |
37 'args': sys.argv, | 37 'args': sys.argv, |
38 'stack': stack, | 38 'stack': stack, |
39 'user': getpass.getuser(), | 39 'user': getpass.getuser(), |
40 'exception': last_tb, | 40 'exception': last_tb, |
41 'host': socket.getfqdn(), | 41 'host': socket.getfqdn(), |
| 42 'cwd': os.getcwd(), |
42 } | 43 } |
43 try: | 44 try: |
44 # That may not always work. | 45 # That may not always work. |
45 params['exception'] = str(last_tb) | 46 params['exception'] = str(last_tb) |
46 except: | 47 except: |
47 pass | 48 pass |
| 49 print '\n'.join(' %s: %s' % (k, v[0:50]) for k,v in params.iteritems()) |
48 request = urllib.urlopen(url, urllib.urlencode(params)) | 50 request = urllib.urlopen(url, urllib.urlencode(params)) |
49 print request.read() | 51 print request.read() |
50 request.close() | 52 request.close() |
51 except IOError: | 53 except IOError: |
52 print('There was a failure while trying to send the stack trace. Too bad.') | 54 print('There was a failure while trying to send the stack trace. Too bad.') |
53 | 55 |
54 | 56 |
55 def CheckForException(): | 57 def CheckForException(): |
56 """Runs at exit. Look if there was an exception active.""" | 58 """Runs at exit. Look if there was an exception active.""" |
57 last_value = getattr(sys, 'last_value', None) | 59 last_value = getattr(sys, 'last_value', None) |
58 if last_value and not isinstance(last_value, KeyboardInterrupt): | 60 if last_value and not isinstance(last_value, KeyboardInterrupt): |
59 last_tb = getattr(sys, 'last_traceback', None) | 61 last_tb = getattr(sys, 'last_traceback', None) |
60 if last_tb: | 62 if last_tb: |
61 SendStack(repr(last_value), ''.join(traceback.format_tb(last_tb))) | 63 SendStack(last_value, ''.join(traceback.format_tb(last_tb))) |
62 | 64 |
63 | 65 |
64 def Register(): | 66 def Register(): |
65 """Registers the callback at exit. Calling it multiple times is no-op.""" | 67 """Registers the callback at exit. Calling it multiple times is no-op.""" |
66 global _REGISTERED | 68 global _REGISTERED |
67 if _REGISTERED: | 69 if _REGISTERED: |
68 return | 70 return |
69 _REGISTERED = True | 71 _REGISTERED = True |
70 atexit.register(CheckForException) | 72 atexit.register(CheckForException) |
71 | 73 |
72 | 74 |
73 # Skip unit tests and we don't want anything from non-googler. | 75 # Skip unit tests and we don't want anything from non-googler. |
74 if (not 'test' in sys.modules['__main__'].__file__ and | 76 if (not 'test' in sys.modules['__main__'].__file__ and |
75 socket.getfqdn().endswith('.google.com') and | 77 socket.getfqdn().endswith('.google.com') and |
76 not 'NO_BREAKPAD' in os.environ): | 78 not 'NO_BREAKPAD' in os.environ): |
77 Register() | 79 Register() |
78 | 80 |
79 # Uncomment this line if you want to test it out. | 81 # Uncomment this line if you want to test it out. |
80 #Register() | 82 #Register() |
OLD | NEW |