patch for vuplus again
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / NFIFlash / downloader.py
old mode 100644 (file)
new mode 100755 (executable)
index c91c858..acf9251
@@ -9,6 +9,7 @@ from Components.Sources.Progress import Progress
 from Components.Label import Label
 from Components.FileList import FileList
 from Components.MultiContent import MultiContentEntryText
+from Components.ScrollLabel import ScrollLabel
 from Tools.Directories import fileExists
 from Tools.HardwareInfo import HardwareInfo
 from enigma import eConsoleAppContainer, eListbox, gFont, eListboxPythonMultiContent, \
@@ -16,6 +17,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 +26,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)
@@ -103,7 +54,7 @@ class Feedlist(MenuList):
 
        def isValid(self):
                l = self.l.getCurrentSelection()
-               if l[0] == 0:
+               if not l or l[0] == 0:
                        return False
                else:
                        return True
@@ -112,6 +63,34 @@ class Feedlist(MenuList):
                if self.instance is not None:
                        self.instance.moveSelectionTo(idx)
 
+class NFOViewer(Screen):
+       skin = """
+               <screen name="NFOViewer" position="110,115" size="540,400" title="Changelog viewer" >
+                       <widget name="changelog" position="10,10" size="520,380" font="Regular;16" />
+               </screen>"""
+
+       def __init__(self, session, nfo):
+               Screen.__init__(self, session)
+               self["changelog"] = ScrollLabel(nfo)
+
+               self["ViewerActions"] = ActionMap(["SetupActions", "ColorActions", "DirectionActions"],
+                       {
+                               "green": self.exit,
+                               "red": self.exit,
+                               "ok": self.exit,
+                               "cancel": self.exit,
+                               "down": self.pageDown,
+                               "up": self.pageUp                       
+                       })
+       def pageUp(self):
+               self["changelog"].pageUp()
+
+       def pageDown(self):
+               self["changelog"].pageDown()
+                       
+       def exit(self):
+               self.close(False)
+
 class NFIDownload(Screen):
        LIST_SOURCE = 1
        LIST_DEST = 2
@@ -280,6 +259,8 @@ class NFIDownload(Screen):
                        self["destlist"].pageDown()
 
        def ok(self):
+               if self.focus is self.LIST_SOURCE and self.nfo:
+                       self.session.open(NFOViewer, self.nfo)
                if self.download:
                        return
                if self.focus is self.LIST_DEST:
@@ -293,13 +274,13 @@ class NFIDownload(Screen):
 
        def feed_failed(self, failure_instance):
                print "[feed_failed] " + str(failure_instance)
-               self["infolabel"].text = _("Could not connect to Dreambox .NFI Image Feed Server:") + "\n" + failure_instance.getErrorMessage() + "\n\n" + _("Please check your network settings!")
+               self["infolabel"].text = _("Could not connect to STB .NFI Image Feed Server:") + "\n" + failure_instance.getErrorMessage() + "\n\n" + _("Please check your network settings!")
                self.downloading(False)
 
        def feed_finished(self, feedhtml):
                print "[feed_finished] " + str(feedhtml)
                self.downloading(False)
-               fileresultmask = re.compile("<a href=[\'\"](?P<url>.*?)[\'\"]>(?P<name>.*?.nfi)</a>", re.DOTALL)
+               fileresultmask = re.compile("<a class=[\'\"]nfi[\'\"] href=[\'\"](?P<url>.*?)[\'\"]>(?P<name>.*?.nfi)</a>", re.DOTALL)
                searchresults = fileresultmask.finditer(feedhtml)
                fileresultlist = []
                if searchresults:
@@ -358,7 +339,7 @@ class NFIDownload(Screen):
                else:   
                        self.nfofilename = ""
                        self["infolabel"].text = _("No details for this image file")
-               self["statusbar"].text = ""
+               self["statusbar"].text = _("Press OK to view full changelog")
 
        def nfi_download(self):
                if self["destlist"].getCurrentDirectory() is None:
@@ -505,7 +486,7 @@ class NFIDownload(Screen):
 
        def dmesg_cleared(self, answer):
                self.container.appClosed.remove(self.dmesg_cleared)
-               self.msgbox = self.session.open(MessageBox, _("Please disconnect all USB devices from your Dreambox and (re-)attach the target USB stick (minimum size is 64 MB) now!"), MessageBox.TYPE_INFO)
+               self.msgbox = self.session.open(MessageBox, _("Please disconnect all USB devices from your STB and (re-)attach the target USB stick (minimum size is 64 MB) now!"), MessageBox.TYPE_INFO)
                hotplugNotifier.append(self.hotplugCB)
 
        def hotplugCB(self, dev, action):
@@ -544,7 +525,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)
@@ -669,14 +650,14 @@ class NFIDownload(Screen):
                                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)
+               self.session.open(MessageBox, _("To update your STB 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:
+               try:
                        self.download.stop()
                        #self.nfi_failed(None, "Cancelled by user request")
                        self.downloading(False)
-               else:
+               except AttributeError:
                        self.close()
 
 def main(session, **kwargs):