use ScrollLabel in update plugin to let the user see the whole result of the update...
[enigma2.git] / lib / python / Plugins / update / plugin.py
1 from enigma import *
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Components.ActionMap import ActionMap
5 from Components.ScrollLabel import ScrollLabel
6 from Components.GUIComponent import *
7
8 import os
9
10 class Upgrade(Screen):
11         skin = """
12                 <screen position="100,100" size="550,400" title="IPKG upgrade..." >
13                         <widget name="text" position="0,0" size="550,400" font="Regular;15" />
14                 </screen>"""
15                 
16         def __init__(self, session, args = None):
17                 self.skin = Upgrade.skin
18                 Screen.__init__(self, session)
19
20                 self["text"] = ScrollLabel(_("Please press OK!"))
21                                 
22                 self["actions"] = ActionMap(["WizardActions", "DirectionActions"], 
23                 {
24                         "ok": self.go,
25                         "back": self.close,
26                         "up": self["text"].pageUp,
27                         "down": self["text"].pageDown
28                 }, -1)
29                 
30                 self.update = True
31                 self.delayTimer = eTimer()
32                 self.delayTimer.timeout.get().append(self.doUpdateDelay)
33                 
34         def go(self):
35                 if self.update:
36                         self.session.openWithCallback(self.doUpdate, MessageBox, _("Do you want to update your Dreambox?\nAfter pressing OK, please wait!"))            
37                 else:
38                         self.close()
39         
40         def doUpdateDelay(self):
41                 lines = os.popen("ipkg update && ipkg upgrade -force-defaults -force-overwrite", "r").readlines()
42                 string = ""
43                 for x in lines:
44                         string += x
45                 self["text"].setText(_("Updating finished. Here is the result:") + "\n\n" + string)
46                 self.update = False
47                         
48         
49         def doUpdate(self, val = False):
50                 if val == True:
51                         self["text"].setText(_("Updating... Please wait... This can take some minutes..."))
52                         self.delayTimer.start(0, 1)
53                 else:
54                         self.close()
55
56 RT_HALIGN_LEFT = 0
57 RT_HALIGN_RIGHT = 1
58 RT_HALIGN_CENTER = 2
59 RT_HALIGN_BLOCK = 4
60
61 RT_VALIGN_TOP = 0
62 RT_VALIGN_CENTER = 8
63 RT_VALIGN_BOTTOM = 16
64
65 def PacketEntryComponent(packet):
66         res = [ packet ]
67         
68         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0,250, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, packet[0]))
69         res.append((eListboxPythonMultiContent.TYPE_TEXT, 250, 0, 200, 30, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, packet[1]))
70         res.append((eListboxPythonMultiContent.TYPE_TEXT, 450, 0, 100, 30, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, packet[2]))
71         return res
72
73 class PacketList(GUIComponent):
74         def __init__(self, list):
75                 GUIComponent.__init__(self)
76                 self.l = eListboxPythonMultiContent()
77                 self.l.setList(list)
78                 self.l.setFont(0, gFont("Regular", 20))
79                 self.l.setFont(1, gFont("Regular", 18))
80         
81         def getCurrent(self):
82                 return self.l.getCurrentSelection()
83         
84         def GUIcreate(self, parent):
85                 self.instance = eListbox(parent)
86                 self.instance.setContent(self.l)
87                 self.instance.setItemHeight(30)
88         
89         def GUIdelete(self):
90                 self.instance.setContent(None)
91                 self.instance = None
92
93         def invalidate(self):
94                 self.l.invalidate()
95
96 class Ipkg(Screen):
97         skin = """
98                 <screen position="100,100" size="550,400" title="IPKG upgrade..." >
99                         <widget name="list" position="0,0" size="550,400" scrollbarMode="showOnDemand" />
100                 </screen>"""
101                 
102         def __init__(self, session, args = None):
103                 self.skin = Ipkg.skin
104                 Screen.__init__(self, session)
105         
106                 list = []
107                 self.list = list
108                 self.fillPacketList()
109
110                 self["list"] = PacketList(self.list)
111                                 
112                 self["actions"] = ActionMap(["WizardActions"], 
113                 {
114                         "ok": self.close,
115                         "back": self.close
116                 }, -1)
117                 
118
119         def fillPacketList(self):
120                 lines = os.popen("ipkg list", "r").readlines()
121                 packetlist = []
122                 for x in lines:
123                         split = x.split(' - ')
124                         packetlist.append([split[0].strip(), split[1].strip()])
125                 
126                 lines = os.popen("ipkg list_installed", "r").readlines()
127                 
128                 installedlist = {}
129                 for x in lines:
130                         split = x.split(' - ')
131                         installedlist[split[0].strip()] = split[1].strip()
132                 
133                 for x in packetlist:
134                         status = ""
135                         if installedlist.has_key(x[0]):
136                                 if installedlist[x[0]] == x[1]:
137                                         status = "installed"
138                                 else:
139                                         status = "upgradable"
140                         self.list.append(PacketEntryComponent([x[0], x[1], status]))
141                 
142         def go(self):
143                 if self.update:
144                         self.session.openWithCallback(self.doUpdate, MessageBox, _("Do you want to update your Dreambox?\nAfter pressing OK, please wait!"))            
145                 else:
146                         self.close()
147         
148         def doUpdateDelay(self):
149                 lines = os.popen("ipkg update && ipkg upgrade", "r").readlines()
150                 string = ""
151                 for x in lines:
152                         string += x
153                 self["text"].setText(_("Updating finished. Here is the result:") + "\n\n" + string)
154                 self.update = False
155                         
156         
157         def doUpdate(self, val = False):
158                 if val == True:
159                         self["text"].setText(_("Updating... Please wait... This can take some minutes..."))
160                         self.delayTimer.start(0, 1)
161                 else:
162                         self.close()
163
164
165
166 def autostart():
167         return
168         os.popen("ipkg update", "r")    
169 #
170 #def autoend():
171         #print "**************************** AUTOEND"
172
173 def getPicturePaths():
174         return ["update.png", "update.png"]
175
176 def getPlugins():
177         return [("Softwareupdate", "Updates your receiver's software", "screen", "Upgrade"),
178                         ("IPKG", "Updates your receiver's software", "screen", "Ipkg")]
179         
180 def getMenuRegistrationList():
181         list = []
182         list.append(("setup", 2, "Softwareupdate", "Upgrade"))
183         return list