[Fedora-livecd-list] [PATCH 2/3] Work with the logging settings when emitting progress.

James Laska jlaska at redhat.com
Wed Nov 24 16:33:41 UTC 2010


---
 imgcreate/yuminst.py |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/imgcreate/yuminst.py b/imgcreate/yuminst.py
index 9e54982..ea89ece 100644
--- a/imgcreate/yuminst.py
+++ b/imgcreate/yuminst.py
@@ -28,13 +28,21 @@ import pykickstart.parser
 from imgcreate.errors import *
 
 class TextProgress(object):
+    logger = logging.getLogger()
+    def emit(self, lvl, msg):
+        '''play nice with the logging module'''
+        for hdlr in self.logger.handlers:
+            if lvl >= self.logger.level:
+                hdlr.stream.write(msg)
+                hdlr.stream.flush()
+
     def start(self, filename, url, *args, **kwargs):
-        sys.stdout.write("Retrieving %s " % (url,))
+        self.emit(logging.INFO, "Retrieving %s " % (url,))
         self.url = url
     def update(self, *args):
         pass
     def end(self, *args):
-        sys.stdout.write("...OK\n")
+        self.emit(logging.INFO, "...OK\n")
 
 class LiveCDYum(yum.YumBase):
     def __init__(self):
-- 
1.7.3.2



More information about the livecd mailing list