1 from enigma import eConsoleAppContainer
2 from Components.Console import Console
3 from Components.About import about
4 from Components.DreamInfoHandler import DreamInfoHandler
5 from Components.Language import language
6 from Components.Sources.List import List
7 from Components.Ipkg import IpkgComponent
8 from Components.Network import iNetwork
9 from Tools.Directories import pathExists, fileExists, resolveFilename, SCOPE_METADIR
13 class SoftwareTools(DreamInfoHandler):
14 lastDownloadDate = None
15 NetworkConnectionAvailable = None
18 available_updatelist = []
19 available_packetlist = []
20 installed_packetlist = {}
24 aboutInfo = about.getImageVersionString()
25 if aboutInfo.startswith("dev-"):
26 self.ImageVersion = 'Experimental'
28 self.ImageVersion = 'Stable'
29 self.language = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
30 DreamInfoHandler.__init__(self, self.statusCallback, blocking = False, neededTag = 'ALL_TAGS', neededFlag = self.ImageVersion, language = self.language)
31 self.directory = resolveFilename(SCOPE_METADIR)
33 self.NotifierCallback = None
34 self.Console = Console()
35 self.UpdateConsole = Console()
37 self.unwanted_extensions = ('-dbg', '-dev', '-doc')
38 self.ipkg = IpkgComponent()
39 self.ipkg.addCallback(self.ipkgCallback)
41 def statusCallback(self, status, progress):
44 def startSoftwareTools(self, callback = None):
45 if callback is not None:
46 self.NotifierCallback = callback
47 iNetwork.checkNetworkState(self.checkNetworkCB)
49 def checkNetworkCB(self,data):
52 SoftwareTools.NetworkConnectionAvailable = True
55 SoftwareTools.NetworkConnectionAvailable = False
58 def getUpdates(self, callback = None):
59 if SoftwareTools.NetworkConnectionAvailable == True:
60 SoftwareTools.lastDownloadDate = time()
61 if SoftwareTools.list_updating is False and callback is None:
62 SoftwareTools.list_updating = True
63 self.ipkg.startCmd(IpkgComponent.CMD_UPDATE)
64 elif SoftwareTools.list_updating is False and callback is not None:
65 SoftwareTools.list_updating = True
66 self.NotifierCallback = callback
67 self.ipkg.startCmd(IpkgComponent.CMD_UPDATE)
68 elif SoftwareTools.list_updating is True and callback is not None:
69 #update info collecting already in progress
70 self.NotifierCallback = callback
72 SoftwareTools.list_updating = False
73 if callback is not None:
75 elif self.NotifierCallback is not None:
76 self.NotifierCallback(False)
78 def ipkgCallback(self, event, param):
79 if event == IpkgComponent.EVENT_ERROR:
80 SoftwareTools.list_updating = False
81 elif event == IpkgComponent.EVENT_DONE:
82 if SoftwareTools.list_updating:
83 self.startIpkgListAvailable()
86 def startIpkgListAvailable(self, callback = None):
87 if callback is not None:
88 SoftwareTools.list_updating = True
89 if SoftwareTools.list_updating:
90 if not self.UpdateConsole:
91 self.UpdateConsole = Console()
93 self.UpdateConsole.ePopen(cmd, self.IpkgListAvailableCB, callback)
95 def IpkgListAvailableCB(self, result, retval, extra_args = None):
96 (callback) = extra_args
98 if SoftwareTools.list_updating:
99 SoftwareTools.available_packetlist = []
100 for x in result.splitlines():
101 split = x.split(' - ')
102 name = split[0].strip()
103 if not any(name.endswith(x) for x in self.unwanted_extensions):
104 SoftwareTools.available_packetlist.append([name, split[1].strip(), split[2].strip()])
106 self.startInstallMetaPackage()
108 if self.UpdateConsole:
109 if len(self.UpdateConsole.appContainers) == 0:
112 SoftwareTools.list_updating = False
113 if self.UpdateConsole:
114 if len(self.UpdateConsole.appContainers) == 0:
115 if callback is not None:
118 def startInstallMetaPackage(self, callback = None):
119 if callback is not None:
120 SoftwareTools.list_updating = True
121 if SoftwareTools.list_updating:
122 if not self.UpdateConsole:
123 self.UpdateConsole = Console()
124 cmd = "ipkg install enigma2-meta enigma2-plugins-meta enigma2-skins-meta"
125 self.UpdateConsole.ePopen(cmd, self.InstallMetaPackageCB, callback)
127 def InstallMetaPackageCB(self, result, retval, extra_args = None):
128 (callback) = extra_args
130 self.fillPackagesIndexList()
132 self.startIpkgListInstalled()
134 if self.UpdateConsole:
135 if len(self.UpdateConsole.appContainers) == 0:
138 SoftwareTools.list_updating = False
139 if self.UpdateConsole:
140 if len(self.UpdateConsole.appContainers) == 0:
141 if callback is not None:
144 def startIpkgListInstalled(self, callback = None):
145 if callback is not None:
146 SoftwareTools.list_updating = True
147 if SoftwareTools.list_updating:
148 if not self.UpdateConsole:
149 self.UpdateConsole = Console()
150 cmd = "ipkg list_installed"
151 self.UpdateConsole.ePopen(cmd, self.IpkgListInstalledCB, callback)
153 def IpkgListInstalledCB(self, result, retval, extra_args = None):
154 (callback) = extra_args
156 SoftwareTools.installed_packetlist = {}
157 for x in result.splitlines():
158 split = x.split(' - ')
159 name = split[0].strip()
160 if not any(name.endswith(x) for x in self.unwanted_extensions):
161 SoftwareTools.installed_packetlist[name] = split[1].strip()
165 if self.UpdateConsole:
166 if len(self.UpdateConsole.appContainers) == 0:
169 SoftwareTools.list_updating = False
170 if self.UpdateConsole:
171 if len(self.UpdateConsole.appContainers) == 0:
172 if callback is not None:
175 def countUpdates(self, callback = None):
176 SoftwareTools.available_updates = 0
177 SoftwareTools.available_updatelist = []
178 for package in self.packagesIndexlist[:]:
179 attributes = package[0]["attributes"]
180 packagename = attributes["packagename"]
181 for x in SoftwareTools.available_packetlist:
182 if x[0] == packagename:
183 if SoftwareTools.installed_packetlist.has_key(packagename):
184 if SoftwareTools.installed_packetlist[packagename] != x[1]:
185 SoftwareTools.available_updates +=1
186 SoftwareTools.available_updatelist.append([packagename])
188 SoftwareTools.list_updating = False
189 if self.UpdateConsole:
190 if len(self.UpdateConsole.appContainers) == 0:
191 if callback is not None:
194 elif self.NotifierCallback is not None:
195 self.NotifierCallback(True)
196 self.NotifierCallback = None
198 def startIpkgUpdate(self, callback = None):
200 self.Console = Console()
202 self.Console.ePopen(cmd, self.IpkgUpdateCB, callback)
204 def IpkgUpdateCB(self, result, retval, extra_args = None):
205 (callback) = extra_args
208 if len(self.Console.appContainers) == 0:
209 if callback is not None:
213 def cleanupSoftwareTools(self):
214 if self.NotifierCallback is not None:
215 self.NotifierCallback = None
217 if self.Console is not None:
218 if len(self.Console.appContainers):
219 for name in self.Console.appContainers.keys():
220 self.Console.kill(name)
221 if self.UpdateConsole is not None:
222 if len(self.UpdateConsole.appContainers):
223 for name in self.UpdateConsole.appContainers.keys():
224 self.UpdateConsole.kill(name)
226 iSoftwareTools = SoftwareTools()