import xml.sax
-from Tools.Directories import crawlDirectory, resolveFilename, SCOPE_CONFIG, SCOPE_SKIN
+from Tools.Directories import crawlDirectory, resolveFilename, SCOPE_CONFIG, SCOPE_SKIN, copyfile, copytree
from Components.NimManager import nimmanager
from Components.Ipkg import IpkgComponent
from Components.config import config, configfile
+from Tools.HardwareInfo import HardwareInfo
from enigma import eConsoleAppContainer, eDVBDB
import os
self.elements = []
self.validFileTypes = ["skin", "config", "services", "favourites", "package"]
self.prerequisitesMet = prerequisiteMet
-
-
+
def printError(self, error):
print "Error in defaults xml files:", error
raise InfoHandlerParseError, error
def startElement(self, name, attrs):
- print name, ":", attrs.items()
+ #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":
self.filetype = type
self.fileattrs = attrs
def endElement(self, name):
- print "end", name
- print "self.elements:", self.elements
+ #print "end", name
+ #print "self.elements:", self.elements
self.elements.pop()
if name == "file":
- print "prerequisites:", self.prerequisites
+ #print "prerequisites:", self.prerequisites
if len(self.prerequisites) == 0 or self.prerequisitesMet(self.prerequisites):
if not self.attributes.has_key(self.filetype):
self.attributes[self.filetype] = []
self.attributes["author"] = str(data)
if self.elements[-1] == "name":
self.attributes["name"] = str(data)
- print "characters", data
+ #print "characters", data
class DreamInfoHandler:
STATUS_WORKING = 0
STATUS_ERROR = 2
STATUS_INIT = 4
- def __init__(self, statusCallback, blocking = False):
+ def __init__(self, statusCallback, blocking = False, neededTag = None):
+ self.hardware_info = HardwareInfo()
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)
+ self.console.appClosed.append(self.installNext)
+ self.reloadFavourites = False
self.statusCallback = statusCallback
self.setStatus(self.STATUS_INIT)
# 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])
for package in self.packageslist[:]:
if not self.prerequisiteMet(package[0]["prerequisites"]):
self.packageslist.remove(package)
- return packages
+ return self.packageslist
def prerequisiteMet(self, prerequisites):
# 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
+ else:
+ 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"):
+ has_system = False
for bcastsystem in prerequisites["bcastsystem"]:
if nimmanager.hasNimType(bcastsystem):
- return True
- return False
+ has_system = True
+ if not has_system:
+ return False
if prerequisites.has_key("hardware"):
+ hardware_found = False
for hardware in prerequisites["hardware"]:
- # TODO: hardware detection
- met = True
+ if hardware == self.hardware_info.device_name:
+ hardware_found = True
+ if not hardware_found:
+ return False
return True
def installPackages(self, indexes):
self.installPackage(self.installIndexes[self.currentlyInstallingMetaIndex])
def installPackage(self, index):
+ print "self.packageslist:", self.packageslist
+ if len(self.packageslist) <= index:
+ print "no package with index", index, "found... installing nothing"
+ return
print "installing package with index", index, "and name", self.packageslist[index][0]["attributes"]["name"]
attributes = self.packageslist[index][0]["attributes"]
self.statusCallback(self.status, None)
def installNext(self, *args, **kwargs):
+ if self.reloadFavourites:
+ self.reloadFavourites = False
+ db = eDVBDB.getInstance().reloadBouquets()
+
self.currentIndex += 1
attributes = self.installingAttributes
#print "attributes:", attributes
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.currentAttributeIndex = 0
self.installPackage(self.installIndexes[self.currentlyInstallingMetaIndex])
+ return
self.setStatus(self.STATUS_WORKING)
+ print "currentAttributeIndex:", self.currentAttributeIndex
currentAttribute = self.attributeNames[self.currentAttributeIndex]
print "installing", currentAttribute, "with index", self.currentIndex
print "installing skin:", directory, " - ", name
print "cp -a %s %s" % (directory, resolveFilename(SCOPE_SKIN))
if self.blocking:
- os.system("cp -a %s %s" % (directory, resolveFilename(SCOPE_SKIN)))
+ copytree(directory, resolveFilename(SCOPE_SKIN))
self.installNext()
else:
if self.console.execute("cp -a %s %s" % (directory, resolveFilename(SCOPE_SKIN))):
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
+ self.reloadFavourites = True
if self.blocking:
- os.system("cp %s %s" % ((directory + name), resolveFilename(SCOPE_CONFIG)))
+ copyfile(directory + name, resolveFilename(SCOPE_CONFIG))
self.installNext()
else:
if self.console.execute("cp %s %s" % ((directory + name), resolveFilename(SCOPE_CONFIG))):