handle multiple configuration files correctly. Patch by Pieter Grimmerink
[enigma2.git] / lib / python / Components / Ipkg.py
index dbc99653e7f417eb7c9e2f3a56315698da9c6319..79389b4df0ee30aa99bd03845ab87cf966e2b298 100644 (file)
@@ -10,6 +10,7 @@ class IpkgComponent:
        EVENT_LISTITEM = 9
        EVENT_DONE = 10
        EVENT_ERROR = 11
        EVENT_LISTITEM = 9
        EVENT_DONE = 10
        EVENT_ERROR = 11
+       EVENT_MODIFIED = 12
        
        CMD_INSTALL = 0
        CMD_LIST = 1
        
        CMD_INSTALL = 0
        CMD_LIST = 1
@@ -21,10 +22,7 @@ class IpkgComponent:
                self.ipkg = ipkg
                
                self.cmd = eConsoleAppContainer()
                self.ipkg = ipkg
                
                self.cmd = eConsoleAppContainer()
-               self.cmd.appClosed.get().append(self.cmdFinished)
-               self.cmd.dataAvail.get().append(self.cmdData)
                self.cache = None
                self.cache = None
-               
                self.callbackList = []
                self.setCurrentCommand()
                
                self.callbackList = []
                self.setCurrentCommand()
                
@@ -33,8 +31,11 @@ class IpkgComponent:
                
        def runCmd(self, cmd):
                print "executing", self.ipkg, cmd
                
        def runCmd(self, cmd):
                print "executing", self.ipkg, cmd
-               self.cmd.execute(self.ipkg + " " + cmd)
-               
+               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")
        def startCmd(self, cmd, args = None):
                if cmd == self.CMD_UPDATE:
                        self.runCmd("update")
@@ -55,7 +56,9 @@ class IpkgComponent:
        
        def cmdFinished(self, retval):
                self.callCallbacks(self.EVENT_DONE)
        
        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:
        def cmdData(self, data):
                print "data:", data
                if self.cache is None:
@@ -95,6 +98,12 @@ class IpkgComponent:
                                self.callCallbacks(self.EVENT_ERROR, None)
                        elif data.find('ipkg_download: ERROR:') == 0:
                                self.callCallbacks(self.EVENT_ERROR, None)
                                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)
        def callCallbacks(self, event, param = None):
                for callback in self.callbackList:
                        callback(event, param)
@@ -110,3 +119,9 @@ class IpkgComponent:
                
        def isRunning(self):
                return self.cmd.running()
                
        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))