Move the reusable ConsoleStyleFile and StyleWriter classes into
authorZac Medico <zmedico@gentoo.org>
Sat, 15 Dec 2007 21:32:25 +0000 (21:32 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 15 Dec 2007 21:32:25 +0000 (21:32 -0000)
the ouput module.

svn path=/main/trunk/; revision=8934

bin/repoman
pym/portage/output.py

index 9c7fae637eb79f8c7ed05df76458d2ecbcd5a4fd..1f80ed435176b3c4e166629db44d93b3db0273f9 100755 (executable)
@@ -68,6 +68,7 @@ from portage.process import find_binary, spawn
 from portage.util import initialize_logger
 from portage.output import bold, create_color_func, darkgreen, \
        green, nocolor, red, turquoise, yellow
+from portage.output import ConsoleStyleFile, StyleWriter
 
 initialize_logger()
 
@@ -425,58 +426,6 @@ def get_commit_message_with_stdin():
        commitmessage = "".join(commitmessage)
        return commitmessage
 
-class ConsoleStyleFile(object):
-       """
-       A file-like object that behaves something like the
-       portage.output.colorize() function. Style identifiers
-       passed in via the new_styles() method will be used to
-       apply console codes to output.
-       """
-       from portage.output import codes as _codes
-       def __init__(self, f):
-               self._file = f
-               self._styles = None
-               self.write_listener = None
-
-       def new_styles(self, styles):
-               self._styles = styles
-
-       def write(self, s):
-               if self._styles:
-                       for style in self._styles:
-                               self._file.write(self._codes[style])
-                       self._file.write(s)
-                       self._file.write(self._codes["reset"])
-               else:
-                       self._file.write(s)
-               if self.write_listener:
-                       self.write_listener.write(s)
-
-       def writelines(self, lines):
-               for s in lines:
-                       self.write(s)
-
-       def flush(self):
-               self._file.flush()
-
-       def close(self):
-               self._file.close()
-
-class StyleWriter(formatter.DumbWriter):
-       """
-       This is just a DumbWriter with a hook in the new_styles() method
-       that passes a styles tuple as a single argument to a callable
-       style_listener attribute.
-       """
-       def __init__(self, **kwargs):
-               formatter.DumbWriter.__init__(self, **kwargs)
-               self.style_listener = None
-
-       def new_styles(self, styles):
-               formatter.DumbWriter.new_styles(self, styles)
-               if self.style_listener:
-                       self.style_listener(styles)
-
 def format_qa_output(f, stats, fails, dofull, dofail):
        full = options.mode in ("full", "lfull")
        for x in qacats:
index 9eae2ee87bb9e3a3ae92bc1ec5ed9b30da728063..148fddd0fdb7d09b60fd4061caec399bb0815c80 100644 (file)
@@ -6,6 +6,7 @@ __docformat__ = "epytext"
 
 import commands
 import errno
+import formatter
 import os
 import re
 import shlex
@@ -314,6 +315,57 @@ def create_color_func(color_key):
 for c in compat_functions_colors:
        globals()[c] = create_color_func(c)
 
+class ConsoleStyleFile(object):
+       """
+       A file-like object that behaves something like
+       the colorize() function. Style identifiers
+       passed in via the new_styles() method will be used to
+       apply console codes to output.
+       """
+       def __init__(self, f):
+               self._file = f
+               self._styles = None
+               self.write_listener = None
+
+       def new_styles(self, styles):
+               self._styles = styles
+
+       def write(self, s):
+               if self._styles:
+                       for style in self._styles:
+                               self._file.write(codes[style])
+                       self._file.write(s)
+                       self._file.write(codes["reset"])
+               else:
+                       self._file.write(s)
+               if self.write_listener:
+                       self.write_listener.write(s)
+
+       def writelines(self, lines):
+               for s in lines:
+                       self.write(s)
+
+       def flush(self):
+               self._file.flush()
+
+       def close(self):
+               self._file.close()
+
+class StyleWriter(formatter.DumbWriter):
+       """
+       This is just a DumbWriter with a hook in the new_styles() method
+       that passes a styles tuple as a single argument to a callable
+       style_listener attribute.
+       """
+       def __init__(self, **kwargs):
+               formatter.DumbWriter.__init__(self, **kwargs)
+               self.style_listener = None
+
+       def new_styles(self, styles):
+               formatter.DumbWriter.new_styles(self, styles)
+               if self.style_listener:
+                       self.style_listener(styles)
+
 def get_term_size():
        """
        Get the number of lines and columns of the tty that is connected to