1 |
commit: 89455e5de82d644e5b034642bacaac8338e8987a |
2 |
Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
3 |
AuthorDate: Mon Feb 21 11:38:41 2011 +0000 |
4 |
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
5 |
CommitDate: Thu Feb 24 06:49:58 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=89455e5d |
7 |
|
8 |
add an error callback function ability to pass errors to. |
9 |
|
10 |
--- |
11 |
layman/output.py | 20 +++++++++++++++----- |
12 |
1 files changed, 15 insertions(+), 5 deletions(-) |
13 |
|
14 |
diff --git a/layman/output.py b/layman/output.py |
15 |
index 05260ce..469f673 100644 |
16 |
--- a/layman/output.py |
17 |
+++ b/layman/output.py |
18 |
@@ -24,7 +24,8 @@ class MessageBase(object): |
19 |
err = sys.stderr, |
20 |
info_level = INFO_LEVEL, |
21 |
warn_level = WARN_LEVEL, |
22 |
- col = True |
23 |
+ col = True, |
24 |
+ error_callback=None |
25 |
): |
26 |
# Where should the error output go? This can also be a file |
27 |
self.error_out = err |
28 |
@@ -44,7 +45,9 @@ class MessageBase(object): |
29 |
|
30 |
self.debug_lev = OFF |
31 |
|
32 |
- self.has_error = False |
33 |
+ # callback function that gets passed any error messages |
34 |
+ # that have shown up. |
35 |
+ self.error_callback = error_callback |
36 |
|
37 |
|
38 |
def _color (self, col, text): |
39 |
@@ -73,6 +76,12 @@ class MessageBase(object): |
40 |
def set_debug_level(self, debugging_level = DEBUG_LEVEL): |
41 |
self.debug_lev = debugging_level |
42 |
|
43 |
+ def do_error_callback(self, error): |
44 |
+ """runs the error_callback function with the error |
45 |
+ that occurred |
46 |
+ """ |
47 |
+ if self.error_callback: |
48 |
+ self.error_callback(error) |
49 |
|
50 |
|
51 |
class Message(MessageBase): |
52 |
@@ -86,8 +95,9 @@ class Message(MessageBase): |
53 |
err = sys.stderr, |
54 |
info_level = INFO_LEVEL, |
55 |
warn_level = WARN_LEVEL, |
56 |
- col = True |
57 |
- ): |
58 |
+ col = True, |
59 |
+ error_callback = None |
60 |
+ ): |
61 |
|
62 |
MessageBase.__init__(self) |
63 |
|
64 |
@@ -170,7 +180,7 @@ class Message(MessageBase): |
65 |
sys.stdout.flush() |
66 |
print >> self.error_out, self.color_func('red', '* ') + i |
67 |
self.error_out.flush() |
68 |
- self.has_error = True |
69 |
+ self.do_error_callback(error) |
70 |
|
71 |
|
72 |
def die (self, error): |