[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / 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                 self.processed_packages = []
29                 
30                 self.activity = 0
31                 self.activityTimer = eTimer()
32                 self.activityTimer.callback.append(self.doActivityTimer)
33                 #self.activityTimer.start(100, False)
34                                 
35                 self.ipkg = IpkgComponent()
36                 self.ipkg.addCallback(self.ipkgCallback)
37                 
38                 self.runningCmd = None
39                 self.runNextCmd()
40                 
41                 self["actions"] = ActionMap(["WizardActions"], 
42                 {
43                         "ok": self.exit, 
44                         "back": self.exit
45                 }, -1)
46                 
47         def runNextCmd(self):
48                 if self.runningCmd is None:
49                         self.runningCmd = 0
50                 else:
51                         self.runningCmd += 1
52                 print len(self.cmdList), self.runningCmd
53                 if len(self.cmdList) - 1 < self.runningCmd:
54                         self.activityslider.setValue(0)
55                         self.slider.setValue(len(self.cmdList))
56                                 
57                         self.package.setText("")
58                         self.status.setText(_("Done - Installed, upgraded or removed %d packages with %d errors") % (self.packages, self.error))
59                         return False
60                 else:
61                         cmd = self.cmdList[self.runningCmd]
62                         self.slider.setValue(self.runningCmd)
63                         self.ipkg.startCmd(cmd[0], args = cmd[1])
64                         self.startActivityTimer()
65                         
66         def doActivityTimer(self):
67                 if not self.ipkg.isRunning():
68                         self.stopActivityTimer()
69                 else:
70                         self.activity += 1
71                         if self.activity == 100:
72                                 self.activity = 0
73                         self.activityslider.setValue(self.activity)
74                 
75         def startActivityTimer(self):
76                 self.activityTimer.start(100, False)
77                 
78         def stopActivityTimer(self):
79                 self.activityTimer.stop()
80                 
81         def ipkgCallback(self, event, param):
82                 if event == IpkgComponent.EVENT_DOWNLOAD:
83                         self.status.setText(_("Downloading"))
84                 elif event == IpkgComponent.EVENT_UPGRADE:
85                         if self.sliderPackages.has_key(param):
86                                 self.slider.setValue(self.sliderPackages[param])
87                         self.package.setText(param)
88                         self.status.setText(_("Upgrading"))
89                         if not param in self.processed_packages:
90                                 self.processed_packages.append(param)
91                                 self.packages += 1
92                 elif event == IpkgComponent.EVENT_INSTALL:
93                         self.package.setText(param)
94                         self.status.setText(_("Installing"))
95                         if not param in self.processed_packages:
96                                 self.processed_packages.append(param)
97                                 self.packages += 1
98                 elif event == IpkgComponent.EVENT_REMOVE:
99                         self.package.setText(param)
100                         self.status.setText(_("Removing"))
101                         if not param in self.processed_packages:
102                                 self.processed_packages.append(param)
103                                 self.packages += 1
104                 elif event == IpkgComponent.EVENT_CONFIGURING:
105                         self.package.setText(param)
106                         self.status.setText(_("Configuring"))
107                 elif event == IpkgComponent.EVENT_ERROR:
108                         self.error += 1
109                 elif event == IpkgComponent.EVENT_DONE:
110                         self.runNextCmd()
111                 elif event == IpkgComponent.EVENT_MODIFIED:
112                         self.session.openWithCallback(
113                                 self.modificationCallback,
114                                 MessageBox,
115                                 _("A configuration file (%s) was modified since Installation.\nDo you want to keep your version?") % (param)
116                         )
117
118         def modificationCallback(self, res):
119                 self.ipkg.write(res and "N" or "Y")
120
121         def exit(self):
122                 if not self.ipkg.isRunning():
123                         self.close()