1 from enigma import eConsoleAppContainer
21 def __init__(self, ipkg = '/usr/bin/ipkg'):
24 self.cmd = eConsoleAppContainer()
26 self.callbackList = []
27 self.setCurrentCommand()
29 def setCurrentCommand(self, command = None):
30 self.currentCommand = command
32 def runCmd(self, cmd):
33 print "executing", self.ipkg, cmd
34 self.cmd.appClosed.get().append(self.cmdFinished)
35 self.cmd.dataAvail.get().append(self.cmdData)
36 if 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)
59 self.cmd.appClosed.get().remove(self.cmdFinished)
60 self.cmd.dataAvail.get().remove(self.cmdData)
62 def cmdData(self, data):
64 if self.cache is None:
70 splitcache = self.cache.split('\n')
71 if self.cache[-1] == '\n':
72 iteration = splitcache
75 iteration = splitcache[:-1]
76 self.cache = splitcache[-1]
77 for mydata in iteration:
79 self.parseLine(mydata)
81 def parseLine(self, data):
82 if self.currentCommand == self.CMD_LIST:
83 item = data.split(' - ', 2)
84 self.fetchedList.append(item)
85 self.callCallbacks(self.EVENT_LISTITEM, item)
87 if data.find('Downloading') == 0:
88 self.callCallbacks(self.EVENT_DOWNLOAD, data.split(' ', 5)[1].strip())
89 elif data.find('Upgrading') == 0:
90 self.callCallbacks(self.EVENT_UPGRADE, data.split(' ', 1)[1].split(' ')[0])
91 elif data.find('Installing') == 0:
92 self.callCallbacks(self.EVENT_INSTALL, data.split(' ', 1)[1].split(' ')[0])
93 elif data.find('Configuring') == 0:
94 self.callCallbacks(self.EVENT_CONFIGURING, data.split(' ', 1)[1].split(' ')[0])
95 elif data.find('An error occurred') == 0:
96 self.callCallbacks(self.EVENT_ERROR, None)
97 elif data.find('Failed to download') == 0:
98 self.callCallbacks(self.EVENT_ERROR, None)
99 elif data.find('ipkg_download: ERROR:') == 0:
100 self.callCallbacks(self.EVENT_ERROR, None)
101 elif data.find(' Configuration file \'') >= 0:
102 # Note: the config file update question doesn't end with a newline, so
103 # if we get multiple config file update questions, the next ones
104 # don't necessarily start at the beginning of a line
105 self.callCallbacks(self.EVENT_MODIFIED, data.split(' \'', 1)[1][:-1])
107 def callCallbacks(self, event, param = None):
108 for callback in self.callbackList:
109 callback(event, param)
111 def addCallback(self, callback):
112 self.callbackList.append(callback)
114 def getFetchedList(self):
115 return self.fetchedList
121 return self.cmd.running()
123 def write(self, what):
125 # We except unterminated commands
127 self.cmd.write(what, len(what))