allow installing from multiple directories
[enigma2.git] / lib / python / Components / DreamInfoHandler.py
index cc07160..858b99a 100644 (file)
@@ -31,7 +31,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"]:
+               if name in ["hardware", "bcastsystem", "satellite", "tag"]:
                        if not attrs.has_key("type"):
                                        self.printError(str(name) + " tag with no type attribute")
                        if self.elements[-3] == "default":
@@ -97,9 +97,17 @@ class DreamInfoHandler:
        STATUS_ERROR = 2
        STATUS_INIT = 4
        
-       def __init__(self, statusCallback):
+       def __init__(self, statusCallback, blocking = False, neededTag = None):
                self.directory = "/"
                
+               self.neededTag = neededTag
+               
+               # 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.get().append(self.installNext)
                
@@ -107,7 +115,7 @@ class DreamInfoHandler:
                self.setStatus(self.STATUS_INIT)
                                
                self.packageslist = []
-       
+                       
        def readInfo(self, directory, file):
                print "Reading .info file", file
                handler = InfoHandler(self.prerequisiteMet, directory)
@@ -122,7 +130,13 @@ class DreamInfoHandler:
        # prerequisites = True: give only packages matching the prerequisites
        def fillPackagesList(self, prerequisites = True):
                self.packageslist = []
-               packages = crawlDirectory(self.directory, ".*\.info$")
+               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])
                        
@@ -136,6 +150,18 @@ class DreamInfoHandler:
                # TODO: we need to implement a hardware detection here...
                print "prerequisites:", prerequisites
                met = True
+               if self.neededTag is None:
+                       if prerequisites.has_key("tag"):
+                               return False
+               else:
+                       if prerequisites.has_key("tag"):
+                               if not self.neededTag in prerequisites["tag"]:
+                                       return False
+                               
+               if prerequisites.has_key("satellite"):
+                       for sat in prerequisites["satellite"]:
+                               if int(sat) not in nimmanager.getConfiguredSats():
+                                       return False                            
                if prerequisites.has_key("bcastsystem"):
                        for bcastsystem in prerequisites["bcastsystem"]:
                                if nimmanager.hasNimType(bcastsystem):
@@ -146,7 +172,17 @@ class DreamInfoHandler:
                                # TODO: hardware detection
                                met = True
                return True
-                       
+       
+       def installPackages(self, indexes):
+               print "installing packages", indexes
+               if len(indexes) == 0:
+                       self.setStatus(self.STATUS_DONE)
+                       return
+               self.installIndexes = indexes
+               print "+++++++++++++++++++++++bla"
+               self.currentlyInstallingMetaIndex = 0
+               self.installPackage(self.installIndexes[self.currentlyInstallingMetaIndex])
+
        def installPackage(self, index):
                print "installing package with index", index, "and name", self.packageslist[index][0]["attributes"]["name"]
                
@@ -164,10 +200,18 @@ class DreamInfoHandler:
        def installNext(self, *args, **kwargs):
                self.currentIndex += 1
                attributes = self.installingAttributes
+               #print "attributes:", attributes
                
-               if self.currentAttributeIndex >= len(self.attributeNames): # end reached
-                       self.setStatus(self.STATUS_DONE)
-                       return
+               if self.currentAttributeIndex >= len(self.attributeNames): # end of package reached
+                       print "end of package reached"
+                       if self.currentlyInstallingMetaIndex is None or self.currentlyInstallingMetaIndex >= len(self.installIndexes) - 1:
+                               print "set status to DONE"
+                               self.setStatus(self.STATUS_DONE)
+                               return
+                       else:
+                               print "increment meta index to install next package"
+                               self.currentlyInstallingMetaIndex += 1
+                               self.installPackage(self.installIndexes[self.currentlyInstallingMetaIndex])
                
                self.setStatus(self.STATUS_WORKING)             
                
@@ -182,6 +226,7 @@ class DreamInfoHandler:
                                self.installNext()
                                return
                else: # nothing to install here
+                       self.currentIndex = -1
                        self.currentAttributeIndex += 1
                        self.installNext()
                        return
@@ -221,9 +266,13 @@ class DreamInfoHandler:
                self.installNext()
                
        def installIPK(self, directory, name):
-               self.ipkg = IpkgComponent()
-               self.ipkg.addCallback(self.ipkgCallback)
-               self.ipkg.startCmd(IpkgComponent.CMD_INSTALL, {'package': directory + name})
+               if self.blocking:
+                       os.system("ipkg install " + directory + name)
+                       self.installNext()
+               else:
+                       self.ipkg = IpkgComponent()
+                       self.ipkg.addCallback(self.ipkgCallback)
+                       self.ipkg.startCmd(IpkgComponent.CMD_INSTALL, {'package': directory + name})
                
        def ipkgCallback(self, event, param):
                print "ipkgCallback"
@@ -235,22 +284,30 @@ class DreamInfoHandler:
        def installSkin(self, directory, name):
                print "installing skin:", directory, " - ", name
                print "cp -a %s %s" % (directory, resolveFilename(SCOPE_SKIN))
-               if self.console.execute("cp -a %s %s" % (directory, resolveFilename(SCOPE_SKIN))):
-                       print "execute failed"
+               if self.blocking:
+                       os.system("cp -a %s %s" % (directory, resolveFilename(SCOPE_SKIN)))
                        self.installNext()
+               else:
+                       if self.console.execute("cp -a %s %s" % (directory, resolveFilename(SCOPE_SKIN))):
+                               print "execute failed"
+                               self.installNext()
 
        def mergeServices(self, directory, name, merge = False):
                print "merging services:", directory, " - ", name
-               
-               db = eDVBDB.getInstance()
-               db.reloadServicelist()
-               db.loadServicelist(directory + name)
-               db.saveServicelist()
+               if os.path.isfile(directory + name):
+                       db = eDVBDB.getInstance()
+                       db.reloadServicelist()
+                       db.loadServicelist(directory + name)
+                       db.saveServicelist()
                self.installNext()
 
        def installFavourites(self, directory, name):
                print "installing favourites:", directory, " - ", name
 
-               if self.console.execute("cp %s %s" % ((directory + name), resolveFilename(SCOPE_CONFIG))):
-                       print "execute failed"
+               if self.blocking:
+                       os.system("cp %s %s" % ((directory + name), resolveFilename(SCOPE_CONFIG)))
                        self.installNext()
+               else:
+                       if self.console.execute("cp %s %s" % ((directory + name), resolveFilename(SCOPE_CONFIG))):
+                               print "execute failed"
+                               self.installNext()