1 from enigma import eConsoleAppContainer
2 from Tools.BoundFunction import boundFunction
6 self.appContainers = {}
11 def ePopen(self, cmd, callback=None, extra_args=[]):
14 while self.appContainers.has_key(name):
15 name = cmd +'_'+ str(i)
17 print "[ePopen] command:", cmd
18 self.appResults[name] = ""
19 self.extra_args[name] = extra_args
20 self.callbacks[name] = callback
21 self.appContainers[name] = eConsoleAppContainer()
22 self.appContainers[name].dataAvail.append(boundFunction(self.dataAvailCB,name))
23 self.appContainers[name].appClosed.append(boundFunction(self.finishedCB,name))
24 if isinstance(cmd, str): # until .execute supports a better api
26 retval = self.appContainers[name].execute(*cmd)
28 self.finishedCB(name, retval)
30 def eBatch(self, cmds, callback, extra_args=[], debug=False):
33 self.ePopen(cmd, self.eBatchCB, [cmds, callback, extra_args])
35 def eBatchCB(self, data, retval, _extra_args):
36 (cmds, callback, extra_args) = _extra_args
38 print '[eBatch] retval=%s, cmds left=%d, data:\n%s' % (retval, len(cmds), data)
41 self.ePopen(cmd, self.eBatchCB, [cmds, callback, extra_args])
45 def dataAvailCB(self, name, data):
46 self.appResults[name] += data
48 def finishedCB(self, name, retval):
49 del self.appContainers[name].dataAvail[:]
50 del self.appContainers[name].appClosed[:]
51 data = self.appResults[name]
52 extra_args = self.extra_args[name]
53 del self.appContainers[name]
54 del self.extra_args[name]
55 if self.callbacks[name]:
56 self.callbacks[name](data,retval,extra_args)
57 del self.callbacks[name]
60 if name in self.appContainers:
61 print "[Console] killing: ",self.appContainers[name]
62 self.appContainers[name].kill()
65 for name in self.appContainers: