ipkg upgrade now working with the eConsoleAppContainer for realtime display of ipkg...
[enigma2.git] / lib / python / Plugins / update / plugin.py
index 070c199..8c2715b 100644 (file)
 from enigma import *
 from Screens.Screen import Screen
 from Screens.MessageBox import MessageBox
-from Components.ActionMap import ActionMap
+from Components.ActionMap import ActionMap, NumberActionMap
 from Components.ScrollLabel import ScrollLabel
 from Components.GUIComponent import *
+from Components.MenuList import MenuList
+from Components.Input import Input
 from Plugins.Plugin import PluginDescriptor
 
 import os
 
+class UpdatePluginMenu(Screen):
+       skin = """
+               <screen position="200,100" size="300,250" title="Update..." >
+                       <widget name="menu" position="10,10" size="290,175" scrollbarMode="showOnDemand" />
+               </screen>"""
+               
+       def __init__(self, session, args = None):
+               self.skin = UpdatePluginMenu.skin
+               Screen.__init__(self, session)
+               
+               list = []
+               list.append((_("Upgrade"), "upgrade"))
+               list.append((_("Choose source"), "source"))
+               list.append((_("Packet management"), "ipkg"))
+               
+               self["menu"] = MenuList(list)
+                               
+               self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
+               {
+                       "ok": self.go,
+                       "back": self.close,
+               }, -1)
+               
+       def go(self):
+               if (self["menu"].l.getCurrentSelection()[1] == "upgrade"):
+                       self.session.openWithCallback(self.runUpgrade, MessageBox, _("Do you want to update your Dreambox?\nAfter pressing OK, please wait!"))
+               elif (self["menu"].l.getCurrentSelection()[1] == "source"):
+                       self.session.open(IPKGSource)
+               elif (self["menu"].l.getCurrentSelection()[1] == "ipkg"):
+                       self.session.open(Ipkg)
+       
+       def runUpgrade(self, result):
+               if result:
+                       self.session.open(Upgrade)
+
+class IPKGSource(Screen):
+       skin = """
+               <screen position="100,100" size="550,60" title="IPKG source" >
+                       <widget name="text" position="0,0" size="550,25" font="Regular;20" />
+               </screen>"""
+               
+       def __init__(self, session, args = None):
+               self.skin = IPKGSource.skin
+               Screen.__init__(self, session)
+               
+               fp = file('/etc/ipkg/official-feed.conf', 'r')
+               sources = fp.readlines()
+               fp.close()
+               
+               self["text"] = Input(sources[0], maxSize=False, type=Input.TEXT)
+                               
+               self["actions"] = NumberActionMap(["WizardActions", "InputActions"], 
+               {
+                       "ok": self.go,
+                       "back": self.close,
+                       "left": self.keyLeft,
+                       "right": self.keyRight,
+                       "1": self.keyNumberGlobal,
+                       "2": self.keyNumberGlobal,
+                       "3": self.keyNumberGlobal,
+                       "4": self.keyNumberGlobal,
+                       "5": self.keyNumberGlobal,
+                       "6": self.keyNumberGlobal,
+                       "7": self.keyNumberGlobal,
+                       "8": self.keyNumberGlobal,
+                       "9": self.keyNumberGlobal,
+                       "0": self.keyNumberGlobal
+               }, -1)
+               
+       def go(self):
+               fp = file('/etc/ipkg/official-feed.conf', 'w')
+               fp.write(self["text"].getText())
+               fp.close()
+               self.close()
+               
+       def keyLeft(self):
+               self["text"].left()
+       
+       def keyRight(self):
+               self["text"].right()
+       
+       def keyNumberGlobal(self, number):
+               print "pressed", number
+               self["text"].number(number)
+
 class Upgrade(Screen):
        skin = """
                <screen position="100,100" size="550,400" title="IPKG upgrade..." >
@@ -18,42 +105,42 @@ class Upgrade(Screen):
                self.skin = Upgrade.skin
                Screen.__init__(self, session)
 
-               self["text"] = ScrollLabel(_("Please press OK!"))
-                               
+               self["text"] = ScrollLabel(_("Updating... Please wait... This can take some minutes..."))
                self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
                {
-                       "ok": self.go,
-                       "back": self.close,
+                       "ok": self.cancel,
+                       "back": self.cancel,
                        "up": self["text"].pageUp,
                        "down": self["text"].pageDown
                }, -1)
                
-               self.update = True
-               self.delayTimer = eTimer()
-               self.delayTimer.timeout.get().append(self.doUpdateDelay)
-               
-       def go(self):
-               if self.update:
-                       self.session.openWithCallback(self.doUpdate, MessageBox, _("Do you want to update your Dreambox?\nAfter pressing OK, please wait!"))            
-               else:
-                       self.close()
-       
-       def doUpdateDelay(self):
-               lines = os.popen("ipkg update && ipkg upgrade -force-defaults -force-overwrite", "r").readlines()
-               string = ""
-               for x in lines:
-                       string += x
-               self["text"].setText(_("Updating finished. Here is the result:") + "\n\n" + string)
-               self.update = False
+               self.container = eConsoleAppContainer()
+               self.run = 0
+               self.container.appClosed.get().append(self.updateFinished)
+               self.container.dataAvail.get().append(self.dataAvail)
+               self.onLayoutFinish.append(self.startUpdate) # dont start before gui is finished
+
+       def startUpdate(self):
+               self["text"].setText(_("Update Progress:") + "\n\n")
+               self.container.execute("ipkg update")
+
+       def updateFinished(self, retval):
+               if self.run == 0:
+                       self.run = 1
+                       self.container.execute("ipkg upgrade")
+               elif self.run == 1:
+                       str = self["text"].getText()
+                       str += _("Updating finished!!");
+                       self["text"].setText(str)
+                       self.run = 2
                        
-       
-       def doUpdate(self, val = False):
-               if val == True:
-                       self["text"].setText(_("Updating... Please wait... This can take some minutes..."))
-                       self.delayTimer.start(0, 1)
-               else:
+       def cancel(self):
+               if self.run == 2:
                        self.close()
 
+       def dataAvail(self, str):
+               self["text"].setText(self["text"].getText() + str)
+
 RT_HALIGN_LEFT = 0
 RT_HALIGN_RIGHT = 1
 RT_HALIGN_CENTER = 2
@@ -162,8 +249,8 @@ class Ipkg(Screen):
                else:
                        self.close()
 
-def main(session):
-       session.open(Upgrade)
+def UpgradeMain(session):
+       session.open(UpdatePluginMenu)
 
 def Plugins():
-       return PluginDescriptor(name="Softwareupdate", description="Updates your receiver's software", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)
+       return PluginDescriptor(name="Softwareupdate", description="Updates your receiver's software", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=UpgradeMain)