1 from enigma import eConsoleAppContainer
20 def __init__(self, ipkg = '/usr/bin/ipkg'):
23 self.cmd = eConsoleAppContainer()
24 self.cmd.appClosed.get().append(self.cmdFinished)
25 self.cmd.dataAvail.get().append(self.cmdData)
28 self.callbackList = []
29 self.setCurrentCommand()
31 def setCurrentCommand(self, command = None):
32 self.currentCommand = command
34 def runCmd(self, cmd):
35 print "executing", self.ipkg, cmd
36 self.cmd.execute(self.ipkg + " " + cmd)
38 def startCmd(self, cmd, args = None):
39 if cmd == self.CMD_UPDATE:
41 elif cmd == self.CMD_UPGRADE:
45 self.runCmd("upgrade" + append)
46 elif cmd == self.CMD_LIST:
48 if args['installed_only']:
49 self.runCmd("list_installed")
52 elif cmd == self.CMD_INSTALL:
53 self.runCmd("install " + args['package'])
54 self.setCurrentCommand(cmd)
56 def cmdFinished(self, retval):
57 self.callCallbacks(self.EVENT_DONE)
59 def cmdData(self, data):
61 if self.cache is None:
67 splitcache = self.cache.split('\n')
68 if self.cache[-1] == '\n':
69 iteration = splitcache
72 iteration = splitcache[:-1]
73 self.cache = splitcache[-1]
74 for mydata in iteration:
76 self.parseLine(mydata)
78 def parseLine(self, data):
79 if self.currentCommand == self.CMD_LIST:
80 item = data.split(' - ', 2)
81 self.fetchedList.append(item)
82 self.callCallbacks(self.EVENT_LISTITEM, item)
84 if data.find('Downloading') == 0:
85 self.callCallbacks(self.EVENT_DOWNLOAD, data.split(' ', 5)[1].strip())
86 elif data.find('Upgrading') == 0:
87 self.callCallbacks(self.EVENT_UPGRADE, data.split(' ', 1)[1].split(' ')[0])
88 elif data.find('Installing') == 0:
89 self.callCallbacks(self.EVENT_INSTALL, data.split(' ', 1)[1].split(' ')[0])
90 elif data.find('Configuring') == 0:
91 self.callCallbacks(self.EVENT_CONFIGURING, data.split(' ', 1)[1].split(' ')[0])
92 elif data.find('An error occurred') == 0:
93 self.callCallbacks(self.EVENT_ERROR, None)
94 elif data.find('Failed to download') == 0:
95 self.callCallbacks(self.EVENT_ERROR, None)
96 elif data.find('ipkg_download: ERROR:') == 0:
97 self.callCallbacks(self.EVENT_ERROR, None)
98 def callCallbacks(self, event, param = None):
99 for callback in self.callbackList:
100 callback(event, param)
102 def addCallback(self, callback):
103 self.callbackList.append(callback)
105 def getFetchedList(self):
106 return self.fetchedList
112 return self.cmd.running()