1 from enigma import eConsoleAppContainer
21 def __init__(self, ipkg = '/usr/bin/ipkg'):
24 self.cmd = eConsoleAppContainer()
25 self.cmd.appClosed.get().append(self.cmdFinished)
26 self.cmd.dataAvail.get().append(self.cmdData)
29 self.callbackList = []
30 self.setCurrentCommand()
32 def setCurrentCommand(self, command = None):
33 self.currentCommand = command
35 def runCmd(self, cmd):
36 print "executing", self.ipkg, cmd
37 self.cmd.execute(self.ipkg + " " + cmd)
39 def startCmd(self, cmd, args = None):
40 if cmd == self.CMD_UPDATE:
42 elif cmd == self.CMD_UPGRADE:
46 self.runCmd("upgrade" + append)
47 elif cmd == self.CMD_LIST:
49 if args['installed_only']:
50 self.runCmd("list_installed")
53 elif cmd == self.CMD_INSTALL:
54 self.runCmd("install " + args['package'])
55 self.setCurrentCommand(cmd)
57 def cmdFinished(self, retval):
58 self.callCallbacks(self.EVENT_DONE)
60 def cmdData(self, data):
62 if self.cache is None:
68 splitcache = self.cache.split('\n')
69 if self.cache[-1] == '\n':
70 iteration = splitcache
73 iteration = splitcache[:-1]
74 self.cache = splitcache[-1]
75 for mydata in iteration:
77 self.parseLine(mydata)
79 def parseLine(self, data):
80 if self.currentCommand == self.CMD_LIST:
81 item = data.split(' - ', 2)
82 self.fetchedList.append(item)
83 self.callCallbacks(self.EVENT_LISTITEM, item)
85 if data.find('Downloading') == 0:
86 self.callCallbacks(self.EVENT_DOWNLOAD, data.split(' ', 5)[1].strip())
87 elif data.find('Upgrading') == 0:
88 self.callCallbacks(self.EVENT_UPGRADE, data.split(' ', 1)[1].split(' ')[0])
89 elif data.find('Installing') == 0:
90 self.callCallbacks(self.EVENT_INSTALL, data.split(' ', 1)[1].split(' ')[0])
91 elif data.find('Configuring') == 0:
92 self.callCallbacks(self.EVENT_CONFIGURING, data.split(' ', 1)[1].split(' ')[0])
93 elif data.find('An error occurred') == 0:
94 self.callCallbacks(self.EVENT_ERROR, None)
95 elif data.find('Failed to download') == 0:
96 self.callCallbacks(self.EVENT_ERROR, None)
97 elif data.find('ipkg_download: ERROR:') == 0:
98 self.callCallbacks(self.EVENT_ERROR, None)
99 elif data.find(' Configuration file') == 0:
100 self.callCallbacks(self.EVENT_MODIFIED, data.split(' \'', 1)[1][:-1])
102 def callCallbacks(self, event, param = None):
103 for callback in self.callbackList:
104 callback(event, param)
106 def addCallback(self, callback):
107 self.callbackList.append(callback)
109 def getFetchedList(self):
110 return self.fetchedList
116 return self.cmd.running()
118 def write(self, what):
120 # We except unterminated commands
122 self.cmd.write(what, len(what))