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