summaryrefslogtreecommitdiffstats
path: root/layman/output.py
diff options
context:
space:
mode:
authorBrian Dolbec <brian.dolbec@gmail.com>2011-02-13 16:52:19 -0800
committerBrian Dolbec <brian.dolbec@gmail.com>2011-02-13 16:52:19 -0800
commit69ca817b92d78e91b03ee3e327b9e369c8f26e5a (patch)
tree07c738052174c33aeaddd9dc0ff357ab1a9d1a95 /layman/output.py
parentd308b929d9fb4a0c69d331079f9a8b3ebbb2164a (diff)
downloadlayman-69ca817b92d78e91b03ee3e327b9e369c8f26e5a.tar.gz
layman-69ca817b92d78e91b03ee3e327b9e369c8f26e5a.tar.bz2
layman-69ca817b92d78e91b03ee3e327b9e369c8f26e5a.zip
Split out MessageBase class, more code reduction/cleanup
Diffstat (limited to 'layman/output.py')
-rw-r--r--layman/output.py53
1 files changed, 38 insertions, 15 deletions
diff --git a/layman/output.py b/layman/output.py
index 5785d58..250ce96 100644
--- a/layman/output.py
+++ b/layman/output.py
@@ -12,15 +12,14 @@ __version__ = "0.1"
import sys, inspect, types
-from optparse import OptionGroup
+from optparse import OptionGroup
-from layman.constants import codes, INFO_LEVEL, WARN_LEVEL, OFF
+from layman.constants import codes, INFO_LEVEL, WARN_LEVEL, DEBUG_LEVEL, OFF
-
-class Message:
- #FIXME: Think about some simple doctests before you modify this class the
- # next time.
+class MessageBase(object):
+ """Base Message class helper functions and variables
+ """
def __init__(self,
out = sys.stdout,
@@ -29,7 +28,6 @@ class Message:
warn_level = WARN_LEVEL,
col = True
):
-
# Where should the error output go? This can also be a file
self.error_out = err
@@ -43,24 +41,27 @@ class Message:
self.info_lev = info_level
# Should the output be colored?
+ self.color_func = None
self.set_colorize(col)
+ self.debug_lev = OFF
+
self.has_error = False
- def color (self, col, text):
+ def _color (self, col, text):
return codes[col] + text + codes['reset']
- def no_color (self, col, text):
+ def _no_color (self, col, text):
return text
def set_colorize(self, state):
if state:
- self.color_func = self.color
+ self.color_func = self._color
else:
- self.color_func = self.no_color
+ self.color_func = self._no_color
def set_info_level(self, info_level = INFO_LEVEL):
@@ -71,10 +72,34 @@ class Message:
self.warn_lev = warn_level
+ def set_debug_level(self, debugging_level = DEBUG_LEVEL):
+ self.debug_lev = debugging_level
+
+
+
+class Message(MessageBase):
+ """Primary Message output methods
+ """
+ #FIXME: Think about some simple doctests before you modify this class the
+ # next time.
+
+ def __init__(self,
+ out = sys.stdout,
+ err = sys.stderr,
+ info_level = INFO_LEVEL,
+ warn_level = WARN_LEVEL,
+ col = True
+ ):
+
+ MessageBase.__init__(self)
+
+
## Output Functions
def debug(self, info, level = OFF):
- """empty debug function"""
+ """empty debug function, does nothing,
+ declared here for compatibility with DebugMessage
+ """
pass
@@ -84,8 +109,6 @@ class Message:
def info (self, info, level = INFO_LEVEL):
- #print "info =", info
-
if type(info) not in types.StringTypes:
info = str(info)
@@ -145,7 +168,7 @@ class Message:
for i in error.split('\n'):
# NOTE: Forced flushing ensures that stdout and stderr
# stay in nice order. This is a workaround for calls like
- # "overlord -L |& less".
+ # "layman -L |& less".
sys.stdout.flush()
print >> self.error_out, self.color_func('red', '* ') + i
self.error_out.flush()