X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/2ca2437ed16a3676fea816e2061aefb69ccf047d..37152843c915fd0a9352256d804ced4ff54c23c4:/lib/python/Plugins/SystemPlugins/NFIFlash/flasher.py diff --git a/lib/python/Plugins/SystemPlugins/NFIFlash/flasher.py b/lib/python/Plugins/SystemPlugins/NFIFlash/flasher.py old mode 100644 new mode 100755 index b077905f..7a0da851 --- a/lib/python/Plugins/SystemPlugins/NFIFlash/flasher.py +++ b/lib/python/Plugins/SystemPlugins/NFIFlash/flasher.py @@ -1,4 +1,3 @@ -# -*- coding: utf8 -*- from Screens.Screen import Screen from Screens.MessageBox import MessageBox from Screens.ChoiceBox import ChoiceBox @@ -18,7 +17,7 @@ import re class writeNAND(Task): def __init__(self,job,param,box): - Task.__init__(self,job, _("Writing image file to NAND Flash")) + Task.__init__(self,job, ("Writing image file to NAND Flash")) self.setTool("/usr/lib/enigma2/python/Plugins/SystemPlugins/NFIFlash/mywritenand") if box == "dm7025": self.end = 256 @@ -27,7 +26,7 @@ class writeNAND(Task): if box == "dm8000": self.setTool("/usr/lib/enigma2/python/Plugins/SystemPlugins/NFIFlash/dm8000_writenand") self.args += param - self.weighting = 1 + self.weighting = 1 def processOutput(self, data): print "[writeNand] " + data @@ -40,13 +39,19 @@ class writeNAND(Task): self.output_line = data class NFISummary(Screen): - skin = """ - + skin = ( + """ - - """ + + """, + """ + + + + + """) def __init__(self, session, parent): Screen.__init__(self, session, parent) @@ -64,10 +69,10 @@ class NFIFlash(Screen): - - - - + + + + @@ -96,6 +101,7 @@ class NFIFlash(Screen): { "green": self.ok, "yellow": self.reboot, + "blue": self.runWizard, "ok": self.ok, "left": self.left, "right": self.right, @@ -110,6 +116,43 @@ class NFIFlash(Screen): self.md5sum = "" self.job = None self.box = HardwareInfo().get_device_name() + self.configuration_restorable = None + self.wizard_mode = False + from enigma import eTimer + self.delayTimer = eTimer() + self.delayTimer.callback.append(self.runWizard) + self.delayTimer.start(50,1) + + def check_for_wizard(self): + if self["filelist"].getCurrentDirectory() is not None and fileExists(self["filelist"].getCurrentDirectory()+"wizard.nfo"): + self["key_blue"].text = _("USB stick wizard") + return True + else: + self["key_blue"].text = "" + return False + + def runWizard(self): + if not self.check_for_wizard(): + self.wizard_mode = False + return + wizardcontent = open(self["filelist"].getCurrentDirectory()+"/wizard.nfo", "r").readlines() + nfifile = None + for line in wizardcontent: + line = line.strip() + if line.startswith("image: "): + nfifile = self["filelist"].getCurrentDirectory()+line[7:] + if line.startswith("configuration: "): + backupfile = self["filelist"].getCurrentDirectory()+line[15:] + if fileExists(backupfile): + print "wizard configuration:", backupfile + self.configuration_restorable = backupfile + else: + self.configuration_restorable = None + if nfifile and fileExists(nfifile): + self.wizard_mode = True + print "wizard image:", nfifile + self.check_for_NFO(nfifile) + self.queryFlash() def closeCB(self): if ( self.job is None or self.job.status is not self.job.IN_PROGRESS ) and not self.no_autostart: @@ -134,12 +177,16 @@ class NFIFlash(Screen): self["filelist"].pageUp() self.check_for_NFO() - def check_for_NFO(self): + def check_for_NFO(self, nfifile=None): self.session.summary.setText(self["filelist"].getFilename()) - if self["filelist"].getFilename() is None: - return - if self["filelist"].getCurrentDirectory() is not None: - self.nfifile = self["filelist"].getCurrentDirectory()+self["filelist"].getFilename() + if nfifile is None: + self.session.summary.setText(self["filelist"].getFilename()) + if self["filelist"].getFilename() is None: + return + if self["filelist"].getCurrentDirectory() is not None: + self.nfifile = self["filelist"].getCurrentDirectory()+self["filelist"].getFilename() + else: + self.nfifile = nfifile if self.nfifile.upper().endswith(".NFI"): self["key_green"].text = _("Flash") @@ -147,13 +194,13 @@ class NFIFlash(Screen): if fileExists(nfofilename): nfocontent = open(nfofilename, "r").read() self["infolabel"].text = nfocontent - pos = nfocontent.find("md5sum") + pos = nfocontent.find("MD5:") if pos > 0: - self.md5sum = nfofilename + self.md5sum = nfocontent[pos+5:pos+5+32] + " " + self.nfifile else: self.md5sum = "" else: - self["infolabel"].text = _("No details for this image file") + ":\n" + self["filelist"].getFilename() + self["infolabel"].text = _("No details for this image file") + (self["filelist"].getFilename() or "") self.md5sum = "" else: self["infolabel"].text = "" @@ -165,6 +212,7 @@ class NFIFlash(Screen): self["filelist"].descent() self.session.summary.setText(self["filelist"].getFilename()) self.check_for_NFO() + self.check_for_wizard() else: self.queryFlash() @@ -175,20 +223,28 @@ class NFIFlash(Screen): print sign if sign.find("NFI1" + self.box + "\0") == 0: if self.md5sum != "": - self["statusbar"].text = _("Please wait for md5 signature verification...") - self.session.summary.setText(_("Please wait for md5 signature verification...")) + self["statusbar"].text = ("Please wait for md5 signature verification...") + self.session.summary.setText(("Please wait for md5 signature verification...")) self.container = eConsoleAppContainer() self.container.setCWD(self["filelist"].getCurrentDirectory()) - self.container.appClosed.get().append(self.md5finished) - self.container.execute("md5sum -cs " + self.md5sum) + self.container.appClosed.append(self.md5finished) + self.container.dataSent.append(self.md5ready) + self.container.execute("md5sum -cw -") + self.container.write(self.md5sum) else: self.session.openWithCallback(self.queryCB, MessageBox, _("This .NFI file does not have a md5sum signature and is not guaranteed to work. Do you really want to burn this image to flash memory?"), MessageBox.TYPE_YESNO) else: self.session.open(MessageBox, (_("This .NFI file does not contain a valid %s image!") % (self.box.upper())), MessageBox.TYPE_ERROR) - + + def md5ready(self, retval): + self.container.sendEOF() + def md5finished(self, retval): if retval==0: - self.session.openWithCallback(self.queryCB, MessageBox, _("This .NFI file has a valid md5 signature. Continue programming this image to flash memory?"), MessageBox.TYPE_YESNO) + if self.wizard_mode: + self.session.openWithCallback(self.queryCB, MessageBox, _("Shall the USB stick wizard proceed and program the image file %s into flash memory?" % self.nfifile.rsplit('/',1)[-1]), MessageBox.TYPE_YESNO) + else: + self.session.openWithCallback(self.queryCB, MessageBox, _("This .NFI file has a valid md5 signature. Continue programming this image to flash memory?"), MessageBox.TYPE_YESNO) else: self.session.openWithCallback(self.queryCB, MessageBox, _("The md5sum validation failed, the file may be corrupted! Are you sure that you want to burn this image to flash memory? You are doing this at your own risk!"), MessageBox.TYPE_YESNO) @@ -197,6 +253,7 @@ class NFIFlash(Screen): self.createJob() else: self["statusbar"].text = _("Please select .NFI flash image file from medium") + self.wizard_mode = False def createJob(self): self.job = Job("Image flashing job") @@ -236,6 +293,8 @@ class NFIFlash(Screen): elif j.status == j.FINISHED: self["statusbar"].text = _("Writing NFI image file to flash completed") self.session.summary.setText(_("NFI image flashing completed. Press Yellow to Reboot!")) + if self.wizard_mode: + self.restoreConfiguration() self["key_yellow"].text = _("Reboot") elif j.status == j.FAILED: @@ -246,10 +305,19 @@ class NFIFlash(Screen): print "[jobcb] %s %s %s" % (jobref, fasel, blubber) self["key_green"].text = _("Flash") - def reboot(self): + def reboot(self, ret=None): if self.job.status == self.job.FINISHED: - self["statusbar"].text = _("rebooting...") + self["statusbar"].text = ("rebooting...") TryQuitMainloop(self.session,2) - + + def restoreConfiguration(self): + if self.configuration_restorable: + from Screens.Console import Console + cmdlist = [ "mount /dev/mtdblock/3 /mnt/realroot -t jffs2", "tar -xzvf " + self.configuration_restorable + " -C /mnt/realroot/" ] + self.session.open(Console, title = "Restore running", cmdlist = cmdlist, finishedCallback = self.restore_finished, closeOnSuccess = True) + + def restore_finished(self): + self.session.openWithCallback(self.reboot, MessageBox, _("USB stick wizard finished. Your dreambox will now restart with your new image!"), MessageBox.TYPE_INFO) + def createSummary(self): return NFISummary