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