Author: dmeyer
Date: Thu Nov 2 15:08:41 2006
New Revision: 8530
Modified:
trunk/core/src/fxdparser.py
trunk/ui/src/audio/fxdhandler.py
trunk/ui/src/fxditem.py
trunk/ui/src/image/fxdhandler.py
trunk/ui/src/playlist.py
trunk/ui/src/video/fxdhandler.py
trunk/ui/src/video/interface.py
Log:
fxd parser cleanup
Modified: trunk/core/src/fxdparser.py
==============================================================================
--- trunk/core/src/fxdparser.py (original)
+++ trunk/core/src/fxdparser.py Thu Nov 2 15:08:41 2006
@@ -1,42 +1,97 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# fxdparser.py - Freevo FXD parser
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2006 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+# python imports
import os
import sys
+
+# kaa.base imports
import kaa.xml
from kaa.strutils import unicode_to_str
-class FXD(kaa.xml.Document):
-
- def __init__(self, filename):
- kaa.xml.Document.__init__(self, filename, 'freevo')
- self._filename = filename
- self._dirname = os.path.dirname(filename)
-
- def parse_content(self, node):
- title = node.getattr('title') or ''
- image = None
- info = {}
+class Element(object):
+ def __init__(self, dirname, node):
+ self._node = node
+ self.dirname = dirname
+ self.title = node.getattr('title') or ''
+ self.image = None
+ self.info = {}
for attr in node:
if attr.name == 'cover-img' and attr.content:
- image = os.path.join(self._dirname,
unicode_to_str(attr.content))
- if not os.path.isfile(image):
- image = None
+ self.image = os.path.join(dirname,
unicode_to_str(attr.content))
+ if not os.path.isfile(self.image):
+ self.image = None
continue
if attr.name == 'info':
for i in attr.children:
if i.type == 'element' and i.content:
- info[unicode_to_str(i.name)] = i.content
+ self.info[unicode_to_str(i.name)] = i.content
continue
- return (node.name, title, image, info, node)
+
+ def __iter__(self):
+ return self._node.__iter__()
+ def __getattr__(self, attr):
+ return getattr(self._node, attr)
+
+
+class FXD(kaa.xml.Document):
+ """
+ FXD file object.
+ """
+ def __init__(self, filename):
+ kaa.xml.Document.__init__(self, filename, 'freevo')
+ # Filename for the FXD file
+ self.filename = filename
+ # Directory of the FXD file
+ self.dirname = os.path.dirname(filename)
+
+
def get_content(self, node=None):
+ """
+ Get all elements of the node.
+ """
content = []
if node == None:
node = self
for c in node:
if c.type == 'element':
- content.append(self.parse_content(c))
+ content.append(Element(self.dirname, c))
return content
+
def get_content_types(self, node=None):
+ """
+ Get all element types of the node.
+ """
content = []
if node == None:
node = self
@@ -44,6 +99,3 @@
if c.type == 'element':
content.append(c.name)
return content
-
-# doc = FXD(sys.argv[1])
-# print doc.get_content()
Modified: trunk/ui/src/audio/fxdhandler.py
==============================================================================
--- trunk/ui/src/audio/fxdhandler.py (original)
+++ trunk/ui/src/audio/fxdhandler.py Thu Nov 2 15:08:41 2006
@@ -59,7 +59,7 @@
from audioitem import AudioItem
-def fxdhandler(name, title, image, info, node, parent, listing, dirname):
+def fxdhandler(node, parent, listing):
"""
parse audio specific stuff from fxd files
"""
Modified: trunk/ui/src/fxditem.py
==============================================================================
--- trunk/ui/src/fxditem.py (original)
+++ trunk/ui/src/fxditem.py Thu Nov 2 15:08:41 2006
@@ -60,36 +60,36 @@
log = logging.getLogger()
# the parser for fxd nodes
-callbacks = []
+_callbacks = []
def add_parser(types, node, callback):
"""
Add a node parser for fxd files.
"""
- callbacks.append((types, node, callback))
+ _callbacks.append((types, node, callback))
class Mimetype(plugin.MimetypePlugin):
"""
- class to handle fxd files in directories
+ Class to handle fxd files in directories
"""
def get(self, parent, listing):
"""
- return a list of items based on the listing
+ Return a list of items based on the listing
"""
fxd_files = listing.get('fxd')
if not fxd_files:
return []
- display_type = parent.display_type
- if display_type == 'tv':
- display_type = 'video'
+ type = parent.display_type
+ if type == 'tv':
+ type = 'video'
items = []
for fxd_file in fxd_files:
try:
doc = freevo.fxdparser.FXD(fxd_file.filename)
- items.extend(self._parse(doc, doc, parent, listing,
display_type))
+ items.extend(self._parse(doc, doc, parent, listing, type))
except:
log.exception("fxd file %s corrupt" % fxd_file.filename)
continue
@@ -98,32 +98,37 @@
def suffix(self):
"""
- return the list of suffixes this class handles
+ Return the list of suffixes this class handles
"""
return [ 'fxd' ]
def count(self, parent, listing):
"""
- return how many items will be build on files
+ Return how many items will be build on files
"""
return len(self.get(parent, listing))
def _parse(self, doc, node, parent, listing, display_type):
+ """
+ Internal parser function
+ """
items = []
- for name, title, image, info, node in doc.get_content(node):
- for types, tag, handler in callbacks:
- if tag == name and \
- (not display_type or not types or display_type in
types):
- i = handler(name, title, image, info, node, parent,
listing,
- doc._dirname)
+ for c in doc.get_content(node):
+ for types, tag, handler in _callbacks:
+ if display_type and types and not display_type in types:
+ # wrong type
+ continue
+ if tag == c.name:
+ i = handler(c, parent, listing)
if i is not None:
items.append(i)
- if name == 'container':
- c = Container(name, title, image, info, parent)
- c.items = self._parse(doc, node, c, listing, display_type)
- items.append(c)
+ if c.name == 'container':
+ con = Container(c.title, c.image, c.info, parent)
+ con.items = self._parse(doc, c, con, listing, display_type)
+ if con.items:
+ items.append(con)
return items
@@ -132,7 +137,7 @@
"""
a simple container containing for items parsed from the fxd
"""
- def __init__(self, name, title, image, info, parent):
+ def __init__(self, title, image, info, parent):
Item.__init__(self, parent)
self.items = []
self.name = title
Modified: trunk/ui/src/image/fxdhandler.py
==============================================================================
--- trunk/ui/src/image/fxdhandler.py (original)
+++ trunk/ui/src/image/fxdhandler.py Thu Nov 2 15:08:41 2006
@@ -68,7 +68,7 @@
from imageitem import ImageItem
-def fxdhandler(name, title, image, info, node, parent, listing, dirname):
+def fxdhandler(node, parent, listing):
"""
Parse image specific stuff from fxd files
"""
Modified: trunk/ui/src/playlist.py
==============================================================================
--- trunk/ui/src/playlist.py (original)
+++ trunk/ui/src/playlist.py Thu Nov 2 15:08:41 2006
@@ -487,7 +487,7 @@
return items
- def fxdhandler(self, name, title, image, info, node, parent, listing,
dirname):
+ def fxdhandler(self, node, parent, listing):
"""
parse playlist specific stuff from fxd files
@@ -511,7 +511,8 @@
continue
for file in c.children:
if file.name in ('file', 'directory'):
- filename = os.path.join(dirname,
unicode_to_str(file.content))
+ f = unicode_to_str(file.content)
+ filename = os.path.join(node.dirname, f)
query = kaa.beacon.query(filename=filename)
if file.name == 'directory':
recursive = file.getattr('recursive') == '1'
@@ -519,11 +520,11 @@
items.append(query)
# create playlist object
- pl = Playlist(title, items, parent, parent.display_type,
+ pl = Playlist(node.title, items, parent, parent.display_type,
random=node.getattr('random') == '1',
repeat=node.getattr('repeat') == '1')
- pl.image = image
- pl.info = info
+ pl.image = node.image
+ pl.info = node.info
return pl
Modified: trunk/ui/src/video/fxdhandler.py
==============================================================================
--- trunk/ui/src/video/fxdhandler.py (original)
+++ trunk/ui/src/video/fxdhandler.py Thu Nov 2 15:08:41 2006
@@ -75,7 +75,7 @@
# get logging object
log = logging.getLogger('video')
-def parse_movie(name, title, image, info, node, parent, listing, dirname):
+def parse_movie(node, parent, listing):
"""
Callback for VideoItem <movie>
"""
@@ -115,14 +115,14 @@
# multiple items based n the same file can have different info. Or maybe
# we just ignore this. In that case, the fxdinfo code will be replaced by
# an in beacon solution.
- item.fxdinfo = dict(info)
+ item.fxdinfo = dict(node.info)
- if title:
- item.set_name(title)
+ if node.title:
+ item.set_name(node.title)
# BEACON_FIXME: item.files.fxd_file = fxd.filename
- if image:
- item.image = image
+ if node.image:
+ item.image = node.image
# BEACON_FIXME: item.files.image = image
return item
Modified: trunk/ui/src/video/interface.py
==============================================================================
--- trunk/ui/src/video/interface.py (original)
+++ trunk/ui/src/video/interface.py Thu Nov 2 15:08:41 2006
@@ -64,7 +64,7 @@
# load the fxd part of video
fxditem.add_parser(['video'], 'movie', fxdhandler.parse_movie)
- fxditem.add_parser(['video'], 'disc-set', fxdhandler.parse_disc_set)
+ # fxditem.add_parser(['video'], 'disc-set', fxdhandler.parse_disc_set)
# update the database based on the current mimetypes
database.update()
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog