DreamInfoHandler.py: strip data. refs #578
[enigma2.git] / lib / python / Components / DreamInfoHandler.py
index 25397feb48260db796e6f50fb427d9c3325c7986..03d52157c98f73b73033590a30bfda85541cc861 100755 (executable)
@@ -7,6 +7,7 @@ from Components.config import config, configfile
 from Tools.HardwareInfo import HardwareInfo
 from enigma import eConsoleAppContainer, eDVBDB
 import os
+from re import compile as re_compile, search as re_search, IGNORECASE
 
 class InfoHandlerParseError(Exception):
        def __init__(self, value):
@@ -15,7 +16,7 @@ class InfoHandlerParseError(Exception):
                return repr(self.value)
 
 class InfoHandler(xml.sax.ContentHandler):
-       def __init__(self, prerequisiteMet, directory, language = None):
+       def __init__(self, prerequisiteMet, directory):
                self.attributes = {}
                self.directory = directory
                self.list = []
@@ -25,9 +26,7 @@ class InfoHandler(xml.sax.ContentHandler):
                self.validFileTypes = ["skin", "config", "services", "favourites", "package"]
                self.prerequisitesMet = prerequisiteMet
                self.data = ""
-               self.languagedata = ""
-               self.language = language
-               
+
        def printError(self, error):
                print "Error in defaults xml files:", error
                raise InfoHandlerParseError, error
@@ -35,6 +34,7 @@ class InfoHandler(xml.sax.ContentHandler):
        def startElement(self, name, attrs):
                #print name, ":", attrs.items()
                self.elements.append(name)
+
                if name in ("hardware", "bcastsystem", "satellite", "tag", "flag"):
                        if not attrs.has_key("type"):
                                        self.printError(str(name) + " tag with no type attribute")
@@ -45,6 +45,11 @@ class InfoHandler(xml.sax.ContentHandler):
                        if not prerequisites.has_key(name):
                                prerequisites[name] = []
                        prerequisites[name].append(str(attrs["type"]))
+
+               if name == "info":
+                       self.foundTranslation = None
+                       self.data = ""
+
                if name == "files":
                        if attrs.has_key("type"):
                                if attrs["type"] == "directories":
@@ -52,6 +57,7 @@ class InfoHandler(xml.sax.ContentHandler):
                                elif attrs["type"] == "package":
                                        self.attributes["filestype"] = "package"
                                # TODO add a compressed archive type
+
                if name == "file":
                        self.prerequisites = {}
                        if not attrs.has_key("type"):
@@ -73,18 +79,20 @@ class InfoHandler(xml.sax.ContentHandler):
                        if attrs.has_key("details"):
                                self.attributes["details"] = str(attrs["details"])
                        if attrs.has_key("name"):
-                               self.attributes["name"] = str(attrs["name"].encode("utf-8"))
+                               self.attributes["name"] = str(attrs["name"])
                        if attrs.has_key("packagename"):
-                               self.attributes["packagename"] = str(attrs["packagename"].encode("utf-8"))
+                               self.attributes["packagename"] = str(attrs["packagename"])
+                       if attrs.has_key("packagetype"):
+                               self.attributes["packagetype"] = str(attrs["packagetype"])
                        if attrs.has_key("shortdescription"):
-                               self.attributes["shortdescription"] = str(attrs["shortdescription"].encode("utf-8"))
+                               self.attributes["shortdescription"] = str(attrs["shortdescription"])
 
                if name == "screenshot":
                        if attrs.has_key("src"):
                                self.attributes["screenshot"] = str(attrs["src"])
 
        def endElement(self, name):
-               #print "end", name
+               #print "endElement", name
                #print "self.elements:", self.elements
                self.elements.pop()
                if name == "file":
@@ -111,49 +119,41 @@ class InfoHandler(xml.sax.ContentHandler):
                if self.elements[-1] == "name":
                        self.attributes["name"] = str(data)
                if self.elements[-1] == "packagename":
-                       self.attributes["packagename"] = str(data.encode("utf-8"))
+                       self.attributes["packagename"] = str(data)
                if self.elements[-1] == "shortdescription":
-                       self.attributes["shortdescription"] = str(data.encode("utf-8"))
+                       self.attributes["shortdescription"] = str(data)
                if self.elements[-1] == "description":
                        self.data += data.strip()
-                       self.attributes["description"] = str(self.data.encode("utf-8"))
-               if self.language is not None:
-                       if self.elements[-1] == ("name_" + str(self.language)):
-                               self.attributes["name"] = str(data.encode("utf-8"))
-                       if self.elements[-1] == ("shortdescription_" + str(self.language)):
-                               self.attributes["shortdescription"] = str(data.encode("utf-8"))
-                       if self.elements[-1] == ("description_" + str(self.language)):
-                               self.languagedata += data.strip()
-                               self.attributes["description"] = str(self.languagedata.encode("utf-8"))
+                       self.attributes["description"] = str(self.data)
                #print "characters", data
-               
+
+
 class DreamInfoHandler:
        STATUS_WORKING = 0
        STATUS_DONE = 1
        STATUS_ERROR = 2
        STATUS_INIT = 4
-       
-       def __init__(self, statusCallback, blocking = False, neededTag = None, neededFlag = None, language = None):
+
+       def __init__(self, statusCallback, blocking = False, neededTag = None, neededFlag = None):
                self.hardware_info = HardwareInfo()
                self.directory = "/"
-               
+
                self.neededTag = neededTag
                self.neededFlag = neededFlag
-               self.language = language
-               
+
                # caution: blocking should only be used, if further execution in enigma2 depends on the outcome of
                # the installer!
                self.blocking = blocking
-               
+
                self.currentlyInstallingMetaIndex = None
-               
+
                self.console = eConsoleAppContainer()
                self.console.appClosed.append(self.installNext)
                self.reloadFavourites = False
-               
+
                self.statusCallback = statusCallback
                self.setStatus(self.STATUS_INIT)
-                               
+
                self.packageslist = []
                self.packagesIndexlist = []
                self.packageDetails = []
@@ -167,11 +167,11 @@ class DreamInfoHandler:
                                self.packageslist.append((entry,file)) 
                except InfoHandlerParseError:
                        print "file", file, "ignored due to errors in the file"
-               print handler.list
+               #print handler.list
 
        def readIndex(self, directory, file):
-               print "Reading .xml meta index file", file
-               handler = InfoHandler(self.prerequisiteMet, directory, self.language)
+               print "Reading .xml meta index file", directory, file
+               handler = InfoHandler(self.prerequisiteMet, directory)
                try:
                        xml.sax.parse(file, handler)
                        for entry in handler.list:
@@ -181,8 +181,9 @@ class DreamInfoHandler:
                #print handler.list
 
        def readDetails(self, directory, file):
+               self.packageDetails = []
                print "Reading .xml meta details file", file
-               handler = InfoHandler(self.prerequisiteMet, directory, self.language)
+               handler = InfoHandler(self.prerequisiteMet, directory)
                try:
                        xml.sax.parse(file, handler)
                        for entry in handler.list:
@@ -197,13 +198,13 @@ class DreamInfoHandler:
                packages = []
                if not isinstance(self.directory, list):
                        self.directory = [self.directory]
-               
+
                for directory in self.directory:
                        packages += crawlDirectory(directory, ".*\.info$")
 
                for package in packages:
                        self.readInfo(package[0] + "/", package[0] + "/" + package[1])
-                       
+
                if prerequisites:
                        for package in self.packageslist[:]:
                                if not self.prerequisiteMet(package[0]["prerequisites"]):
@@ -213,13 +214,22 @@ class DreamInfoHandler:
        # prerequisites = True: give only packages matching the prerequisites
        def fillPackagesIndexList(self, prerequisites = True):
                self.packagesIndexlist = []
-               if self.language is not None:
-                       indexfile = 'index_' + self.language + '.xml'
-               else:
-                       indexfile = 'index.xml'
+               indexfileList = []
+
                if not isinstance(self.directory, list):
                        self.directory = [self.directory]
-               self.readIndex(self.directory[0] + "/", self.directory[0] + "/" + indexfile)
+
+               for indexfile in os.listdir(self.directory[0]):
+                       if indexfile.startswith("index-"):
+                               if indexfile.endswith(".xml"):
+                                       if indexfile[-7:-6] == "_":
+                                               continue
+                                       indexfileList.append(indexfile)
+               if len(indexfileList):
+                       for file in indexfileList:
+                               neededFile = self.directory[0] + "/" + file
+                               if os.path.isfile(neededFile):
+                                       self.readIndex(self.directory[0] + "/" , neededFile)
 
                if prerequisites:
                        for package in self.packagesIndexlist[:]: