Here is an updated version of the patch to address the concern you
mentioned below.  I basically replaced all the "get_logger()" calls with
"logging.getLogger('mmpython')"

~Dan


On Wed, 2005-04-27 at 10:04 +0200, Dirk Meyer wrote:

> IIRC you don't need that. A logger has a name. So when all files use
> the logger 'mmpython' you can change that. The code you have in
> __init__ doing that is more or less in the logging module itself. 
> 

-- 
Check out my blog: http://members.cox.net/dcasimiro/
Index: TODO
===================================================================
RCS file: /cvsroot/mmpython/mmpython/TODO,v
retrieving revision 1.1
diff -u -r1.1 TODO
--- TODO	16 Apr 2005 15:06:28 -0000	1.1
+++ TODO	1 May 2005 13:14:59 -0000
@@ -5,7 +5,6 @@
 o Cleanup: 
   - create smaller header (see freevo)
   - use freevo coding style
-  - use python logging module
   - remove the valid variable and replace it by an exception on error
 o Move base objects into the different subdirs
 o Dynamic loading without importing everything from __init__
Index: factory.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/factory.py,v
retrieving revision 1.20
diff -u -r1.20 factory.py
--- factory.py	29 May 2004 12:30:36 -0000	1.20
+++ factory.py	1 May 2005 13:14:59 -0000
@@ -80,14 +80,8 @@
 import urlparse
 import traceback
 import urllib
-
-DEBUG = 0
-
-try:
-    DEBUG = int(os.environ['MMPYTHON_DEBUG'])
-except:
-    pass
-
+import mmpython
+import logging
 
 
 def isurl(url):
@@ -112,36 +106,36 @@
         """
         # Check extension as a hint
         for e in self.extmap.keys():
-            if DEBUG > 1: print "trying ext %s" % e
+            logging.getLogger('mmpython').debug("trying ext %s" % e)
             if file.name.lower().endswith(e.lower()):
-                if DEBUG == 1: print "trying ext %s" % e
+                logging.getLogger('mmpython').debug("trying ext %s" % e)
                 try:
                     file.seek(0,0)
                     t = self.extmap[e][3](file)
                     if t.valid: return t
                 except:
-                    if DEBUG:
-                        traceback.print_exc()
+                    logging.getLogger('mmpython').exception(
+                        'There was a problem seeking through file.')
+                      
 
         # no searching on all types
         if ext_only:
             return None
 
-        if DEBUG:
-            print "No Type found by Extension. Trying all"
+        logging.getLogger('mmpython').info('No Type found by Extension. Trying all')
 
         for e in self.types:
-            if DEBUG: print "Trying %s" % e[0]
+            logging.getLogger('mmpython').debug('Trying %s' % e[0])
             try:
                 file.seek(0,0)
                 t = e[3](file)
                 if t.valid:
-                    if DEBUG: print 'found'
+                    logging.getLogger('mmpython').debug('found')
                     return t
             except:
-                if DEBUG:
-                    traceback.print_exc()
-        if DEBUG: print 'not found'
+                logging.getLogger('mmpython').exception(
+                    'There was a problem seeking through the file')
+        logging.getLogger('mmpython').debug('not found')
         return None
 
 
@@ -168,7 +162,7 @@
             # method for this. Perhaps move file.open stuff into __init__
             # instead of doing it here...
             for e in self.stream_types:
-                if DEBUG: print 'Trying %s' % e[0]
+                logging.getLogger('mmpython').debug('Trying %s' % e[0])
                 t = e[3](url)
                 if t.valid:
                     t.url = url
@@ -178,7 +172,7 @@
             (scheme, location, path, query, fragment) = split
             uhandle = urllib.urlopen(url)
             mime = uhandle.info().gettype()
-            print "Trying %s" % mime
+            logging.getLogger('mmpython').debug("Trying %s" % mime)
             if self.mimemap.has_key(mime):
                 t = self.mimemap[mime][3](file)
                 if t.valid: return t
@@ -213,7 +207,7 @@
         are supported.
         """
         for e in self.device_types:
-            if DEBUG: print 'Trying %s' % e[0]
+            logging.getLogger('mmpython').debug('Trying %s' % e[0])
             t = e[3](devicename)
             if t.valid:
                 t.url = 'file://%s' % os.path.abspath(devicename)
@@ -226,7 +220,7 @@
         Create information from the directory.
         """
         for e in self.directory_types:
-            if DEBUG: print 'Trying %s' % e[0]
+            logging.getLogger('mmpython').debug('Trying %s' % e[0])
             t = e[3](dirname)
             if t.valid:
                 return t
@@ -266,8 +260,7 @@
         """
         register the parser to mmpython
         """
-        if DEBUG > 0:
-            print "%s registered" % mimetype
+        logging.getLogger('mmpython').debug('%s registered' % mimetype)
         tuple = (mimetype,extensions,type,c)
 
         if extensions == mediainfo.EXTENSION_DEVICE:
Index: mediainfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/mediainfo.py,v
retrieving revision 1.68
diff -u -r1.68 mediainfo.py
--- mediainfo.py	16 Apr 2005 15:01:15 -0000	1.68
+++ mediainfo.py	1 May 2005 13:14:59 -0000
@@ -112,22 +112,16 @@
 EXTENSION_DIRECTORY = 'directory'
 EXTENSION_STREAM    = 'stream'
 
-DEBUG = 0
-
-try:
-    DEBUG = int(os.environ['MMPYTHON_DEBUG'])
-except:
-    pass
-
 def _debug(text):
     """
     Function for debug prints of MediaItem implementations.
     """
-    if DEBUG > 1:
-        try:
-            print text
-        except:
-            print text.encode('latin-1', 'replace')
+    import logging
+    log = logging.getLogger('mmpython')
+    try:
+        log.debug(text)
+    except:
+        log.debug(text.encode('latin-1', 'replace'))
     
 
 class MediaInfo:
@@ -160,15 +154,17 @@
         result = u''
         result += reduce( lambda a,b: self[b] and b != u'url' and u'%s\n        %s: %s' % \
                          (a, unicode(b), unicode(self[b])) or a, keys, u'' )
-        if DEBUG:
-            try:
-                for i in self._tables.keys():
-                    try:
-                        result += unicode(self._tables[i])
-                    except AttributeError:
-                        pass
-            except AttributeError:
-                pass
+        # I am not sure what this piece of code does...
+        # So, I am commenting it out in the interim
+        #if DEBUG:
+        #    try:
+        #        for i in self._tables.keys():
+        #            try:
+        #                result += unicode(self._tables[i])
+        #            except AttributeError:
+        #                pass
+        #    except AttributeError:
+        #        pass
         return result
         
 
Index: mminfo
===================================================================
RCS file: /cvsroot/mmpython/mmpython/mminfo,v
retrieving revision 1.4
diff -u -r1.4 mminfo
--- mminfo	28 May 2004 12:26:24 -0000	1.4
+++ mminfo	1 May 2005 13:14:59 -0000
@@ -48,35 +48,66 @@
 
 
 print 'mmpython media info'
-
-if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'):
-    print
-    print 'usage: mminfo [options] files'
-    print
-    print 'options:'
-    print '  -d   turn on debug information. For complete debug set -d 2'
-    print
-    print 'A file can be a normal file, a device for VCD/VCD/AudioCD'
-    print
-    print 'Examples:'
-    print '  mminfo foo.avi bar.mpg'
-    print '  mminfo /dev/dvd'
-    print
-    sys.exit(0)
-
 # turn on debug
-if sys.argv[1] == '-d':
-    try:
-        int(sys.argv[2])
-        os.environ['MMPYTHON_DEBUG'] = sys.argv[2]
-        sys.argv = sys.argv[2:]
-    except:
-        os.environ['MMPYTHON_DEBUG'] = '1'
-        sys.argv = sys.argv[1:]
-    
 from mmpython import *
+import version
+import logging
+logger = logging.getLogger('mmpython')
+formatter = logging.Formatter(
+    '(%(name)-8s|%(asctime)s) %(levelname)-5s::msg= %(message)s')
+
+import optik
+usage = 'usage: %prog [options] files\n' + \
+        'A file can be a normal file, a device for VCD/VCD/AudioCD\n\n' + \
+        'Examples:\n' + \
+        '\tmminfo foo.avi bar.mpg\n' + \
+        '\tmminfo /dev/dvd\n'
+parser = optik.OptionParser(usage=usage, version='%prog ' + version.VERSION)
+parser.add_option('-l', '--log',
+                  action='store', type='string', dest='logfilename',
+                  default=None,
+                  help='Send log output to given file', metavar='FILE')
 
-for file in sys.argv[1:]:
+helptext = 'Set output level of logger.  The recognized levels are: ' + \
+           '[NONE|DEBUG|INFO|WARNING|ERROR|CRITICAL]'
+parser.add_option('-d', '--debug',
+                  action='store', dest='debug', default='WARNING',
+                  metavar='LEVEL',
+                  help=helptext)
+
+
+(options, args) = parser.parse_args()
+
+try:
+    # enable debug messages by setting level...
+    level = options.debug.upper()
+    if level is 'NONE':
+        logger.setLevel(0)
+    elif level == 'INFO':
+        logger.setLevel(logging.INFO)
+    elif level == 'DEBUG':
+        logger.setLevel(logging.DEBUG)
+    elif level == 'WARNING':
+        logger.setLevel(logging.WARNING)
+    elif level == 'ERROR':
+        logger.setLevel(logging.ERROR)
+    elif level == 'CRITICAL':
+        logger.setLevel(logging.CRITICAL)
+    else:
+        raise ValueError('%s is an unknown level')
+except:
+    print 'There was a problem setting the debug level'
+
+hdlr = None
+if options.logfilename:
+    hdlr = logging.FileHandler(options.logfilename)
+else:
+    hdlr = logging.StreamHandler()
+
+hdlr.setFormatter(formatter)
+logger.addHandler(hdlr)
+
+for file in args:
     medium = parse(file)
     print
     if len(file) > 70:
@@ -89,3 +120,5 @@
         print
     else:
         print "No Match found"
+
+logging.shutdown()
Index: audio/eyed3info.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/audio/eyed3info.py,v
retrieving revision 1.16
diff -u -r1.16 eyed3info.py
--- audio/eyed3info.py	1 Jan 2005 14:18:11 -0000	1.16
+++ audio/eyed3info.py	1 May 2005 13:15:00 -0000
@@ -100,6 +100,7 @@
 from eyeD3 import frames as eyeD3_frames
 
 import os
+import logging
 import struct
 import traceback
 import id3 as id3info
@@ -174,23 +175,18 @@
          except:
             # The MP3 tag decoder crashed, assume the file is still
             # MP3 and try to play it anyway
-            if mediainfo.DEBUG:
-               print 'music: oops, mp3 tag parsing failed!'
-               print 'music: filename = "%s"' % file.name
-               traceback.print_exc()
+            logging.getLogger('mmpython').exception( \
+               'music: oops, mp3 tag parsing %s failed!' % file.name)
       except:
          # The MP3 tag decoder crashed, assume the file is still
          # MP3 and try to play it anyway
-         if mediainfo.DEBUG:
-            print 'music: oops, mp3 tag parsing failed!'
-            print 'music: filename = "%s"' % file.name
-            traceback.print_exc()
+         logging.getLogger('mmpython').exception(
+            'music: oops, mp3 tag parsing %s failed!' % file.name)
 
       if not self.valid:
          return
 
-      if mediainfo.DEBUG > 1:
-         print id3.tag.frames
+      logging.getLogger('mmpython').debug(id3.tag.frames)
       try:
          if id3 and id3.tag:
             for k in MP3_INFO_TABLE:
@@ -215,8 +211,8 @@
                     tab[f.header.id] = f.url
                 elif f.__class__ is eyeD3_frames.UserURLFrame:
                     tab[f.header.id] = f.url
-                elif mediainfo.DEBUG:
-                   print f.__class__
+                else:
+                   logging.getLogger('mmpython').debug(f.__class__)
             self.appendtable('id3v2', tab, 'en')
 
             if id3.tag.frames['TCON']:
@@ -241,8 +237,7 @@
          if id3:
             self.length = id3.getPlayTime()
       except:
-         if mediainfo.DEBUG:
-            traceback.print_exc()
+         logging.getLogger('mmpython').debug(traceback.print_exc())
       offset, header = self._find_header(file)
       if offset == -1 or header is None:
          return
Index: audio/flacinfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/audio/flacinfo.py,v
retrieving revision 1.7
diff -u -r1.7 flacinfo.py
--- audio/flacinfo.py	5 Oct 2003 21:06:24 -0000	1.7
+++ audio/flacinfo.py	1 May 2005 13:15:00 -0000
@@ -63,6 +63,7 @@
 import mmpython
 import struct
 import re
+import logging
 
 # See: http://flac.sourceforge.net/format.html
 
@@ -79,8 +80,9 @@
             lastblock = (blockheader >> 31) & 1
             type = (blockheader >> 24) & 0x7F
             numbytes = blockheader & 0xFFFFFF
-            if mmpython.mediainfo.DEBUG:
-                print "Last?: %d, NumBytes: %d, Type: %d" % (lastblock, numbytes, type)                                
+            logging.getLogger('mmpython').debug( \
+                "Last?: %d, NumBytes: %d, Type: %d" % \
+                (lastblock, numbytes, type))
             # Read this blocks the data
             data = file.read(numbytes)
             if type == 0:
Index: audio/m4ainfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/audio/m4ainfo.py,v
retrieving revision 1.8
diff -u -r1.8 m4ainfo.py
--- audio/m4ainfo.py	27 Sep 2004 14:54:37 -0000	1.8
+++ audio/m4ainfo.py	1 May 2005 13:15:00 -0000
@@ -6,11 +6,10 @@
 #
 
 import struct
+import logging
 from mmpython import mediainfo
 import mmpython
 
-#_print = mediainfo._debug
-
 class Mpeg4(mediainfo.MusicInfo):
     def __init__(self, file):
         self.containerTags = ('moov', 'udta', 'trak', 'mdia', 'minf', 'dinf', 'stbl',
@@ -25,12 +24,9 @@
                 self.readNextTag(file)
             except ValueError:
                 returnval = 1
-        if mediainfo.DEBUG and self.valid:
-            print self.title
-            print self.artist
-            print self.album
-            print self.year
-            print self.encoder
+        logging.getLogger('mmpython').debug(
+            'title: %s\nartist: %s\nalbum: %s\nyear: %s\nencoder: %s\n' % \
+            (self.title, self.artist, self.album, self.year, self.encoder))
 
     def readNextTag(self, file):
         length, name = self.readInt(file), self.read(4, file)
Index: disc/dvdinfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/disc/dvdinfo.py,v
retrieving revision 1.18
diff -u -r1.18 dvdinfo.py
--- disc/dvdinfo.py	13 Jan 2005 20:20:20 -0000	1.18
+++ disc/dvdinfo.py	1 May 2005 13:15:00 -0000
@@ -26,6 +26,7 @@
 
 
 import os
+import logging
 import ifoparser
 from mmpython import mediainfo
 import mmpython
@@ -64,8 +65,7 @@
         self.context = 'video'
         self.offset = 0
 
-        if mediainfo.DEBUG > 1:
-            print 'trying buggy dvd detection'
+        logging.getLogger('mmpython').info('trying buggy dvd detection')
 
         if isinstance(device, file):
             self.valid = self.isDVDiso(device)
Index: disc/lsdvd.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/disc/lsdvd.py,v
retrieving revision 1.13
diff -u -r1.13 lsdvd.py
--- disc/lsdvd.py	13 Jan 2005 20:19:34 -0000	1.13
+++ disc/lsdvd.py	1 May 2005 13:15:00 -0000
@@ -35,6 +35,7 @@
 
 
 import os
+import logging
 from mmpython import mediainfo
 import mmpython
 from discinfo import DiscInfo
@@ -106,8 +107,8 @@
         DiscInfo.__init__(self)
         self.context = 'video'
         self.offset = 0
-        if mediainfo.DEBUG > 1:
-            print 'trying lsdvd for scanning the disc'
+
+        logging.getLogger('mmpython').info('trying lsdvd for scanning the disc')
 
         if os.path.isdir(device):
             self.valid = self.isDVDdir(device)
@@ -128,8 +129,7 @@
                 # badly mastered dvd
                 self.length = first
 
-            if mediainfo.DEBUG > 1:
-                print 'lsdvd detection ok'
+            logging.getLogger('mmpython').info('lsdvd detection ok')
             
         self.mime    = 'video/dvd'
         self.type    = 'DVD'
@@ -220,8 +220,7 @@
             LSDVD_EXE = os.path.join(path, 'lsdvd')
             break
     else:
-        if mediainfo.DEBUG:
-            print 'ImportError: lsdvd not found'
+        logging.getLogger('mmpython').error('ImportError: lsdvd not found')
         raise ImportError
 
 mmpython.registertype( 'video/dvd', mediainfo.EXTENSION_DEVICE,
Index: image/ImageInfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/image/ImageInfo.py,v
retrieving revision 1.2
diff -u -r1.2 ImageInfo.py
--- image/ImageInfo.py	16 Apr 2005 15:01:53 -0000	1.2
+++ image/ImageInfo.py	1 May 2005 13:15:00 -0000
@@ -36,15 +36,13 @@
 
 import os
 import gzip
+import logging
 from xml.utils import qp_xml
 
-DEBUG = mediainfo.DEBUG
-
 try:
     import Image
 except:
-    if DEBUG:
-        print 'Python Imaging not found'
+    logging.getLogger('mmpython').exception('Python Imaging not found')
 
 import bins
 
@@ -63,8 +61,8 @@
                     # if it's in desc it must be important
                     object.keys.append(key)
         except Exception, e:
-            if DEBUG:
-                print e
+            logging.getLogger('mmpython').exception( \
+                'There was a problem reading the image information')
             pass
 
     comment_file = os.path.join(os.path.dirname(filename),
@@ -96,10 +94,12 @@
     if i.info.has_key('dpi'):
         object['dpi'] = '%sx%s' % i.info['dpi']
 
-    if DEBUG:
-        for info in i.info:
-            if not info == 'exif':
-                print '%s: %s' % (info, i.info[info])
+    # This for loop used to live within a conditional block
+    # not sure how to do that with the logger class just yet.
+    logger = logging.getLogger('mmpython')
+    for info in i.info:
+        if not info == 'exif':
+            logger.debug('%s: %s' % (info, i.info[info]))
 
     object.mode = i.mode
     if not object.height:
Index: misc/xmlinfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/misc/xmlinfo.py,v
retrieving revision 1.2
diff -u -r1.2 xmlinfo.py
--- misc/xmlinfo.py	24 May 2004 10:50:48 -0000	1.2
+++ misc/xmlinfo.py	1 May 2005 13:15:00 -0000
@@ -35,14 +35,12 @@
 import mmpython
 from mmpython import mediainfo
 
-DEBUG = mediainfo.DEBUG
-
 try:
     # XML support
     from xml.utils import qp_xml
 except:
-    if DEBUG:
-        print 'Python XML not found'
+    import logging
+    logging.getLogger('mmpython').exception('Python XML not found')
 
 
 XML_TAG_INFO = {
Index: video/movinfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/video/movinfo.py,v
retrieving revision 1.24
diff -u -r1.24 movinfo.py
--- video/movinfo.py	14 Jul 2004 13:42:57 -0000	1.24
+++ video/movinfo.py	1 May 2005 13:15:00 -0000
@@ -106,6 +106,7 @@
 # -----------------------------------------------------------------------
 #endif
 
+import logging
 import re
 import struct
 import string
@@ -118,11 +119,8 @@
 
 # http://developer.apple.com/documentation/QuickTime/QTFF/index.html
 
-ATOM_DEBUG = 0
-
-if mediainfo.DEBUG > 1:
-    ATOM_DEBUG = 1
-    
+# Note: May need to define custom log level to work like ATOM_DEBUG did here
+ 
 class MovInfo(mediainfo.AVInfo):
     def __init__(self,file):
         mediainfo.AVInfo.__init__(self)
@@ -153,8 +151,7 @@
             pass
 
 
-    def _readatom(self, file):
-        
+    def _readatom(self, file):        
         s = file.read(8)
         if len(s) < 8:
             return 0
@@ -164,8 +161,7 @@
             # stop at nonsense data
             return 0
 
-        if mediainfo.DEBUG or ATOM_DEBUG:
-            print "%s [%X]" % (atomtype,atomsize)
+        logging.getLogger('mmpython').debug('%s [%X]' % (atomtype,atomsize))
 
         if atomtype == 'udta':
             # Userdata (Metadata)
@@ -197,7 +193,7 @@
                         self.appendtable('QTUDTA', i18ntabl[k], QTLANGUAGES[k])
                         self.appendtable('QTUDTA', tabl, QTLANGUAGES[k])
             else:
-                #print "NO i18"
+                logging.getLogger('mmpython').info('NO i18')
                 self.appendtable('QTUDTA', tabl)
              
         elif atomtype == 'trak':
@@ -225,13 +221,13 @@
                         self.date = int(tkhd[1]) - 2082844800
                         self.date = time.strftime('%y/%m/%d', time.gmtime(self.date))
                     except Exception, e:
-                        print 'ex', e
+                        logging.getLogger('mmpython').exception(
+                            'There was trouble extracting the date')
                     
                 elif datatype == 'mdia':
                     pos      += 8
                     datasize -= 8
-                    if ATOM_DEBUG:
-                        print '--> mdia information'
+                    logging.getLogger('mmpython').debug('--> mdia information')
 
                     while datasize:
                         mdia = struct.unpack('>I4s', atomdata[pos:pos+8])
@@ -274,29 +270,38 @@
                                     info = None
 
                         elif mdia[1] == 'dinf':
-                            dref = struct.unpack('>I4s', atomdata[pos+8:pos+8+8])
-                            if ATOM_DEBUG:
-                                print '  --> %s, %s' % mdia
-                                print '    --> %s, %s (reference)' % dref
+                            dref = struct.unpack('>I4s',
+                                                 atomdata[pos+8:pos+8+8])
+                            logging.getLogger('mmpython').debug( \
+                                '  --> %s, %s' % mdia)
+                            logging.getLogger('mmpython').debug(
+                                '    --> %s, %s (reference)' % dref)
                             
-                        elif ATOM_DEBUG:
+                        else:
                             if mdia[1].startswith('st'):
-                                print '  --> %s, %s (sample)' % mdia
+                                logging.getLogger('mmpython').debug(
+                                    '  --> %s, %s (sample)' % mdia)
                             elif mdia[1] in ('vmhd', 'smhd'):
-                                print '  --> %s, %s (media information header)' % mdia
+                                logging.getLogger('mmpython').debug(
+                                    '  --> %s, %s (media information header)' \
+                                    % mdia)
                             else:
-                                print '  --> %s, %s (unknown)' % mdia
+                                logging.getLogger('mmpython').debug(
+                                    '  --> %s, %s (unknown)' % mdia)
 
                         pos      += mdia[0]
                         datasize -= mdia[0]
 
-                elif datatype == 'udta' and ATOM_DEBUG:
-                    print struct.unpack('>I4s', atomdata[:8])
-                elif ATOM_DEBUG:
+                elif datatype == 'udta':
+                    logging.getLogger('mmpython').debug(
+                        struct.unpack('>I4s', atomdata[:8]))
+                else:
                     if datatype == 'edts':
-                        print "--> %s [%d] (edit list)" % (datatype, datasize)
+                        logging.getLogger('mmpython').debug(
+                            '--> %s [%d] (edit list)' % (datatype, datasize))
                     else:
-                        print "--> %s [%d] (unknown)" % (datatype, datasize)
+                        logging.getLogger('mmpython').debug(
+                            '--> %s [%d] (unknown)' % (datatype, datasize))
                 pos += datasize
 
         elif atomtype == 'mvhd':
@@ -326,8 +331,8 @@
                     try:
                         decompressed = zlib.decompress(data[4:])
                     except Exception, e:
-                        if mediainfo.DEBUG:
-                            print 'unable to decompress atom'
+                        logging.getLogger('mmpython').exception(
+                            'There was a proble decompressiong atom')
                         return atomsize
                 import StringIO
                 decompressedIO = StringIO.StringIO(decompressed)
@@ -335,8 +340,8 @@
                     pass
                 
             else:
-                if mediainfo.DEBUG:
-                    print 'unknown compression %s' % method
+                logging.getLogger('mmpython').info('unknown compression %s' \
+                                                   % method)
                 # unknown compression method
                 file.seek(datasize-8,1)
         
@@ -348,18 +353,17 @@
         elif atomtype == 'mdat':
             pos = file.tell() + atomsize - 8
             # maybe there is data inside the mdat
-            if ATOM_DEBUG:
-                print 'parsing mdat'
+            logging.getLogger('mmpython').info('parsing mdat')
             while self._readatom(file):
                 pass
-            if ATOM_DEBUG:
-                print 'end of mdat'
+            logging.getLogger('mmpython').info('end of mdat')
             file.seek(pos, 0)
             
         
         else:
-            if ATOM_DEBUG and not atomtype in ('wide', 'free'):
-                print 'unhandled base atom %s' % atomtype
+            if not atomtype in ('wide', 'free'):
+                logging.getLogger('mmpython').info('unhandled base atom %s' \
+                                                   % atomtype)
 
             # Skip unknown atoms
             try:
Index: video/mpeginfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/video/mpeginfo.py,v
retrieving revision 1.33
diff -u -r1.33 mpeginfo.py
--- video/mpeginfo.py	15 Feb 2005 18:52:51 -0000	1.33
+++ video/mpeginfo.py	1 May 2005 13:15:01 -0000
@@ -70,6 +70,7 @@
 # -----------------------------------------------------------------------
 #endif
 
+import logging
 import re
 import os
 import struct
@@ -212,8 +213,7 @@
                 else:
                     self.type = 'MPEG video'
 
-            if mediainfo.DEBUG > 2:
-                self.__scan__()
+            logging.getLogger('mmpython').debug(self.__scan__())
 
             
     def dxy(self,file):  
@@ -240,8 +240,7 @@
         try:
             aspect = ASPECT_RATIO[v>>4]
         except IndexError:
-            if mediainfo.DEBUG:
-                print 'Index error: %s' % (v>>4)
+            logging.getLogger('mmpython').exception('Index error: %s' % (v>>4))
             aspect = None
         return (fps, aspect)
         
@@ -610,8 +609,7 @@
 
 
     def isPES(self, file):
-        if mediainfo.DEBUG:
-            print 'trying mpeg-pes scan'
+        logging.getLogger('mmpython').info('trying mpeg-pes scan')
         file.seek(0,0)
         buffer = file.read(3)
 
@@ -745,8 +743,8 @@
                         else:
                             # timestamp broken
                             del self.start
-                            if mediainfo.DEBUG:
-                                print 'Timestamp error, correcting'
+                            logging.getLogger('mmpython').warning(
+                                'Timestamp error, correcting')
                             
             if hasattr(self, 'start') and self.start and \
                    self.sequence_header_offset and self.video and self.audio:
@@ -876,8 +874,9 @@
         """
         if not hasattr(self, 'filename') or not hasattr(self, 'start'):
             return 0
+
         file = open(self.filename)
-        print 'scanning file...'
+        logging.getLogger('mmpython').debug('scanning file...')
         while 1:
             file.seek(self.__seek_size__ * 10, 1)
             buffer = file.read(self.__sample_size__)
@@ -886,12 +885,11 @@
             pos = self.__search__(buffer)
             if pos == -1:
                 continue
-            print self.get_time(buffer[pos:])
+            logging.getLogger('mmpython').debug(
+                'buffer position: %s' % self.get_time(buffer[pos:]))
 
         file.close()
-        print 'done'
-        print
-
+        logging.getLogger('mmpython').debug('done scanning file')
     
     
 mmpython.registertype( 'video/mpeg', ('mpeg','mpg','mp4', 'ts'), mediainfo.TYPE_AV, MpegInfo )
Index: video/riffinfo.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/video/riffinfo.py,v
retrieving revision 1.33
diff -u -r1.33 riffinfo.py
--- video/riffinfo.py	15 Mar 2005 17:50:45 -0000	1.33
+++ video/riffinfo.py	1 May 2005 13:15:01 -0000
@@ -110,6 +110,7 @@
 # -----------------------------------------------------------------------
 #endif
 
+import logging
 import re
 import struct
 import string
@@ -172,8 +173,8 @@
             while self.parseRIFFChunk(file):
                 pass
         except IOError:
-            if mediainfo.DEBUG:
-                print 'error in file, stop parsing'
+            logging.getLogger('mmpython').exception( \
+                'error in file, stop parsing')
 
         self.find_subtitles(file.name)
         

Reply via email to