1 import sys
2 import gtk
3 import util
4 import debuglog
5
7 pass
8
10 pass
11
12 _have_recoverable_error = False
13
14 _have_fatal_error = False
15
17 """Used to see if there was a recoverable error reported with
18 errors_log_recoverable_exception() or errors_log_recoverable_error().
19
20 Return value: True if errors_log_recoverable_exception() has been called;
21 False otherwise."""
22
23 global _have_recoverable_error
24 return _have_recoverable_error
25
27 """Records the presence of a recoverable error to the debug log
28 (see debuglog). This condition can be checked later with
29 errors_have_recoverable_error().
30
31 @domain: name of debug log domain
32 @msg: message to print to the debug log"""
33
34 global _have_recoverable_error
35 _have_recoverable_error = True
36 debuglog.debug_log (True, domain, "Got recoverable error: %s" % msg)
37
39 """Used to see if there was a fatal error reported with
40 errors_log_fatal_error().
41
42 Return value: True if errors_log_fatal_error() has been called;
43 False otherwise."""
44
45 global _have_fatal_error
46 return _have_fatal_error
47
49 """Records the presence of a fatal error to the debug log
50 (see debuglog). This condition can be checked later with
51 errors_have_fatal_error().
52
53 @domain: name of debug log domain
54 @msg: message to print to the debug log"""
55
56 global _have_fatal_error
57 _have_fatal_error = True
58 debuglog.debug_log (True, domain, "Got fatal error: %s" % msg)
59
61 """Reports the current exception to the debug log (see debuglog), and records
62 the presence of a recoverable error. This condition can be checked later
63 with errors_have_recoverable_error().
64
65 @domain: name of debug log domain
66 @msg: message to print to the debug log in addition to the current exception"""
67
68 errors_log_recoverable_error (domain, msg)
69 debuglog.debug_log_current_exception (domain)
70
72 """Used only from helper programs for Sabayon. First, this dumps the debug log
73 to stderr. Then, it exits the program with exit code utils.EXIT_CODE_NORMAL
74 if there were no recoverable errors during its execution, or with
75 utils.EXIT_CODE_RECOVERABLE if there were recoverable errors.
76
77 @log_config_filename: File to mention in the debug log as the source for its configuration
78
79 Return value: this function does not return, as it exits the program."""
80
81
82
83
84
85 debuglog.debug_log_dump_to_file (log_config_filename, sys.stderr)
86
87 if errors_have_recoverable_error ():
88 sys.exit (util.EXIT_CODE_RECOVERABLE)
89 else:
90 sys.exit (util.EXIT_CODE_NORMAL)
91
93 """Exits the program when a fatal exception has occurred. First, this logs the
94 current exception to the debug log. Then, it dumps the debug log to stderr
95 and exits the program with exit code util.EXIT_CODE_FATAL.
96
97 @domain: name of debug log domain
98 @log_config_filename: File to mention in the debug log as the source for its configuration
99
100 Return value: this function does not return, as it exits the program."""
101
102 debuglog.debug_log (True, domain, "Fatal exception! Exiting abnormally.")
103 debuglog.debug_log_current_exception (domain)
104 debuglog.debug_log_dump_to_file (log_config_filename, sys.stderr)
105 sys.exit (util.EXIT_CODE_FATAL)
106
108 """Used as a function decorator. You should prefix *all* your callbacks with this decorator:
109
110 @checked_callback ("domain")
111 def my_callback (...):
112 ...
113
114 If an uncaught exception happens in the callback, the decorator will catch the exception,
115 call errors.errors_log_fatal_error() to flag the presence of a fatal error, and it will
116 also exit the main loop. In turn, the main loop is expected to have this form:
117
118 gtk.main ()
119 if errors.errors_have_fatal_error ():
120 print "a fatal error occurred" # or anything else you want to do"""
121
122 def catch_exceptions (func):
123 def wrapper (*args, **kwargs):
124 try:
125 return func (*args, **kwargs)
126 except:
127 errors_log_fatal_error (domain, "Fatal exception in callback; exiting main loop")
128 debuglog.debug_log_current_exception (domain)
129 gtk.main_quit ()
130
131 wrapper.__name__ = func.__name__
132 wrapper.__doc__ = func.__doc__
133
134 return wrapper
135
136 return catch_exceptions
137