X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/9f233a55dbc640a9dd8d1aa46c1291d28fdea3b4..a6f7c725e21a4b6ed064e92b453331837d12f267:/lib/python/Plugins/SystemPlugins/NFIFlash/downloader.py diff --git a/lib/python/Plugins/SystemPlugins/NFIFlash/downloader.py b/lib/python/Plugins/SystemPlugins/NFIFlash/downloader.py index 7e34d2bb..6292a46f 100644 --- a/lib/python/Plugins/SystemPlugins/NFIFlash/downloader.py +++ b/lib/python/Plugins/SystemPlugins/NFIFlash/downloader.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from Components.MenuList import MenuList from Screens.Screen import Screen from Screens.MessageBox import MessageBox @@ -15,6 +16,7 @@ from enigma import eConsoleAppContainer, eListbox, gFont, eListboxPythonMultiCon from os import system, remove import re import urllib +from Tools.Downloader import downloadWithProgress from twisted.web import client from twisted.internet import reactor, defer from twisted.python import failure @@ -23,57 +25,6 @@ from Plugins.SystemPlugins.Hotplug.plugin import hotplugNotifier class UserRequestedCancel(Exception): pass -class HTTPProgressDownloader(client.HTTPDownloader): - def __init__(self, url, outfile, headers=None): - client.HTTPDownloader.__init__(self, url, outfile, headers=headers, agent="Dreambox .NFI Download Plugin") - self.status = None - self.progress_callback = None - self.deferred = defer.Deferred() - - def noPage(self, reason): - if self.status == "304": - print reason.getErrorMessage() - client.HTTPDownloader.page(self, "") - else: - client.HTTPDownloader.noPage(self, reason) - - def gotHeaders(self, headers): - if self.status == "200": - if headers.has_key("content-length"): - self.totalbytes = int(headers["content-length"][0]) - else: - self.totalbytes = 0 - self.currentbytes = 0.0 - return client.HTTPDownloader.gotHeaders(self, headers) - - def pagePart(self, packet): - if self.status == "200": - self.currentbytes += len(packet) - if self.totalbytes and self.progress_callback: - self.progress_callback(self.currentbytes, self.totalbytes) - return client.HTTPDownloader.pagePart(self, packet) - - def pageEnd(self): - return client.HTTPDownloader.pageEnd(self) - -class downloadWithProgress: - def __init__(self, url, outputfile, contextFactory=None, *args, **kwargs): - scheme, host, port, path = client._parse(url) - self.factory = HTTPProgressDownloader(url, outputfile, *args, **kwargs) - self.connection = reactor.connectTCP(host, port, self.factory) - - def start(self): - return self.factory.deferred - - def stop(self): - print "[stop]" - self.connection.disconnect() - #self.factory.deferred.errback(failure.Failure(UserRequestedCancel)) - - def addProgress(self, progress_callback): - print "[addProgress]" - self.factory.progress_callback = progress_callback - class Feedlist(MenuList): def __init__(self, list=[], enableWrapAround = False): MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent) @@ -120,10 +71,10 @@ class NFIDownload(Screen): - - - - + + + + @@ -170,6 +121,7 @@ class NFIDownload(Screen): self.box = HardwareInfo().get_device_name() self.feed_base = "http://www.dreamboxupdate.com/opendreambox/1.5/%s/images/" % self.box self.nfi_filter = "" # "release" # only show NFIs containing this string, or all if "" + self.wizard_mode = False self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "EPGSelectActions"], { @@ -206,7 +158,7 @@ class NFIDownload(Screen): self["key_yellow"].text = (_("Change dir.")) else: self["key_yellow"].text = (_("Select image")) - self["key_blue"].text = (_("Fix USB stick")) + self["key_blue"].text = (_("USB stick wizard")) def switchList(self,to_where=None): if self.download or not self["feedlist"].isValid(): @@ -400,7 +352,7 @@ class NFIDownload(Screen): print "couldn't save nfo file " + self.nfofilename pos = self.nfo.find("MD5:") - if pos > 0 and len(self.nfo) >= pos+5+32: + if pos > 0 and len(self.nfo) >= pos+5+32: self["statusbar"].text = ("Please wait for md5 signature verification...") cmd = "md5sum -c -" md5 = self.nfo[pos+5:pos+5+32] + " " + self.nfilocal @@ -416,6 +368,8 @@ class NFIDownload(Screen): else: self["statusbar"].text = "Download completed." self.downloading(False) + if self.wizard_mode: + self.configBackup() def md5ready(self, retval): self.download_container.sendEOF() @@ -424,9 +378,12 @@ class NFIDownload(Screen): print "[md5finished]: " + str(retval) self.download_container.appClosed.remove(self.md5finished) if retval==0: - self["statusbar"].text = _(".NFI file passed md5sum signature check. You can safely flash this image!") - self.switchList(self.LIST_SOURCE) self.downloading(False) + if self.wizard_mode: + self.configBackup() + else: + self["statusbar"].text = _(".NFI file passed md5sum signature check. You can safely flash this image!") + self.switchList(self.LIST_SOURCE) else: self.session.openWithCallback(self.nfi_remove, MessageBox, (_("The md5sum validation failed, the file may be downloaded incompletely or be corrupted!") + "\n" + _("Remove the broken .NFI file?")), MessageBox.TYPE_YESNO) @@ -537,7 +494,7 @@ class NFIDownload(Screen): self.taskstring = "" self.container.appClosed.append(self.fdisk_finished) self.container.execute("fdisk " + self.stickdevice + "/disc") - self.container.write("d\nn\np\n1\n\n\nt\n6\nw\n") + self.container.write("d\n4\nd\n3\nd\n2\nd\nn\np\n1\n\n\nt\n6\nw\n") self.delayTimer = eTimer() self.delayTimer.callback.append(self.progress_increment) self.delayTimer.start(105, False) @@ -613,10 +570,11 @@ class NFIDownload(Screen): self["job_progressbar"].value = 1000 self["job_progresslabel"].text = "100.00%" self["statusbar"].text = (".NFI Flasher bootable USB stick successfully created.") - self.session.openWithCallback(self.remove_img, MessageBox, _("The .NFI Image flasher USB stick is now ready to use. Please download an .NFI image file from the feed server and save it on the stick. Then reboot and hold the 'Down' key on the front panel to boot the .NFI flasher from the stick!"), MessageBox.TYPE_INFO) + self.session.openWithCallback(self.flasherFinishedCB, MessageBox, _("The USB stick is now bootable. Do you want to download the latest image from the feed server and save it on the stick?"), type = MessageBox.TYPE_YESNO) self["destlist"].changeDir("/mnt/usb") else: - self.session.openWithCallback(self.remove_img, MessageBox, (self.cmd + " " + _("failed") + ":\n" + str(self.taskstring)), MessageBox.TYPE_ERROR) + self.session.openWithCallback(self.flasherFinishedCB, MessageBox, (self.cmd + " " + _("failed") + ":\n" + str(self.taskstring)), MessageBox.TYPE_ERROR) + self.remove_img(True) def remove_img(self, answer): if fileExists("/tmp/nfiflasher_image.tar.bz2"): @@ -626,6 +584,43 @@ class NFIDownload(Screen): self.downloading(False) self.switchList(self.LIST_SOURCE) + def flasherFinishedCB(self, answer): + if answer == True: + self.wizard_mode = True + self["feedlist"].moveSelection(0) + self["path_bottom"].text = str(self["destlist"].getCurrentDirectory()) + self.nfo_download() + self.nfi_download() + + def configBackup(self): + self.session.openWithCallback(self.runBackup, MessageBox, _("The wizard can backup your current settings. Do you want to do a backup now?")) + + def runBackup(self, result=None): + from Tools.Directories import createDir, isMount, pathExists + from time import localtime + from datetime import date + from Screens.Console import Console + if result: + if isMount("/mnt/usb/"): + if (pathExists("/mnt/usb/backup") == False): + createDir("/mnt/usb/backup", True) + d = localtime() + dt = date(d.tm_year, d.tm_mon, d.tm_mday) + self.backup_file = "backup/" + str(dt) + "_settings_backup.tar.gz" + self.session.open(Console, title = "Backup running", cmdlist = ["tar -czvf " + "/mnt/usb/" + self.backup_file + " /etc/enigma2/ /etc/network/interfaces /etc/wpa_supplicant.conf"], finishedCallback = self.backup_finished, closeOnSuccess = True) + else: + self.backup_file = None + self.backup_finished(skipped=True) + + def backup_finished(self, skipped=False): + if not skipped: + wizardfd = open("/mnt/usb/wizard.nfo", "w") + if wizardfd: + wizardfd.write("image: "+self["feedlist"].getNFIname()+'\n') + wizardfd.write("configuration: "+self.backup_file+'\n') + wizardfd.close() + self.session.open(MessageBox, _("To update your Dreambox firmware, please follow these steps:\n1) Turn off your box with the rear power switch and plug in the bootable USB stick.\n2) Turn mains back on and hold the DOWN button on the front panel pressed for 10 seconds.\n3) Wait for bootup and follow instructions of the wizard."), type = MessageBox.TYPE_INFO) + def closeCB(self): if self.download: self.download.stop()