diff options
author | Brian Dolbec <dolsen@gentoo.org> | 2012-06-06 21:42:27 -0700 |
---|---|---|
committer | Brian Dolbec <dolsen@gentoo.org> | 2012-06-06 21:42:27 -0700 |
commit | afb17b0a5bef67fa51e92373fd5043ac27f4c8f2 (patch) | |
tree | 031d99ec3920b8ff4d4f6b8b60d3dc85792d2fd9 | |
parent | 15fd9944117dcc90f0f297aac4f6fcbb7d9e2f95 (diff) | |
download | layman-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.py | 14 |
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) |