Merge branch 'master' of git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / python / Plugins / SystemPlugins / NFIFlash / downloader.py
index 7b4add56afc70e66f3b1c033a094fe1ddb8c7443..6292a46fe38aa968907d0a4f096814b177f517f0 100644 (file)
@@ -16,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
@@ -24,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)
@@ -544,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)
@@ -660,14 +610,15 @@ class NFIDownload(Screen):
                                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()
-
-       def backup_finished(self):
-               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.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):