diff options
| author | Stefan Pluecken <stefan.pluecken@multimedia-labs.de> | 2008-04-28 23:35:46 +0000 |
|---|---|---|
| committer | Stefan Pluecken <stefan.pluecken@multimedia-labs.de> | 2008-04-28 23:35:46 +0000 |
| commit | bce291362914ca2b1101ec3503ccc89c001e7bcb (patch) | |
| tree | a0383eb85b98f5844db719fd0d591466a2e2ed04 /lib/python | |
| parent | 8da594660701d8cfc7e9a656fa0d2683287757ef (diff) | |
| download | enigma2-bce291362914ca2b1101ec3503ccc89c001e7bcb.tar.gz enigma2-bce291362914ca2b1101ec3503ccc89c001e7bcb.zip | |
default wizard
beware: could overwrite some of your data in /etc/enigma2. add
config.misc.defaultchosen=false to /etc/enigma2/settings to prevent
this.
Diffstat (limited to 'lib/python')
| -rw-r--r-- | lib/python/Components/DreamInfoHandler.py | 325 | ||||
| -rw-r--r-- | lib/python/Components/Makefile.am | 3 | ||||
| -rw-r--r-- | lib/python/Screens/DefaultWizard.py | 49 | ||||
| -rw-r--r-- | lib/python/Screens/Makefile.am | 5 | ||||
| -rw-r--r-- | lib/python/Screens/StartWizard.py | 4 |
5 files changed, 381 insertions, 5 deletions
diff --git a/lib/python/Components/DreamInfoHandler.py b/lib/python/Components/DreamInfoHandler.py new file mode 100644 index 00000000..33b86bb2 --- /dev/null +++ b/lib/python/Components/DreamInfoHandler.py @@ -0,0 +1,325 @@ +import xml.sax +from Tools.Directories import crawlDirectory, resolveFilename, SCOPE_CONFIG, SCOPE_SKIN +from Components.NimManager import nimmanager +from Components.Ipkg import IpkgComponent +from enigma import eConsoleAppContainer +import os + +class InfoHandlerParseError(Exception): + def __init__(self, value): + self.value = value + def __str__(self): + return repr(self.value) + +class InfoHandler(xml.sax.ContentHandler): + def __init__(self, prerequisiteMet, directory): + self.attributes = {} + self.directory = directory + self.list = [] + self.globalprerequisites = {} + self.prerequisites = {} + 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() + self.elements.append(name) + if name in ["hardware", "bcastsystem", "satellite"]: + if not attrs.has_key("type"): + self.printError(str(name) + " tag with no type attribute") + if self.elements[-3] == "default": + prerequisites = self.globalprerequisites + else: + prerequisites = self.prerequisites + if not prerequisites.has_key(name): + prerequisites[name] = [] + prerequisites[name].append(str(attrs["type"])) + if name == "files": + if attrs.has_key("type"): + if attrs["type"] == "directories": + self.attributes["filestype"] = "directories" + # TODO add a compressed archive type + if name == "file": + self.prerequisites = {} + if not attrs.has_key("type"): + self.printError("file tag with no type attribute") + else: + if not attrs.has_key("name"): + self.printError("file tag with no name attribute") + else: + if not attrs.has_key("directory"): + directory = self.directory + type = attrs["type"] + if not type in self.validFileTypes: + self.printError("file tag with invalid type attribute") + else: + self.filetype = type + self.fileattrs = attrs + def endElement(self, name): + print "end", name + print "self.elements:", self.elements + self.elements.pop() + if name == "file": + 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] = [] + if self.fileattrs.has_key("directory"): + directory = str(self.fileattrs["directory"]) + if len(directory) < 1 or directory[0] != "/": + directory = self.directory + directory + else: + directory = self.directory + self.attributes[self.filetype].append({ "name": str(self.fileattrs["name"]), "directory": directory }) + + if name == "default": + self.list.append({"attributes": self.attributes, 'prerequisites': self.globalprerequisites}) + self.attributes = {} + self.globalprerequisites = {} + + def characters(self, data): + if self.elements[-1] == "author": + self.attributes["author"] = str(data) + if self.elements[-1] == "name": + self.attributes["name"] = str(data) + print "characters", data + +class DreamInfoHandler: + STATUS_WORKING = 0 + STATUS_DONE = 1 + STATUS_ERROR = 2 + STATUS_INIT = 4 + + def __init__(self, statusCallback): + self.directory = "/" + + self.console = eConsoleAppContainer() + self.console.appClosed.get().append(self.installNext) + + self.statusCallback = statusCallback + self.setStatus(self.STATUS_INIT) + + self.packageslist = [] + + def readInfo(self, directory, file): + print "Reading .info file", file + handler = InfoHandler(self.prerequisiteMet, directory) + try: + xml.sax.parse(file, handler) + for entry in handler.list: + self.packageslist.append((entry,file)) + except InfoHandlerParseError: + print "file", file, "ignored due to errors in the file" + print handler.list + + # prerequisites = True: give only packages matching the prerequisites + def fillPackagesList(self, prerequisites = True): + self.packageslist = [] + packages = crawlDirectory(self.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"]): + self.packageslist.remove(package) + return packages + + def prerequisiteMet(self, prerequisites): + # TODO: we need to implement a hardware detection here... + print "prerequisites:", prerequisites + met = True + if prerequisites.has_key("bcastsystem"): + for bcastsystem in prerequisites["bcastsystem"]: + if nimmanager.hasNimType(bcastsystem): + return True + return False + if prerequisites.has_key("hardware"): + for hardware in prerequisites["hardware"]: + # TODO: hardware detection + met = True + return True + + def installPackage(self, index): + print "installing package with index", index, "and name", self.packageslist[index][0]["attributes"]["name"] + + attributes = self.packageslist[index][0]["attributes"] + self.installingAttributes = attributes + self.attributeNames = ["skin", "config", "favourites", "package", "services"] + self.currentAttributeIndex = 0 + self.currentIndex = -1 + self.installNext() + + def setStatus(self, status): + self.status = status + self.statusCallback(self.status, None) + + def installNext(self, *args, **kwargs): + self.currentIndex += 1 + attributes = self.installingAttributes + + if self.currentAttributeIndex >= len(self.attributeNames): # end reached + self.setStatus(self.STATUS_DONE) + return + + self.setStatus(self.STATUS_WORKING) + + currentAttribute = self.attributeNames[self.currentAttributeIndex] + + print "installing", currentAttribute, "with index", self.currentIndex + + if attributes.has_key(currentAttribute): + if self.currentIndex >= len(attributes[currentAttribute]): # all jobs done for current attribute + self.currentIndex = -1 + self.currentAttributeIndex += 1 + self.installNext() + return + else: # nothing to install here + self.currentAttributeIndex += 1 + self.installNext() + return + + if currentAttribute == "skin": + skin = attributes["skin"][self.currentIndex] + self.installSkin(skin["directory"], skin["name"]) + elif currentAttribute == "config": + if self.currentIndex == 0: + from Components.config import configfile + configfile.save() + config = attributes["config"][self.currentIndex] + self.mergeConfig(config["directory"], config["name"]) + elif currentAttribute == "favourites": + favourite = attributes["favourites"][self.currentIndex] + self.installFavourites(favourite["directory"], favourite["name"]) + elif currentAttribute == "package": + package = attributes["package"][self.currentIndex] + self.installIPK(package["directory"], package["name"]) + elif currentAttribute == "services": + service = attributes["services"][self.currentIndex] + self.mergeServices(service["directory"], service["name"]) + + def readfile(self, filename): + fd = open(filename) + lines = fd.readlines() + fd.close() + return lines + + def mergeConfig(self, directory, name, merge = True): + print "merging config:", directory, " - ", name + + newconfig = self.readfile(directory + name) + newconfig.sort() + print newconfig + + if merge: + oldconfig = self.readfile(resolveFilename(SCOPE_CONFIG) + "settings") + oldconfig.sort() + print oldconfig + else: + oldconfig = [] + + # merge with duplicate removal through dictionary + mergeddict = {} + for list in oldconfig, newconfig: + for entry in list: + splitentry = entry.split("=") + if len(splitentry) != 2: # wrong entry + continue + mergeddict[splitentry[0]] = splitentry[1].strip() + + print "new:" + fd = open(resolveFilename(SCOPE_CONFIG) + "settings", "w") + for entry in mergeddict.keys(): + print entry + "=" + mergeddict[entry] + fd.write(entry + "=" + mergeddict[entry] + '\n') + fd.close() + self.installNext() + #configfile.load() + + + def installIPK(self, directory, name): + self.ipkg = IpkgComponent() + self.ipkg.addCallback(self.ipkgCallback) + self.ipkg.startCmd(IpkgComponent.CMD_INSTALL, {'package': directory + name}) + + def ipkgCallback(self, event, param): + print "ipkgCallback" + if event == IpkgComponent.EVENT_DONE: + self.installNext() + elif event == IpkgComponent.EVENT_ERROR: + self.installNext() + + 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" + self.installNext() + + def readServices(self, filename): + newservicesfile = self.readfile(filename) + + transponders = [] + services = [] + status = 0 # 0 = start, 1 = transponders, 2 = services + count = 0 + while count < len(newservicesfile): + if status == 0: + if newservicesfile[count].strip() == "transponders": + status = 1 + elif status == 1: # reading transponders + if newservicesfile[count].strip() == "end": # finished reading transponders + pass + elif newservicesfile[count].strip() == "services": # start of services section + status = 2 + else: + transponders.append(''.join(newservicesfile[count:count + 3])) + count += 2 + elif status == 2: # reading services + if newservicesfile[count].strip() == "end": # finished reading file + break + else: + services.append(''.join(newservicesfile[count:count + 3])) + count += 2 + count += 1 + return (transponders, services) + + def mergeServices(self, directory, name, merge = False): + print "merging services:", directory, " - ", name + + newtransponders, newservices = self.readServices(directory + name) + if merge: + oldtransponders, oldservices = self.readServices(resolveFilename(SCOPE_CONFIG) + "lamedb") + else: + oldtransponders, oldservices = [], [] + + fp = open(resolveFilename(SCOPE_CONFIG) + "lamedb", "w") + fp.write("eDVB services /3/\n") + + fp.write("transponders\n") + for transponderlist in oldtransponders, newtransponders: + for transponder in transponderlist: + fp.write(transponder) + fp.write("end\n") + + fp.write("services\n") + for serviceslist in oldservices, newservices: + for service in serviceslist: + fp.write(service) + fp.write("end\n") + + fp.close() + 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" + self.installNext() diff --git a/lib/python/Components/Makefile.am b/lib/python/Components/Makefile.am index f344046d..71160c9b 100644 --- a/lib/python/Components/Makefile.am +++ b/lib/python/Components/Makefile.am @@ -17,4 +17,5 @@ install_PYTHON = \ FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py FileList.py \ MultiContent.py MediaPlayer.py TunerInfo.py VideoWindow.py ChoiceList.py \ Element.py Playlist.py ParentalControl.py ParentalControlList.py \ - Ipkg.py SelectionList.py Scanner.py SystemInfo.py Task.py + Ipkg.py SelectionList.py Scanner.py SystemInfo.py DreamInfoHandler.py \ + Task.py diff --git a/lib/python/Screens/DefaultWizard.py b/lib/python/Screens/DefaultWizard.py new file mode 100644 index 00000000..5d274b0e --- /dev/null +++ b/lib/python/Screens/DefaultWizard.py @@ -0,0 +1,49 @@ +from Wizard import Wizard, wizardManager +from Tools.Directories import crawlDirectory, resolveFilename, SCOPE_DEFAULTDIR + +from Components.Pixmap import Pixmap, MovingPixmap +from Components.config import config, ConfigBoolean, configfile +from Components.DreamInfoHandler import DreamInfoHandler, InfoHandler, InfoHandlerParseError +import os + +config.misc.defaultchosen = ConfigBoolean(default = True) + +import xml.sax + +class DefaultWizard(Wizard, DreamInfoHandler): + def __init__(self, session): + DreamInfoHandler.__init__(self, self.statusCallback) + self.directory = resolveFilename(SCOPE_DEFAULTDIR) + self.xmlfile = "defaultwizard.xml" + + Wizard.__init__(self, session, showSteps = False) + self["wizard"] = Pixmap() + self["rc"] = MovingPixmap() + self["arrowdown"] = MovingPixmap() + self["arrowup"] = MovingPixmap() + self["arrowup2"] = MovingPixmap() + + def markDone(self): + config.misc.defaultchosen.value = 0 + config.misc.defaultchosen.save() + configfile.save() + + def statusCallback(self, status, progress): + print "statusCallback:", status, progress + if status == DreamInfoHandler.STATUS_DONE: + self["text"].setText(_("Finished")) + self.markDone() + os.system("killall -9 enigma2") + + def listDefaults(self): + self.packageslist = [] + self.fillPackagesList() + list = [] + for x in range(len(self.packageslist)): + list.append((self.packageslist[x][0]["attributes"]["name"], str(x))) + print "defaults list:", list + return list + + def selectionMade(self, index): + print "selected:", index + self.installPackage(int(index))
\ No newline at end of file diff --git a/lib/python/Screens/Makefile.am b/lib/python/Screens/Makefile.am index dd3baf08..b5068a76 100644 --- a/lib/python/Screens/Makefile.am +++ b/lib/python/Screens/Makefile.am @@ -12,5 +12,6 @@ install_PYTHON = \ Console.py InputBox.py ChoiceBox.py SimpleSummary.py ImageWizard.py \ TimerSelection.py PictureInPicture.py TimeDateInput.py \ SubtitleDisplay.py SubservicesQuickzap.py ParentalControlSetup.py NumericalTextInputHelpDialog.py \ - SleepTimerEdit.py Ipkg.py RdsDisplay.py Globals.py \ - SessionGlobals.py LocationBox.py WizardLanguage.py TaskView.py + SleepTimerEdit.py Ipkg.py RdsDisplay.py Globals.py DefaultWizard.py \ + SessionGlobals.py LocationBox.py WizardLanguage.py TaskView.py + diff --git a/lib/python/Screens/StartWizard.py b/lib/python/Screens/StartWizard.py index 7f64624e..95fc24d1 100644 --- a/lib/python/Screens/StartWizard.py +++ b/lib/python/Screens/StartWizard.py @@ -5,7 +5,7 @@ from Components.Pixmap import Pixmap, MovingPixmap from Components.config import config, ConfigBoolean, configfile from LanguageSelection import LanguageSelection -#from DefaultWizard import DefaultWizard +from DefaultWizard import DefaultWizard config.misc.firstrun = ConfigBoolean(default = True) config.misc.languageselected = ConfigBoolean(default = True) @@ -26,5 +26,5 @@ class StartWizard(WizardLanguage): configfile.save() wizardManager.registerWizard(LanguageSelection, config.misc.languageselected.value, priority = 5) -#wizardManager.registerWizard(DefaultWizard, config.misc.defaultchosen.value) +wizardManager.registerWizard(DefaultWizard, config.misc.defaultchosen.value, priority = 1) wizardManager.registerWizard(StartWizard, config.misc.firstrun.value, priority = 20) |
