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