handle multiple configuration files correctly. Patch by Pieter Grimmerink
[enigma2.git] / lib / python / Components / Ipkg.py
index df700d6b5b1fa5d07712983f0f06b9149344c77b..79389b4df0ee30aa99bd03845ab87cf966e2b298 100644 (file)
@@ -1,6 +1,6 @@
 from enigma import eConsoleAppContainer
 
-class Ipkg:
+class IpkgComponent:
        EVENT_INSTALL = 0
        EVENT_DOWNLOAD = 1
        EVENT_INFLATING = 2
@@ -10,6 +10,7 @@ class Ipkg:
        EVENT_LISTITEM = 9
        EVENT_DONE = 10
        EVENT_ERROR = 11
+       EVENT_MODIFIED = 12
        
        CMD_INSTALL = 0
        CMD_LIST = 1
@@ -21,10 +22,7 @@ class Ipkg:
                self.ipkg = ipkg
                
                self.cmd = eConsoleAppContainer()
-               self.cmd.appClosed.get().append(self.cmdFinished)
-               self.cmd.dataAvail.get().append(self.cmdData)
                self.cache = None
-               
                self.callbackList = []
                self.setCurrentCommand()
                
@@ -33,30 +31,34 @@ class Ipkg:
                
        def runCmd(self, cmd):
                print "executing", self.ipkg, cmd
-               self.cmd.execute(self.ipkg + " " + cmd)
-               
-       def cmdFetchList(self, installed_only = False):
-               self.fetchedList = []
-               if installed_only:
-                       self.runCmd("list_installed")
-               else:
-                       self.runCmd("list")
-               self.setCurrentCommand(self.CMD_LIST)
-               
-       def cmdUpgrade(self, test_only = False):
-               append = ""
-               if test_only:
-                       append = " -test"
-               self.runCmd("upgrade" + append)
-               self.setCurrentCommand(self.CMD_UPGRADE)
-               
-       def cmdUpdate(self):
-               self.runCmd("update")
-               self.setCurrentCommand(self.CMD_UPDATE)
-               
+               self.cmd.appClosed.get().append(self.cmdFinished)
+               self.cmd.dataAvail.get().append(self.cmdData)
+               if self.cmd.execute(self.ipkg + " " + cmd):
+                       self.cmdFinished(-1)
+
+       def startCmd(self, cmd, args = None):
+               if cmd == self.CMD_UPDATE:
+                       self.runCmd("update")
+               elif cmd == self.CMD_UPGRADE:
+                       append = ""
+                       if args["test_only"]:
+                               append = " -test"
+                       self.runCmd("upgrade" + append)
+               elif cmd == self.CMD_LIST:
+                       self.fetchedList = []
+                       if args['installed_only']:
+                               self.runCmd("list_installed")
+                       else:
+                               self.runCmd("list")
+               elif cmd == self.CMD_INSTALL:
+                       self.runCmd("install " + args['package'])
+               self.setCurrentCommand(cmd)
+       
        def cmdFinished(self, retval):
                self.callCallbacks(self.EVENT_DONE)
-       
+               self.cmd.appClosed.get().remove(self.cmdFinished)
+               self.cmd.dataAvail.get().remove(self.cmdData)
+
        def cmdData(self, data):
                print "data:", data
                if self.cache is None:
@@ -96,6 +98,12 @@ class Ipkg:
                                self.callCallbacks(self.EVENT_ERROR, None)
                        elif data.find('ipkg_download: ERROR:') == 0:
                                self.callCallbacks(self.EVENT_ERROR, None)
+                       elif data.find('    Configuration file \'') >= 0:
+                               # Note: the config file update question doesn't end with a newline, so
+                               # if we get multiple config file update questions, the next ones
+                               # don't necessarily start at the beginning of a line
+                               self.callCallbacks(self.EVENT_MODIFIED, data.split(' \'', 1)[1][:-1])
+
        def callCallbacks(self, event, param = None):
                for callback in self.callbackList:
                        callback(event, param)
@@ -111,3 +119,9 @@ class Ipkg:
                
        def isRunning(self):
                return self.cmd.running()
+
+       def write(self, what):
+               if what:
+                       # We except unterminated commands
+                       what += "\n"
+                       self.cmd.write(what, len(what))