hi.
I was looking through the "Help Needed" page on the wiki and noticed
that you wanted to add logging support to mmpython. This patch does
just that.
Here are some highlights:
* There is one globabl logger used throughout the module. It is defined
in the top-level __init__.py file. Devs can get access to it by calling
"mmpython.get_logger()." This allows future developers to change the
default logging options in one place for the entire module.
* I took out all of the DEBUG variables.
* I used my own disgression to categorize errors as "debug, info,
error..." People may want to adjust those later on.
* I used logging's built in support for exceptions
* I modified mminfo to use optik (http://optik.sourceforge.net/) for
option parsing. I thought that it was a standard module, but I am not
so sure any more. I don't know your policy on external dependencies.
Anyway, I added it because it made it easier to add an option for the
logging destination. This was done as a proof of concept.
Bugs
* There was at least one place that tested DEBUG and valid. I just
removed the valid test for now, assuming that I would change the valid
flag to mmpython exceptions.
~Dan
--
Check out my blog: http://members.cox.net/dcasimiro/
? build
? logging.p0
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 23 Apr 2005 15:03:47 -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: __init__.py
===================================================================
RCS file: /cvsroot/mmpython/mmpython/__init__.py,v
retrieving revision 1.35
diff -u -r1.35 __init__.py
--- __init__.py 15 Oct 2004 09:02:11 -0000 1.35
+++ __init__.py 23 Apr 2005 15:03:47 -0000
@@ -93,6 +93,7 @@
from synchronizedobject import SynchronizedObject
_factory = None
+_log = None
def Factory():
global _factory
@@ -109,7 +110,28 @@
def gettype(mimetype,extensions):
f = Factory()
- return f.get(mimetype,extensions)
+ return f.get(mimetype,extensions)
+
+
+def get_logger():
+ '''
+ This function gives us one place to configure any default properties of
+ our logging object. mmpython should use this function to import the
+ logger. That way, we can change policy without having to update *all* of
+ the files
+ '''
+ global _log
+
+ # One-time init
+ try:
+ if _log == None:
+ import logging
+ _log = logging.getLogger('mmpython')
+ except:
+ _log = None
+ # Todo? Handle logger import error
+
+ return _log
# Okay Regular imports and code follow
@@ -169,7 +191,6 @@
USE_NETWORK = 1
-
def parse(filename, ext_only = 0):
"""
parse the file
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 23 Apr 2005 15:03:47 -0000
@@ -80,14 +80,7 @@
import urlparse
import traceback
import urllib
-
-DEBUG = 0
-
-try:
- DEBUG = int(os.environ['MMPYTHON_DEBUG'])
-except:
- pass
-
+import mmpython
def isurl(url):
@@ -112,36 +105,36 @@
"""
# Check extension as a hint
for e in self.extmap.keys():
- if DEBUG > 1: print "trying ext %s" % e
+ mmpython.get_logger().debug("trying ext %s" % e)
if file.name.lower().endswith(e.lower()):
- if DEBUG == 1: print "trying ext %s" % e
+ mmpython.get_logger().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()
+ mmpython.get_logger().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"
+ mmpython.get_logger().info('No Type found by Extension. Trying all')
for e in self.types:
- if DEBUG: print "Trying %s" % e[0]
+ mmpython.get_logger().debug('Trying %s' % e[0])
try:
file.seek(0,0)
t = e[3](file)
if t.valid:
- if DEBUG: print 'found'
+ mmpython.get_logger().debug('found')
return t
except:
- if DEBUG:
- traceback.print_exc()
- if DEBUG: print 'not found'
+ mmpython.get_logger().exception(
+ 'There was a problem seeking through the file')
+ mmpython.get_logger().debug('not found')
return None
@@ -168,7 +161,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]
+ mmpython.get_logger().debug('Trying %s' % e[0])
t = e[3](url)
if t.valid:
t.url = url
@@ -178,7 +171,7 @@
(scheme, location, path, query, fragment) = split
uhandle = urllib.urlopen(url)
mime = uhandle.info().gettype()
- print "Trying %s" % mime
+ mmpython.get_logger().debug("Trying %s" % mime)
if self.mimemap.has_key(mime):
t = self.mimemap[mime][3](file)
if t.valid: return t
@@ -213,7 +206,7 @@
are supported.
"""
for e in self.device_types:
- if DEBUG: print 'Trying %s' % e[0]
+ mmpython.get_logger().debug('Trying %s' % e[0])
t = e[3](devicename)
if t.valid:
t.url = 'file://%s' % os.path.abspath(devicename)
@@ -226,7 +219,7 @@
Create information from the directory.
"""
for e in self.directory_types:
- if DEBUG: print 'Trying %s' % e[0]
+ mmpython.get_logger().debug('Trying %s' % e[0])
t = e[3](dirname)
if t.valid:
return t
@@ -266,8 +259,7 @@
"""
register the parser to mmpython
"""
- if DEBUG > 0:
- print "%s registered" % mimetype
+ mmpython.get_logger().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 23 Apr 2005 15:03:47 -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()
+ 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 23 Apr 2005 15:03:47 -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 = get_logger()
+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 23 Apr 2005 15:03:48 -0000
@@ -174,23 +174,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()
+ mmpython.get_logger().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()
+ mmpython.get_logger().exception(
+ 'music: oops, mp3 tag parsing %s failed!' % file.name)
if not self.valid:
return
- if mediainfo.DEBUG > 1:
- print id3.tag.frames
+ mmpython.get_logger().debug(id3.tag.frames)
try:
if id3 and id3.tag:
for k in MP3_INFO_TABLE:
@@ -215,8 +210,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:
+ mmpython.get_logger().debug(f.__class__)
self.appendtable('id3v2', tab, 'en')
if id3.tag.frames['TCON']:
@@ -241,8 +236,7 @@
if id3:
self.length = id3.getPlayTime()
except:
- if mediainfo.DEBUG:
- traceback.print_exc()
+ mmpython.get_logger().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 23 Apr 2005 15:03:48 -0000
@@ -79,8 +79,8 @@
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)
+ mmpython.get_logger().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 23 Apr 2005 15:03:48 -0000
@@ -9,8 +9,6 @@
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 +23,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
+ mmpython.get_logger().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 23 Apr 2005 15:03:48 -0000
@@ -64,8 +64,7 @@
self.context = 'video'
self.offset = 0
- if mediainfo.DEBUG > 1:
- print 'trying buggy dvd detection'
+ mmpython.get_logger().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 23 Apr 2005 15:03:48 -0000
@@ -106,8 +106,8 @@
DiscInfo.__init__(self)
self.context = 'video'
self.offset = 0
- if mediainfo.DEBUG > 1:
- print 'trying lsdvd for scanning the disc'
+
+ mmpython.get_logger().info('trying lsdvd for scanning the disc')
if os.path.isdir(device):
self.valid = self.isDVDdir(device)
@@ -128,8 +128,7 @@
# badly mastered dvd
self.length = first
- if mediainfo.DEBUG > 1:
- print 'lsdvd detection ok'
+ mmpython.get_logger().info('lsdvd detection ok')
self.mime = 'video/dvd'
self.type = 'DVD'
@@ -220,8 +219,7 @@
LSDVD_EXE = os.path.join(path, 'lsdvd')
break
else:
- if mediainfo.DEBUG:
- print 'ImportError: lsdvd not found'
+ mmpython.get_logger().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 23 Apr 2005 15:03:48 -0000
@@ -38,13 +38,10 @@
import gzip
from xml.utils import qp_xml
-DEBUG = mediainfo.DEBUG
-
try:
import Image
except:
- if DEBUG:
- print 'Python Imaging not found'
+ mmpython.get_logger().exception('Python Imaging not found')
import bins
@@ -63,8 +60,8 @@
# if it's in desc it must be important
object.keys.append(key)
except Exception, e:
- if DEBUG:
- print e
+ mmpython.get_logger().exception( \
+ 'There was a problem reading the image information')
pass
comment_file = os.path.join(os.path.dirname(filename),
@@ -96,10 +93,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 = mmpython.get_logger()
+ 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 23 Apr 2005 15:03:48 -0000
@@ -35,14 +35,11 @@
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'
+ mmpython.get_logger().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 23 Apr 2005 15:03:49 -0000
@@ -118,11 +118,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 +150,7 @@
pass
- def _readatom(self, file):
-
+ def _readatom(self, file):
s = file.read(8)
if len(s) < 8:
return 0
@@ -164,8 +160,7 @@
# stop at nonsense data
return 0
- if mediainfo.DEBUG or ATOM_DEBUG:
- print "%s [%X]" % (atomtype,atomsize)
+ mmpython.get_logger().debug('%s [%X]' % (atomtype,atomsize))
if atomtype == 'udta':
# Userdata (Metadata)
@@ -197,7 +192,7 @@
self.appendtable('QTUDTA', i18ntabl[k], QTLANGUAGES[k])
self.appendtable('QTUDTA', tabl, QTLANGUAGES[k])
else:
- #print "NO i18"
+ mmpython.get_logger().info('NO i18')
self.appendtable('QTUDTA', tabl)
elif atomtype == 'trak':
@@ -225,13 +220,13 @@
self.date = int(tkhd[1]) - 2082844800
self.date = time.strftime('%y/%m/%d', time.gmtime(self.date))
except Exception, e:
- print 'ex', e
+ mmpython.get_logger().exception(
+ 'There was trouble extracting the date')
elif datatype == 'mdia':
pos += 8
datasize -= 8
- if ATOM_DEBUG:
- print '--> mdia information'
+ mmpython.get_logger().debug('--> mdia information')
while datasize:
mdia = struct.unpack('>I4s', atomdata[pos:pos+8])
@@ -274,29 +269,37 @@
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])
+ mmpython.get_logger().debug(' --> %s, %s' % mdia)
+ mmpython.get_logger().debug(
+ ' --> %s, %s (reference)' % dref)
- elif ATOM_DEBUG:
+ else:
if mdia[1].startswith('st'):
- print ' --> %s, %s (sample)' % mdia
+ mmpython.get_logger().debug(
+ ' --> %s, %s (sample)' % mdia)
elif mdia[1] in ('vmhd', 'smhd'):
- print ' --> %s, %s (media information header)' % mdia
+ mmpython.get_logger().debug(
+ ' --> %s, %s (media information header)' \
+ % mdia)
else:
- print ' --> %s, %s (unknown)' % mdia
+ mmpython.get_logger().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':
+ mmpython.get_logger().debug(
+ struct.unpack('>I4s', atomdata[:8]))
+ else:
if datatype == 'edts':
- print "--> %s [%d] (edit list)" % (datatype, datasize)
+ mmpython.get_logger().debug(
+ '--> %s [%d] (edit list)' % (datatype, datasize))
else:
- print "--> %s [%d] (unknown)" % (datatype, datasize)
+ mmpython.get_logger().debug(
+ '--> %s [%d] (unknown)' % (datatype, datasize))
pos += datasize
elif atomtype == 'mvhd':
@@ -326,8 +329,8 @@
try:
decompressed = zlib.decompress(data[4:])
except Exception, e:
- if mediainfo.DEBUG:
- print 'unable to decompress atom'
+ mmpython.get_logger().exception(
+ 'There was a proble decompressiong atom')
return atomsize
import StringIO
decompressedIO = StringIO.StringIO(decompressed)
@@ -335,8 +338,7 @@
pass
else:
- if mediainfo.DEBUG:
- print 'unknown compression %s' % method
+ mmpython.get_logger().info('unknown compression %s' % method)
# unknown compression method
file.seek(datasize-8,1)
@@ -348,18 +350,16 @@
elif atomtype == 'mdat':
pos = file.tell() + atomsize - 8
# maybe there is data inside the mdat
- if ATOM_DEBUG:
- print 'parsing mdat'
+ mmpython.get_logger().info('parsing mdat')
while self._readatom(file):
pass
- if ATOM_DEBUG:
- print 'end of mdat'
+ mmpython.get_logger().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'):
+ mmpython.get_logger().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 23 Apr 2005 15:03:49 -0000
@@ -212,8 +212,7 @@
else:
self.type = 'MPEG video'
- if mediainfo.DEBUG > 2:
- self.__scan__()
+ mmpython.get_logger().debug(self.__scan__())
def dxy(self,file):
@@ -240,8 +239,7 @@
try:
aspect = ASPECT_RATIO[v>>4]
except IndexError:
- if mediainfo.DEBUG:
- print 'Index error: %s' % (v>>4)
+ mmpython.get_logger().exception('Index error: %s' % (v>>4))
aspect = None
return (fps, aspect)
@@ -610,8 +608,7 @@
def isPES(self, file):
- if mediainfo.DEBUG:
- print 'trying mpeg-pes scan'
+ mmpython.get_logger().info('trying mpeg-pes scan')
file.seek(0,0)
buffer = file.read(3)
@@ -745,8 +742,8 @@
else:
# timestamp broken
del self.start
- if mediainfo.DEBUG:
- print 'Timestamp error, correcting'
+ mmpython.get_logger().warning(
+ 'Timestamp error, correcting')
if hasattr(self, 'start') and self.start and \
self.sequence_header_offset and self.video and self.audio:
@@ -876,8 +873,9 @@
"""
if not hasattr(self, 'filename') or not hasattr(self, 'start'):
return 0
+
file = open(self.filename)
- print 'scanning file...'
+ mmpython.get_logger().debug('scanning file...')
while 1:
file.seek(self.__seek_size__ * 10, 1)
buffer = file.read(self.__sample_size__)
@@ -886,12 +884,11 @@
pos = self.__search__(buffer)
if pos == -1:
continue
- print self.get_time(buffer[pos:])
+ mmpython.get_logger().debug(
+ 'buffer position: %s' % self.get_time(buffer[pos:]))
file.close()
- print 'done'
- print
-
+ mmpython.get_logger().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 23 Apr 2005 15:03:49 -0000
@@ -172,8 +172,7 @@
while self.parseRIFFChunk(file):
pass
except IOError:
- if mediainfo.DEBUG:
- print 'error in file, stop parsing'
+ mmpython.get_logger().exception('error in file, stop parsing')
self.find_subtitles(file.name)