Author: dmeyer
Date: Mon Feb 13 19:40:50 2006
New Revision: 1175
Modified:
trunk/metadata/TODO
trunk/metadata/src/image/core.py
trunk/metadata/src/mediainfo.py
trunk/metadata/src/misc/dirinfo.py
Log:
Cleanup by using modules provied by kaa.base
Modified: trunk/metadata/TODO
==============================================================================
--- trunk/metadata/TODO (original)
+++ trunk/metadata/TODO Mon Feb 13 19:40:50 2006
@@ -14,3 +14,6 @@
Create doc in the Wiki and dump it into the doc subdir
Add list of external files kaa.vfs should know about
+
+Move some code from mediainfo to media/core.py See image/core.py was
+example.
Modified: trunk/metadata/src/image/core.py
==============================================================================
--- trunk/metadata/src/image/core.py (original)
+++ trunk/metadata/src/image/core.py Mon Feb 13 19:40:50 2006
@@ -33,11 +33,11 @@
import os
import gzip
import logging
-import libxml2
# kaa imports
from kaa.metadata import factory
from kaa.metadata import mediainfo
+from kaa.base import libxml2
# get logging object
log = logging.getLogger('metadata')
@@ -71,8 +71,15 @@
"""
Parse external files like bins and .comments.
"""
- self.parse_bins(filename)
- self.parse_dot_comment(filename)
+ try:
+ self.parse_bins(filename)
+ except:
+ log.exception('parse_bins')
+ try:
+ self.parse_dot_comment(filename)
+ except:
+ log.exception('parse_dot_comment')
+
def parse_bins(self, filename):
"""
@@ -81,19 +88,15 @@
binsxml = filename + '.xml'
if not os.path.isfile(binsxml):
return
- for node in libxml2.parseFile(binsxml).children:
- if not node.name == 'description':
+ xml = libxml2.Document(binsxml, 'image')
+ for child in xml.get_child('description').children:
+ key = str(child.getattr('name'))
+ if not key or not child.content:
continue
- for child in node.children:
- if not child.name == 'field':
- continue
- value = unicode(child.getContent(), 'utf-8').strip()
- key = child.prop('name')
- if key and value:
- self[key] = value
- if not key in ATTRIBUTES + mediainfo.MEDIACORE:
- # if it's in desc it must be important
- self.keys.append(key)
+ self[key] = child.content
+ if not key in ATTRIBUTES + mediainfo.MEDIACORE:
+ # if it's in desc it must be important
+ self.keys.append(key)
def parse_dot_comment(self, filename):
@@ -104,14 +107,9 @@
os.path.basename(filename) + '.xml')
if not os.path.isfile(comment_file):
return
- for node in libxml2.parseFile(comment_file).children:
- if not node.name == 'Comment':
- continue
- for child in node.children:
- value = unicode(child.getContent(), 'utf-8')
- if not value or value == '0':
- continue
- if child.name == 'Place':
- self.location = value
- if child.name == 'Note':
- self.description = value
+ xml = libxml2.Document(comment_file, 'Comment')
+ for child in xml.children:
+ if child.name == 'Place':
+ self.location = child.content
+ if child.name == 'Note':
+ self.description = child.content
Modified: trunk/metadata/src/mediainfo.py
==============================================================================
--- trunk/metadata/src/mediainfo.py (original)
+++ trunk/metadata/src/mediainfo.py Mon Feb 13 19:40:50 2006
@@ -4,9 +4,6 @@
# -----------------------------------------------------------------------------
# $Id$
#
-# TODO: move some code from mediainfo to media/core.py
-# See image/core.py was example.
-#
# -----------------------------------------------------------------------------
# kaa-Metadata - Media Metadata for Python
# Copyright (C) 2003-2005 Thomas Schueppel, Dirk Meyer
@@ -36,14 +33,12 @@
import os
import logging
import copy
-import locale
# kaa imports
-import table
+from kaa.base.strutils import str_to_unicode
-LOCAL_ENCODING = locale.getpreferredencoding();
-if not LOCAL_ENCODING or LOCAL_ENCODING == "ANSI_X3.4-1968":
- LOCAL_ENCODING = 'latin1';
+# kaa metadata imports
+import table
UNPRINTABLE_KEYS = [ 'thumbnail', 'raw_image']
@@ -168,7 +163,7 @@
for key in self.keys:
value = getattr(self, key)
if isinstance(value, str) and not key in UNPRINTABLE_KEYS:
- setattr(self, key, unicode(value, LOCAL_ENCODING, 'replace'))
+ setattr(self, key, str_to_unicode(value))
def gettable(self, name, language='en'):
Modified: trunk/metadata/src/misc/dirinfo.py
==============================================================================
--- trunk/metadata/src/misc/dirinfo.py (original)
+++ trunk/metadata/src/misc/dirinfo.py Mon Feb 13 19:40:50 2006
@@ -34,10 +34,11 @@
# python imports
import os
import logging
-import libxml2
# kaa imports
+from kaa.base import decorator
from kaa.base.strutils import unicode_to_str
+from kaa.base import libxml2
from kaa.metadata.mediainfo import MediaInfo, MEDIACORE, \
EXTENSION_DIRECTORY, TYPE_MISC
from kaa.metadata.factory import register
@@ -54,8 +55,14 @@
MediaInfo.__init__(self)
self.media = 'directory'
- self.parse_dot_directory(directory)
- self.parse_bins(directory)
+ try:
+ self.parse_dot_directory(directory)
+ except:
+ log.exception('parse_dot_directory')
+ try:
+ self.parse_bins(directory)
+ except:
+ log.exception('parse_bins')
def parse_dot_directory(self, directory):
@@ -83,25 +90,22 @@
if not os.path.isfile(binsxml):
return
- for node in libxml2.parseFile(binsxml).children:
- if not node.name == 'description':
+ xml = libxml2.Document(binsxml, 'album')
+ for child in xml.get_child('description').children:
+ key = str(child.getattr('name'))
+ if not key or not child.content:
continue
- for child in node.children:
- if not child.name == 'field':
+ if key == 'sampleimage':
+ image = os.path.join(directory, unicode_to_str(child.content))
+ if not os.path.isfile(image):
continue
- value = unicode(child.getContent(), 'utf-8').strip()
- key = child.prop('name')
- if key and value:
- if key == 'sampleimage':
- image = os.path.join(directory, unicode_to_str(value))
- if os.path.isfile(image):
- self.image = image
- self.keys.append('image')
- else:
- self[key] = value
- if not key in MEDIACORE:
- # if it's in desc it must be important
- self.keys.append(key)
+ self.image = image
+ self.keys.append('image')
+ continue
+ self[key] = child.content
+ if not key in MEDIACORE:
+ # if it's in desc it must be important
+ self.keys.append(key)
# register to kaa.metadata core
register('directory', EXTENSION_DIRECTORY, TYPE_MISC, DirInfo)
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog