aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <brian.dolbec@gmail.com>2011-02-21 03:38:41 -0800
committerBrian Dolbec <brian.dolbec@gmail.com>2011-02-23 22:49:58 -0800
commit89455e5de82d644e5b034642bacaac8338e8987a (patch)
treef905ceb469b063fad501314f57f7f3eb75ec4c2a /layman/output.py
parentChange most exceptions raised to output.errors(). (diff)
downloadlayman-89455e5de82d644e5b034642bacaac8338e8987a.tar.gz
layman-89455e5de82d644e5b034642bacaac8338e8987a.tar.bz2
layman-89455e5de82d644e5b034642bacaac8338e8987a.zip
add an error callback function ability to pass errors to.
Diffstat (limited to 'layman/output.py')
-rw-r--r--layman/output.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/layman/output.py b/layman/output.py
index 05260ce..469f673 100644
--- a/layman/output.py
+++ b/layman/output.py
@@ -24,7 +24,8 @@ class MessageBase(object):
err = sys.stderr,
info_level = INFO_LEVEL,
warn_level = WARN_LEVEL,
- col = True
+ col = True,
+ error_callback=None
):
# Where should the error output go? This can also be a file
self.error_out = err
@@ -44,7 +45,9 @@ class MessageBase(object):
self.debug_lev = OFF
- self.has_error = False
+ # callback function that gets passed any error messages
+ # that have shown up.
+ self.error_callback = error_callback
def _color (self, col, text):
@@ -73,6 +76,12 @@ class MessageBase(object):
def set_debug_level(self, debugging_level = DEBUG_LEVEL):
self.debug_lev = debugging_level
+ def do_error_callback(self, error):
+ """runs the error_callback function with the error
+ that occurred
+ """
+ if self.error_callback:
+ self.error_callback(error)
class Message(MessageBase):
@@ -86,8 +95,9 @@ class Message(MessageBase):
err = sys.stderr,
info_level = INFO_LEVEL,
warn_level = WARN_LEVEL,
- col = True
- ):
+ col = True,
+ error_callback = None
+ ):
MessageBase.__init__(self)
@@ -170,7 +180,7 @@ class Message(MessageBase):
sys.stdout.flush()
print >> self.error_out, self.color_func('red', '* ') + i
self.error_out.flush()
- self.has_error = True
+ self.do_error_callback(error)
def die (self, error):