1 |
commit: afb17b0a5bef67fa51e92373fd5043ac27f4c8f2 |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Jun 7 04:42:27 2012 +0000 |
4 |
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
5 |
CommitDate: Thu Jun 7 04:42:27 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=afb17b0a |
7 |
|
8 |
Tighten up the code to prevent exceptions and tracebacks if stdout and stderr are not of the file type. |
9 |
|
10 |
--- |
11 |
layman/output.py | 14 ++++++++++---- |
12 |
1 files changed, 10 insertions(+), 4 deletions(-) |
13 |
|
14 |
diff --git a/layman/output.py b/layman/output.py |
15 |
index 2fbeaaf..c90fccc 100644 |
16 |
--- a/layman/output.py |
17 |
+++ b/layman/output.py |
18 |
@@ -29,10 +29,16 @@ class MessageBase(object): |
19 |
error_callback=None |
20 |
): |
21 |
# Where should the error output go? This can also be a file |
22 |
- self.error_out = err |
23 |
+ if isinstance(err, file): |
24 |
+ self.error_out = err |
25 |
+ else: |
26 |
+ raise Exception("MessageBase: input parameter 'err' must be of type: file") |
27 |
|
28 |
# Where should the normal output go? This can also be a file |
29 |
- self.std_out = out |
30 |
+ if isinstance(out, file): |
31 |
+ self.std_out = out |
32 |
+ else: |
33 |
+ raise Exception("MessageBase: input parameter 'out' must be of type: file") |
34 |
|
35 |
# The higher the level the more information you will get |
36 |
self.warn_lev = warn_level |
37 |
@@ -187,10 +193,10 @@ class Message(MessageBase): |
38 |
# NOTE: Forced flushing ensures that stdout and stderr |
39 |
# stay in nice order. This is a workaround for calls like |
40 |
# "layman -L |& less". |
41 |
- sys.stdout.flush() |
42 |
+ self.std_out.flush() |
43 |
self.error_out.flush() |
44 |
print >> self.std_out, " %s %s" % (self.color_func('red', '*'), i) |
45 |
- sys.stdout.flush() |
46 |
+ self.std_out.flush() |
47 |
self.do_error_callback(error) |