aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2012-06-06 21:42:27 -0700
committerBrian Dolbec <dolsen@gentoo.org>2012-06-06 21:42:27 -0700
commitafb17b0a5bef67fa51e92373fd5043ac27f4c8f2 (patch)
tree031d99ec3920b8ff4d4f6b8b60d3dc85792d2fd9
parentset some sane defaults for stdout, stderr, stdin. (diff)
downloadlayman-afb17b0a5bef67fa51e92373fd5043ac27f4c8f2.tar.gz
layman-afb17b0a5bef67fa51e92373fd5043ac27f4c8f2.tar.bz2
layman-afb17b0a5bef67fa51e92373fd5043ac27f4c8f2.zip
Tighten up the code to prevent exceptions and tracebacks if stdout and stderr are not of the file type.
-rw-r--r--layman/output.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/layman/output.py b/layman/output.py
index 2fbeaaf..c90fccc 100644
--- a/layman/output.py
+++ b/layman/output.py
@@ -29,10 +29,16 @@ class MessageBase(object):
error_callback=None
):
# Where should the error output go? This can also be a file
- self.error_out = err
+ if isinstance(err, file):
+ self.error_out = err
+ else:
+ raise Exception("MessageBase: input parameter 'err' must be of type: file")
# Where should the normal output go? This can also be a file
- self.std_out = out
+ if isinstance(out, file):
+ self.std_out = out
+ else:
+ raise Exception("MessageBase: input parameter 'out' must be of type: file")
# The higher the level the more information you will get
self.warn_lev = warn_level
@@ -187,10 +193,10 @@ class Message(MessageBase):
# NOTE: Forced flushing ensures that stdout and stderr
# stay in nice order. This is a workaround for calls like
# "layman -L |& less".
- sys.stdout.flush()
+ self.std_out.flush()
self.error_out.flush()
print >> self.std_out, " %s %s" % (self.color_func('red', '*'), i)
- sys.stdout.flush()
+ self.std_out.flush()
self.do_error_callback(error)