-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoftwarePanel.py
More file actions
236 lines (221 loc) · 12.6 KB
/
SoftwarePanel.py
File metadata and controls
236 lines (221 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
from Plugins.Plugin import PluginDescriptor
from Screens.Screen import Screen
from Screens.MessageBox import MessageBox
from Components.ActionMap import ActionMap
from Components.Label import Label
from Components.Pixmap import Pixmap
from Components.Sources.List import List
from Components.Sources.StaticText import StaticText
from Components.Ipkg import IpkgComponent
from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmapAlphaBlend
from Tools.LoadPixmap import LoadPixmap
from enigma import ePixmap
from Tools.Directories import resolveFilename, SCOPE_CURRENT_PLUGIN, SCOPE_CURRENT_SKIN, SCOPE_METADIR
from os import path as os_path
import os
from boxbranding import getMachineBrand, getMachineName
class SoftwarePanel(Screen):
def __init__(self, session, *args):
Screen.__init__(self, session)
Screen.setTitle(self, _('Software Panel'))
skin = '\n\t\t<screen name="SoftwarePanel" position="center,center" size="650,605" title="Software Panel">\n\t\t\t<widget name="a_off" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Infopanel/icons/aoff.png" position="10,10" zPosition="1" size="36,97" alphatest="on" />\n\t\t\t<widget name="a_red" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Infopanel/icons/ared.png" position="10,10" zPosition="1" size="36,97" alphatest="on" />\n\t\t\t<widget name="a_yellow" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Infopanel/icons/ayellow.png" position="10,10" zPosition="1" size="36,97" alphatest="on" />\n\t\t\t<widget name="a_green" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/Infopanel/icons/agreen.png" position="10,10" zPosition="1" size="36,97" alphatest="on" />\n\t\t\t<widget name="feedstatusRED" position="60,14" size="200,30" zPosition="1" font="Regular;25" halign="left" transparent="1" />\n\t\t\t<widget name="feedstatusYELLOW" position="60,46" size="200,30" zPosition="1" font="Regular;25" halign="left" transparent="1" />\n\t\t\t<widget name="feedstatusGREEN" position="60,78" size="200,30" zPosition="1" font="Regular;25" halign="left" transparent="1" />\n\t\t\t<widget name="packagetext" position="180,50" size="350,30" zPosition="1" font="Regular;25" halign="right" transparent="1" />\n\t\t\t<widget name="packagenr" position="511,50" size="50,30" zPosition="1" font="Regular;25" halign="right" transparent="1" />\n\t\t\t<widget source="list" render="Listbox" position="10,120" size="630,365" scrollbarMode="showOnDemand">\n\t\t\t\t<convert type="TemplatedMultiContent">\n\t\t\t\t\t{"template": [\n\t\t\t\t\t\t\tMultiContentEntryText(pos = (5, 1), size = (540, 28), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name\n\t\t\t\t\t\t\tMultiContentEntryText(pos = (5, 26), size = (540, 20), font=1, flags = RT_HALIGN_LEFT, text = 2), # index 2 is the description\n\t\t\t\t\t\t\tMultiContentEntryPixmapAlphaBlend(pos = (545, 2), size = (48, 48), png = 4), # index 4 is the status pixmap\n\t\t\t\t\t\t\tMultiContentEntryPixmapAlphaBlend(pos = (5, 50), size = (610, 2), png = 5), # index 4 is the div pixmap\n\t\t\t\t\t\t],\n\t\t\t\t\t"fonts": [gFont("Regular", 22),gFont("Regular", 14)],\n\t\t\t\t\t"itemHeight": 52\n\t\t\t\t\t}\n\t\t\t\t</convert>\n\t\t\t</widget>\n\t\t\t<ePixmap pixmap="skin_default/buttons/red.png" position=" 30,570" size="35,27" alphatest="blend" />\n\t\t\t<widget name="key_green_pic" pixmap="skin_default/buttons/green.png" position="290,570" size="35,27" alphatest="blend" />\n\t\t\t<widget name="key_red" position=" 80,573" size="200,26" zPosition="1" font="Regular;22" halign="left" transparent="1" />\n\t\t\t<widget name="key_green" position="340,573" size="200,26" zPosition="1" font="Regular;22" halign="left" transparent="1" />\n\t\t</screen> '
self.skin = skin
self.list = []
self.statuslist = []
self['list'] = List(self.list)
self['a_off'] = Pixmap()
self['a_red'] = Pixmap()
self['a_yellow'] = Pixmap()
self['a_green'] = Pixmap()
self['key_green_pic'] = Pixmap()
self['key_red_pic'] = Pixmap()
self['key_red'] = Label(_('Cancel'))
self['key_green'] = Label(_('Update'))
self['packagetext'] = Label(_('Updates Available:'))
self['packagenr'] = Label('0')
self['feedstatusRED'] = Label('< ' + _('feed status'))
self['feedstatusYELLOW'] = Label('< ' + _('feed status'))
self['feedstatusGREEN'] = Label('< ' + _('feed status'))
self['key_green'].hide()
self['key_green_pic'].hide()
self.update = False
self.packages = 0
self.ipkg = IpkgComponent()
self.ipkg.addCallback(self.ipkgCallback)
self['actions'] = ActionMap(['OkCancelActions',
'DirectionActions',
'ColorActions',
'SetupActions'], {'cancel': self.Exit,
'green': self.Green,
'red': self.Exit}, -2)
self.onLayoutFinish.append(self.layoutFinished)
def Exit(self):
self.ipkg.stop()
self.close()
def Green(self):
if self.packages > 0:
if self.packages <= 200:
from Plugins.SystemPlugins.SoftwareManager.plugin import UpdatePlugin
self.session.open(UpdatePlugin)
self.close()
else:
print 'DO NOT UPDATE !!!'
message = _('There are to many update packages !!\n\nThere is a risk that your %s %s will not\nboot after online-update, or will show disfunction in running Image.\n\nYou need to flash new !!\n\nDo you want to flash-online ?') % (getMachineBrand(), getMachineName())
self.session.openWithCallback(self.checkPackagesCallback, MessageBox, message, default=True)
def checkPackagesCallback(self, ret):
print ret
if ret:
from Plugins.SystemPlugins.SoftwareManager.Flash_online import FlashOnline
self.session.open(FlashOnline)
self.close()
def layoutFinished(self):
self.checkTraficLight()
self.rebuildList()
def UpdatePackageNr(self):
self.packages = len(self.list)
print self.packages
print 'packagenr' + str(self.packages)
self['packagenr'].setText(str(self.packages))
if self.packages == 0:
self['key_green'].hide()
self['key_green_pic'].hide()
else:
self['key_green'].show()
self['key_green_pic'].show()
def checkTraficLight(self):
print 'checkTraficLight'
from urllib import urlopen
import socket
self['a_red'].hide()
self['a_yellow'].hide()
self['a_green'].hide()
self['feedstatusRED'].hide()
self['feedstatusYELLOW'].hide()
self['feedstatusGREEN'].hide()
currentTimeoutDefault = socket.getdefaulttimeout()
socket.setdefaulttimeout(3)
try:
urlopenATV = 'http://ampel.mynonpublic.com/Ampel/index.php'
d = urlopen(urlopenATV)
tmpStatus = d.read()
if 'rot.png' in tmpStatus:
self['a_off'].hide()
self['a_red'].show()
self['feedstatusRED'].show()
elif 'gelb.png' in tmpStatus:
self['a_off'].hide()
self['a_yellow'].show()
self['feedstatusYELLOW'].show()
elif 'gruen.png' in tmpStatus:
self['a_off'].hide()
self['a_green'].show()
self['feedstatusGREEN'].show()
except:
self['a_off'].show()
socket.setdefaulttimeout(currentTimeoutDefault)
def setStatus(self, status = None):
if status:
self.statuslist = []
divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/div-h.png'))
if status == 'update':
if os_path.exists(resolveFilename(SCOPE_CURRENT_SKIN, 'icons/upgrade.png')):
statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'icons/upgrade.png'))
else:
statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, 'SystemPlugins/SoftwareManager/upgrade.png'))
self.statuslist.append((_('Package list update'),
'',
_('Trying to download a new updatelist. Please wait...'),
'',
statuspng,
divpng))
elif status == 'error':
if os_path.exists(resolveFilename(SCOPE_CURRENT_SKIN, 'icons/remove.png')):
statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'icons/remove.png'))
else:
statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, 'SystemPlugins/SoftwareManager/remove.png'))
self.statuslist.append((_('Error'),
'',
_('There was an error downloading the updatelist. Please try again.'),
'',
statuspng,
divpng))
elif status == 'noupdate':
if os_path.exists(resolveFilename(SCOPE_CURRENT_SKIN, 'icons/installed.png')):
statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'icons/installed.png'))
else:
statuspng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, 'SystemPlugins/SoftwareManager/installed.png'))
self.statuslist.append((_('Nothing to upgrade'),
'',
_('There are no updates available.'),
'',
statuspng,
divpng))
self['list'].setList(self.statuslist)
def rebuildList(self):
self.setStatus('update')
self.ipkg.startCmd(IpkgComponent.CMD_UPDATE)
def ipkgCallback(self, event, param):
if event == IpkgComponent.EVENT_ERROR:
self.setStatus('error')
elif event == IpkgComponent.EVENT_DONE:
if self.update == False:
self.update = True
self.ipkg.startCmd(IpkgComponent.CMD_UPGRADE_LIST)
else:
self.buildPacketList()
def buildEntryComponent(self, name, version, description, state):
divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/div-h.png'))
if not description:
description = 'No description available.'
if state == 'installed':
if os_path.exists(resolveFilename(SCOPE_CURRENT_SKIN, 'icons/installed.png')):
installedpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'icons/installed.png'))
else:
installedpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, 'SystemPlugins/SoftwareManager/installed.png'))
return (name,
version,
_(description),
state,
installedpng,
divpng)
elif state == 'upgradeable':
if os_path.exists(resolveFilename(SCOPE_CURRENT_SKIN, 'icons/upgradeable.png')):
upgradeablepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'icons/upgradeable.png'))
else:
upgradeablepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, 'SystemPlugins/SoftwareManager/upgradeable.png'))
return (name,
version,
_(description),
state,
upgradeablepng,
divpng)
else:
if os_path.exists(resolveFilename(SCOPE_CURRENT_SKIN, 'icons/installable.png')):
installablepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'icons/installable.png'))
else:
installablepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_PLUGIN, 'SystemPlugins/SoftwareManager/installable.png'))
return (name,
version,
_(description),
state,
installablepng,
divpng)
def buildPacketList(self):
self.list = []
fetchedList = self.ipkg.getFetchedList()
excludeList = self.ipkg.getExcludeList()
if len(fetchedList) > 0:
for x in fetchedList:
try:
self.list.append(self.buildEntryComponent(x[0], x[1], x[2], 'upgradeable'))
except:
print '[SOFTWAREPANEL] ' + x[0] + ' no valid architecture, ignoring !!'
if self.list:
self['list'].setList(self.list)
else:
self.setStatus('noupdate')
elif len(fetchedList) == 0:
self.setStatus('noupdate')
else:
self.setStatus('error')
self.UpdatePackageNr()