Merge branch 'master' of /git/enigma2
[enigma2.git] / lib / python / Screens / Ipkg.py
1 from Components.ActionMap import ActionMap
2 from Components.Ipkg import IpkgComponent
3 from Components.Label import Label
4 from Components.Slider import Slider
5 from Screens.Screen import Screen
6 from Screens.MessageBox import MessageBox
7 from enigma import eTimer
8
9 class Ipkg(Screen):
10         def __init__(self, session, cmdList = []):
11                 Screen.__init__(self, session)
12                 
13                 self.cmdList = cmdList
14
15                 self.sliderPackages = {}
16                 
17                 self.slider = Slider(0, len(cmdList))
18                 self["slider"] = self.slider
19                 self.activityslider = Slider(0, 100)
20                 self["activityslider"] = self.activityslider
21                 self.status = Label(_("Preparing... Please wait"))
22                 self["status"] = self.status
23                 self.package = Label()
24                 self["package"] = self.package
25                 
26                 self.packages = 0
27                 self.error = 0
28                 
29                 self.activity = 0
30                 self.activityTimer = eTimer()
31                 self.activityTimer.callback.append(self.doActivityTimer)
32                 #self.activityTimer.start(100, False)
33                                 
34                 self.ipkg = IpkgComponent()
35                 self.ipkg.addCallback(self.ipkgCallback)
36                 
37                 self.runningCmd = None
38                 self.runNextCmd()
39                 
40                 self["actions"] = ActionMap(["WizardActions"], 
41                 {
42                         "ok": self.exit, 
43                         "back": self.exit
44                 }, -1)
45                 
46         def runNextCmd(self):
47                 if self.runningCmd is None:
48                         self.runningCmd = 0
49                 else:
50                         self.runningCmd += 1
51                 print len(self.cmdList), self.runningCmd
52                 if len(self.cmdList) - 1 < self.runningCmd:
53                         self.activityslider.setValue(0)
54                         self.slider.setValue(len(self.cmdList))
55                                 
56                         self.package.setText("")
57                         self.status.setText(_("Done - Installed, upgraded or removed %d packages with %d errors") % (self.packages, self.error))
58                         return False
59                 else:
60                         cmd = self.cmdList[self.runningCmd]
61                         self.slider.setValue(self.runningCmd)
62                         self.ipkg.startCmd(cmd[0], args = cmd[1])
63                         self.startActivityTimer()
64                         
65         def doActivityTimer(self):
66                 if not self.ipkg.isRunning():
67                         self.stopActivityTimer()
68                 else:
69                         self.activity += 1
70                         if self.activity == 100:
71                                 self.activity = 0
72                         self.activityslider.setValue(self.activity)
73                 
74         def startActivityTimer(self):
75                 self.activityTimer.start(100, False)
76                 
77         def stopActivityTimer(self):
78                 self.activityTimer.stop()
79                 
80         def ipkgCallback(self, event, param):
81                 if event == IpkgComponent.EVENT_DOWNLOAD:
82                         self.status.setText(_("Downloading"))
83                 elif event == IpkgComponent.EVENT_UPGRADE:
84                         if self.sliderPackages.has_key(param):
85                                 self.slider.setValue(self.sliderPackages[param])
86                         self.package.setText(param)
87                         self.status.setText(_("Upgrading"))
88                         self.packages += 1
89                 elif event == IpkgComponent.EVENT_INSTALL:
90                         self.package.setText(param)
91                         self.status.setText(_("Installing"))
92                         self.packages += 1
93                 elif event == IpkgComponent.EVENT_REMOVE:
94                         self.package.setText(param)
95                         self.status.setText(_("Removing"))
96                         self.packages += 1
97                 elif event == IpkgComponent.EVENT_CONFIGURING:
98                         self.package.setText(param)
99                         self.status.setText(_("Configuring"))
100                 elif event == IpkgComponent.EVENT_ERROR:
101                         self.error += 1
102                 elif event == IpkgComponent.EVENT_DONE:
103                         self.runNextCmd()
104                 elif event == IpkgComponent.EVENT_MODIFIED:
105                         self.session.openWithCallback(
106                                 self.modificationCallback,
107                                 MessageBox,
108                                 _("A configuration file (%s) was modified since Installation.\nDo you want to keep your version?") % (param)
109                         )
110
111         def modificationCallback(self, res):
112                 self.ipkg.write(res and "N" or "Y")
113
114         def exit(self):
115                 if not self.ipkg.isRunning():
116                         self.close()