d8de35443474adf75f7cea0c30812411e2d01b1a
[enigma2.git] / lib / python / Plugins / SystemPlugins / CleanupWizard / CleanupWizard.py
1 from Screens.Wizard import wizardManager, WizardSummary
2 from Screens.WizardLanguage import WizardLanguage
3 from Screens.Rc import Rc
4 from Screens.Console import Console
5 from Screens.MessageBox import MessageBox
6 from Components.Console import Console
7 from Components.Ipkg import IpkgComponent
8 from Components.Pixmap import Pixmap, MovingPixmap, MultiPixmap
9 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigText, ConfigLocations, ConfigBoolean
10 from Tools.Directories import fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
11 from os import system, statvfs, stat
12
13
14 def checkFreeSpaceAvailable():
15         try:
16                 stat = statvfs('/')
17         except OSError:
18                 return None
19         return (stat.f_bfree * stat.f_bsize)/1024 #return free space in kiloBytes
20
21
22 class CleanupWizard(WizardLanguage, Rc):
23
24         skin = """
25                 <screen name="CleanupWizard" position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
26                         <widget name="text" position="153,40" size="380,330" font="Regular;22" />
27                         <widget source="list" render="Listbox" position="43,300" size="460,220" scrollbarMode="showOnDemand" >
28                                 <convert type="StringList" />
29                         </widget>
30                         <widget name="config" position="53,340" zPosition="1" size="440,180" transparent="1" scrollbarMode="showOnDemand" />
31                         <ePixmap pixmap="skin_default/buttons/button_red.png" position="40,225" zPosition="0" size="15,16" transparent="1" alphatest="on" />
32                         <widget name="languagetext" position="55,225" size="95,30" font="Regular;18" />
33                         <widget name="wizard" pixmap="skin_default/wizard.png" position="40,50" zPosition="10" size="110,174" alphatest="on" />
34                         <widget name="rc" pixmaps="skin_default/rc.png,skin_default/rcold.png" position="530,50" zPosition="10" size="154,500" alphatest="on" />
35                         <widget name="arrowdown" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
36                         <widget name="arrowdown2" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
37                         <widget name="arrowup" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
38                         <widget name="arrowup2" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
39                 </screen>"""
40
41         def __init__(self, session):
42                 self.xmlfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/CleanupWizard/cleanupwizard.xml")
43                 WizardLanguage.__init__(self, session, showSteps = False, showStepSlider = False)
44                 Rc.__init__(self)
45                 self.session = session
46                 self["wizard"] = Pixmap()
47                 self.selectedAction = None
48                 self.selectedPackage = None
49                 self.NextStep = None
50                 self.Text = None
51                 self.buildListRef = None
52                 self.RemoveRef = None
53                 self.excluded_extensions = ('-skins', '-streamproxy', '-frontprocessorupgrade', '-crashlogautosubmit', '-hotplug', '-webinterface', '-mediascanner', '-genuinedreambox', '-mediaplayer', '-pictureplayer', '-dvdplayer', '-dvdburn', '-videotune', '-videomode', '-softwaremanager', '-skinselector', '-satfinder' )
54                 self.Console = Console()
55                 self.installed_packetlist = []
56                 self.ipkg = IpkgComponent()
57                 self.ipkg.addCallback(self.ipkgCallback)
58
59         def markDone(self):
60                 pass
61
62         def listAction(self):
63                 list = []
64                 list.append((_("OK, remove some extensions"), "removeextensions"))
65                 list.append((_("Exit the cleanup wizard"), "end"))
66                 return list
67
68         def listAgainAction(self):
69                 list = []
70                 list.append((_("OK, remove another extensions"), "removeextensions"))
71                 list.append((_("Exit the cleanup wizard"), "end"))
72                 return list
73
74         def ActionSelectionMade(self, index):
75                 self.selectedAction = index
76                 self.ActionSelect(index)
77
78         def ActionSelect(self, index):
79                 if index == 'end':
80                         self.NextStep = 'end'
81                 else:
82                         self.NextStep = 'removeextensions'
83
84         def ActionSelectionMoved(self):
85                 self.ActionSelect(self.selection)
86
87         def buildList(self,action):
88                 if self.NextStep is not 'end':
89                         if not self.Console:
90                                 self.Console = Console()
91                         cmd = "ipkg list_installed | grep enigma2"
92                         self.Console.ePopen(cmd, self.buildListInstalled_Finished)
93                         self.buildListRef = self.session.openWithCallback(self.buildListfinishedCB, MessageBox, _("Please wait while searching for removable packages..."), type = MessageBox.TYPE_INFO, enable_input = False)
94                 else:
95                         self.buildListfinishedCB(False)
96
97         def buildListInstalled_Finished(self, result, retval, extra_args = None):
98                 if len(result):
99                         self.installed_packetlist = []
100                         for x in result.splitlines():
101                                 split = x.split(' - ')
102                                 if not any(split[0].strip().endswith(x) for x in self.excluded_extensions): #ignore some base plugins
103                                         if split[0].strip() != 'enigma2':
104                                                 self.installed_packetlist.append((split[0].strip()))
105                 self.buildListRef.close(True)
106
107         def buildListfinishedCB(self,data):
108                 self.buildListRef = None
109                 if data is True:
110                         self.currStep = self.getStepWithID(self.NextStep)
111                         self.afterAsyncCode()
112                 else:
113                         self.currStep = self.getStepWithID(self.NextStep)
114                         self.afterAsyncCode()
115
116         def listInstalledPackages(self):
117                 list = []
118                 if self.installed_packetlist and len(self.installed_packetlist):
119                         for x in self.installed_packetlist:
120                                 if x.startswith('enigma2-plugin-'):
121                                         pluginname = x.replace("enigma2-plugin-","")
122                                 elif x.startswith('enigma2-skin-'):
123                                         pluginname = x.replace("enigma2-","")
124                                 else:
125                                         pluginname = x
126                                 list.append( (pluginname,x) )
127                 return list
128
129         def PackageSelectionMade(self, index):
130                 self.PackageSelect(index)
131
132         def PackageSelectionMoved(self):
133                 self.PackageSelect(self.selection)
134
135         def PackageSelect(self, package):
136                 self.selectedPackage = package
137
138         def ipkgCallback(self, event, param):
139                 if event == IpkgComponent.EVENT_ERROR:
140                         freeSpace = checkFreeSpaceAvailable()
141                         txt_line1 = _("There was an error. The package:") + "\n" + str(self.selectedPackage) + "\n" + _("could not be removed") + "\n"
142                         txt_line2 = _("There are now ") + str(freeSpace) + " kB " + _("available") + "\n\n"
143                         txt_line3 = _("Please select an option below.")
144                         self.Text = txt_line1 + txt_line2 + txt_line3
145                         self.NextStep = 'StatusRemoveERROR'
146                         self.RemoveRef.close(True)
147                 elif event == IpkgComponent.EVENT_DONE:
148                         freeSpace = checkFreeSpaceAvailable()
149                         txt_line1 = _("The package:") + "\n" + str(self.selectedPackage) + "\n" + _("was removed successfully") + "\n"
150                         txt_line2 = _("There are now ") + str(freeSpace) + " kB " + _("available") + "\n\n"
151                         txt_line3 = _("Please select an option below.")
152                         self.Text = txt_line1 + txt_line2 + txt_line3
153                         self.NextStep = 'StatusRemoveOK'
154                         self.RemoveRef.close(True)
155                 pass
156
157         def removeExtension(self,extension):
158                 if self.NextStep is not 'end':
159                         self.ipkg.startCmd(IpkgComponent.CMD_REMOVE, {'package': extension})
160                         self.RemoveRef = self.session.openWithCallback(self.removeExtensionFinishedCB, MessageBox, _("Please wait while removing selected package..."), type = MessageBox.TYPE_INFO, enable_input = False)
161                 else:
162                         self.buildListfinishedCB(False)
163
164         def removeExtensionFinishedCB(self,data):
165                 self.RemoveRef = None
166                 if data is True:
167                         self.currStep = self.getStepWithID(self.NextStep)
168                         self.afterAsyncCode()
169                 else:
170                         self.currStep = self.getStepWithID(self.NextStep)
171                         self.afterAsyncCode()
172