Change mkpart from none to optimal (should fix 4k sector alignment)
[enigma2-plugins.git] / eparted / src / eparted.py
1 # -*- coding: utf-8 -*-
2 # code by GeminiTeam
3
4 from enigma import eTimer
5
6 from Screens.Screen import Screen
7 from Screens.MessageBox import MessageBox
8
9 from Components.Label import Label
10 from Components.Pixmap import MultiPixmap
11 from Components.Sources.StaticText import StaticText
12 from Components.Sources.List import List
13 from Components.ActionMap import ActionMap
14 from Components.MenuList import MenuList
15 from Components.Console import Console
16 from Tools.Directories import pathExists, createDir
17 from Tools.BoundFunction import boundFunction
18 from Tools.LoadPixmap import LoadPixmap
19
20 from Tools.Directories import resolveFilename, SCOPE_SKIN
21 SkinDefaultPath = resolveFilename(SCOPE_SKIN, "skin_default/")
22
23 from Components.ConfigList import ConfigListScreen
24 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigInteger, ConfigYesNo, ConfigText, ConfigSelection, NoSave
25 config.plugins.eparted = ConfigSubsection()
26
27 from locale import _
28 from os import system as os_system, path as os_path, listdir
29
30 #from Plugins.Bp.geminimain.gTools import cleanexit
31
32 LIST_TYPE_DEV = 0
33 LIST_TYPE_PAR = 1
34 LIST_TYPE = 0
35
36 DEV_PATH = 1
37 DEV_SIZE = 2
38 DEV_TYPE = 3
39 DEV_NAME = 7
40
41 PA_NR = 1
42 PA_START = 2
43 PA_END = 3
44 PA_SIZE = 4
45 PA_FS = 5
46 PA_TYPE = 6
47 PA_NAME = 7
48
49 #-----------------------------------------------------------------------------
50
51 def getInt_epart(val):
52         try:
53                 return int(float(val[0:-2]))#Einheit abschneiden
54         except:
55                 return 0
56
57 def parseCmd(result):
58         devlist = []
59         try:
60                 entry = []
61                 addok = False
62                 for x in result.split('\n'):
63                         #if x=="BYT;":#start
64                         if x.find("BYT;") >= 0:
65                                 addok = True
66                         elif x == "":#end
67                                 if addok and len(entry):
68                                         devlist.append(entry)
69                                 addok = False
70                                 entry = []
71                         else:
72                                 if addok and len(x) > 1 and x[len(x) - 1] == ';':
73                                         l = x.split(':')
74                                         if len(l) == 7:#Part
75                                                 l.insert(0, LIST_TYPE_PAR)
76                                                 l[PA_START] = getInt_epart(l[PA_START])
77                                                 l[PA_END] = getInt_epart(l[PA_END])
78                                                 l[PA_SIZE] = getInt_epart(l[PA_SIZE])
79                                                 l[PA_NAME] = ""
80                                                 if l[PA_FS].find("linux-swap") == 0:
81                                                         l[PA_FS] = "linux-swap"
82                                                 entry.append(l)
83                                         elif len(l) == 8:#Device
84                                                 if l[0].find("/dev/mtd") < 0:
85                                                         l.insert(0, LIST_TYPE_DEV)
86                                                         entry.append(l)
87         except:
88                 print "[eParted] <parse error>"
89                 return []
90         return devlist
91
92 def myExecute(cmd, session, test=False):
93         if test:
94                 from time import sleep
95                 sleep(5)
96                 result = 0
97         else:
98                 res = os_system(cmd)
99                 result = (res >> 8)
100         print "[eParted]", result, cmd
101         if result != 0 and session is not None:
102                 session.open(MessageBox, _("Error command '%s'") % cmd, MessageBox.TYPE_ERROR, timeout=8)
103         return result
104         
105 def getMountP():
106         try:
107                 mounts = open("/proc/mounts")
108         except IOError:
109                 return []
110
111         lines = mounts.readlines()
112         mounts.close()
113         return lines
114
115 def ismounted(dev):
116         for x in getMountP():
117                 parts = x.strip().split(" ")
118                 if len(parts) > 1:
119                         realpath = os_path.realpath(parts[0])
120                         if realpath == dev:
121                                 return parts[1]
122         return None
123
124 rereaddevices = False
125 #-------------------------------------------------------------------------------------
126
127 class Ceparted(Screen):
128         skin = """<screen position="center,center" size="600,200" title="eParted v0.13">
129                         <widget name="list" position="5,5" size="590,190" />
130                 </screen>"""
131         def __init__(self, session):
132                 Screen.__init__(self, session)
133
134                 self["actions"] = ActionMap(["OkCancelActions"],
135                 {
136                         "cancel": self.Exit,
137                         "ok": self.Ok
138                 }, -1)
139
140                 self["list"] = MenuList(list=[])
141                 self.Console = Console()
142                 global rereaddevices
143                 rereaddevices = True
144                 self.__readDev()
145
146         def Ok(self):
147                 sel = self["list"].getCurrent()
148                 if sel and sel[1]:
149                         global rereaddevices
150                         rereaddevices = False
151                         self.session.openWithCallback(self.__readDev, Cpart, sel[1])
152         
153         def __readDev(self):
154                 global rereaddevices
155                 if rereaddevices:
156                         self.Console.ePopen("parted -m -l", self.__FinishedConsole)
157                 
158         def Exit(self):
159                 self.Console.killAll()
160                 self.close()
161                 #cleanexit(__name__)
162
163         def __FinishedConsole(self, result, retval, extra_args=None):
164                 if retval == 0 and '\n' in result:
165                         list = []
166                         for x in parseCmd(result):
167                                 if x[0][LIST_TYPE] == LIST_TYPE_DEV:
168                                         name = x[0][DEV_NAME]
169                                         if len(name) == 0:
170                                                 name = x[0][DEV_PATH]
171                                         tstr = name
172                                         tstr += "  (%s - %d %s %s)" % (x[0][DEV_SIZE], len(x) - 1, _("partition(s)"), x[0][DEV_PATH])
173                                         list.append((tstr, (name, x[0][DEV_PATH], x[0][DEV_SIZE])))
174                         self["list"].setList(list)
175
176 #-------------------------------------------------------------------------------------
177
178 class AddPart(Screen, ConfigListScreen):
179         skin = """<screen name="AddPart" position="center,center" size="600,190" title="add Partition" >
180                         <ePixmap pixmap="skin_default/buttons/red.png" position="5,5" zPosition="0" size="140,40" transparent="1" alphatest="on" />
181                         <ePixmap pixmap="skin_default/buttons/green.png" position="155,5" zPosition="0" size="140,40" transparent="1" alphatest="on" />
182                         <widget render="Label" source="key_red" position="5,5" size="140,40" zPosition="2" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" />
183                         <widget render="Label" source="key_green" position="155,5" size="140,40" zPosition="2" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" />
184                         <widget name="config" position="5,60" size="590,120" scrollbarMode="showOnDemand" />
185                 </screen>"""
186
187         def __init__(self, session, maxsize, unit, countpart):
188                 Screen.__init__(self, session)
189                 self.session = session
190                 self.setup_title = _("add partition")
191
192                 menu = []
193                 default = "ext3"
194                 if pathExists("/sbin/mkfs.ext2"):
195                         menu.append("ext2")
196                 if pathExists("/sbin/mkfs.ext3"):
197                         menu.append("ext3")
198                 if pathExists("/sbin/mkfs.ext4"):
199                         menu.append("ext4")
200                         default = "ext4"
201                 if pathExists("/sbin/mkfs.xfs"):
202                         menu.append("xfs")
203                 if pathExists("/sbin/mkswap"):
204                         menu.append("linux-swap")
205                 if pathExists("/sbin/mkfs.vfat"):
206                         menu.append("fat32")
207                 if pathExists("/usr/sbin/mkfs.msdos"):
208                         menu.append("fat16")
209                 config.plugins.eparted.fs = NoSave(ConfigSelection(default=default, choices=menu))
210                 config.plugins.eparted.size = NoSave(ConfigInteger(default=maxsize, limits=[1, maxsize]))
211
212                 list = []
213                 if countpart < 4:#nur 4 parts möglich bei primary
214                         list.append(getConfigListEntry(_("size in %s (max %d %s):") % (unit, maxsize, unit), config.plugins.eparted.size))
215                 list.append(getConfigListEntry(_("filesystem:"), config.plugins.eparted.fs))
216                 ConfigListScreen.__init__(self, list, session=session)
217                 
218                 self["key_red"] = StaticText(_("cancel"))
219                 self["key_green"] = StaticText(_("ok"))
220                 
221                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
222                 {
223                         "red": self.keyCancel,
224                         "cancel": self.keyCancel,
225                         "green": self.keySave,
226                         "save": self.keySave,
227                         "ok": self.keySave,
228                 }, -2)
229
230         def keyCancel(self):
231                 self.close()
232                 
233         def keySave(self):
234                 if config.plugins.eparted.size.value > 0:
235                         self.close((config.plugins.eparted.size.value, config.plugins.eparted.fs.value))
236
237 #-------------------------------------------------------------------------------------
238
239 class Cpart(Screen):
240         PA_TYPE_USE = 1
241         PA_TYPE_LAST = 2
242         PA_TYPE_FREE = 4
243
244         skin = """<screen position="center,center" size="670,200" title="eParted">
245                         <widget source="list" render="Listbox" position="0,0" size="670,160" scrollbarMode="showOnDemand" enableWrapAround="on">
246                         <convert type="TemplatedMultiContent">
247                                 {"template": [
248                                 MultiContentEntryText(pos = (0,5), size = (50, 30), font=0, flags = RT_HALIGN_LEFT, text=0),
249                                 MultiContentEntryText(pos = (60,5), size = (150, 30), font=0, flags = RT_HALIGN_LEFT, text=1),
250                                 MultiContentEntryText(pos = (210,5), size = (150, 30), font=0, flags = RT_HALIGN_LEFT, text=2),
251                                 MultiContentEntryText(pos = (360,5), size = (150, 30), font=0, flags = RT_HALIGN_LEFT, text=3),
252                                 MultiContentEntryText(pos = (510,5), size = (160, 30), font=0, flags = RT_HALIGN_LEFT, text=4)
253                                 ],
254                                 "fonts": [gFont("Regular", 20)],
255                                 "itemHeight": 35
256                                 }
257                         </convert>
258                         </widget>
259                         <widget name="PixmapRed" position="25,170" size="15,16" pixmaps="skin_default/buttons/button_red_off.png,skin_default/buttons/button_red.png" transparent="1" alphatest="on" />
260                         <widget name="LabelRed" position="50,160" size="150,40" font="Regular;19" valign="center" />
261                         <widget name="PixmapGreen" position="225,170" size="15,16" pixmaps="skin_default/buttons/button_green_off.png,skin_default/buttons/button_green.png" transparent="1" alphatest="on" />
262                         <widget name="LabelGreen" position="250,160" size="150,40" font="Regular;19" valign="center" />
263                         <widget name="PixmapBlue" position="425,170" size="15,16" pixmaps="skin_default/buttons/button_blue_off.png,skin_default/buttons/button_blue.png" transparent="1" alphatest="on" />
264                         <widget name="LabelBlue" position="450,160" size="150,40" font="Regular;19" valign="center" />
265                 </screen>"""
266
267         def __init__(self, session, entry):
268                 Screen.__init__(self, session)
269
270                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
271                 {
272                         "cancel": self.Exit,
273                         "green": self.KeyGreen,
274                         "blue": self.KeyBlue,
275                         "red": self.KeyRed
276                 }, -1)
277
278                 self["list"] = List(list=[])
279                 self["list"].onSelectionChanged.append(self.__SetLabels)
280                 self["PixmapRed"] = MultiPixmap()
281                 self["PixmapGreen"] = MultiPixmap()
282                 self["PixmapBlue"] = MultiPixmap()
283                 self["LabelRed"] = Label()
284                 self["LabelGreen"] = Label()
285                 self["LabelBlue"] = Label()
286
287                 self.__devpath = entry[DEV_PATH]
288                 self.__fullsize = 0
289                 self.__old_part_list = []
290                 self.__new_part_list = []
291                 self.__comlist = []
292                 self.__unit = entry[2][len(entry[2]) - 2:]
293
294                 self.Console = Console()
295                 self.__getPartInfo()
296                 
297         def Exit(self):
298                 self.Console.killAll()
299                 self.close()
300                 
301         def __getPartInfo(self, val=None):
302                 self.Console.ePopen("parted -m %s unit %s print" % (self.__devpath, self.__unit), self.__FinishedConsole)
303                 
304         def __Filllist(self):
305                 list = []
306                 index = self["list"].getIndex()
307                 for x in self.__new_part_list:
308                         if x[LIST_TYPE] == LIST_TYPE_PAR:
309                                 #print x
310                                 p0 = "%s: %s" % (_("Nr"), x[PA_NR])
311                                 p1 = "%s: %d%s" % (_("Start"), x[PA_START], self.__unit)
312                                 p2 = "%s: %d%s" % (_("End"), x[PA_END], self.__unit)
313                                 p3 = "%s: %d%s" % (_("Size"), x[PA_SIZE], self.__unit)
314                                 p4 = "%s: %s" % (_("Type"), x[PA_FS])
315                                 list.append((p0, p1, p2, p3, p4, x))
316                         self["list"].setList(list)
317                 self["list"].setIndex(index)
318                 self.__createCommandList()
319                 
320         def __SetLabels(self):
321                 sel = self["list"].getCurrent()
322                 self["LabelGreen"].setText("")
323                 self["LabelRed"].setText("")
324                 if sel and sel[5]:
325                         if sel[5][PA_TYPE] & self.PA_TYPE_FREE and len(self.__new_part_list) < 6:
326                                 self["PixmapGreen"].setPixmapNum(1)
327                                 self["LabelGreen"].setText(_("add"))
328                         else:
329                                 self["PixmapGreen"].setPixmapNum(0)
330                         if sel[5][PA_TYPE] & self.PA_TYPE_LAST and bool(sel[5][PA_TYPE] & self.PA_TYPE_FREE) == False:
331                                 self["PixmapRed"].setPixmapNum(1)
332                                 self["LabelRed"].setText(_("delete"))
333                         else:
334                                 self["PixmapRed"].setPixmapNum(0)
335                                 
336         def __addFreePart(self, plist, lastPartEnd):
337                 x = [LIST_TYPE_PAR, str(len(plist)), lastPartEnd, self.__fullsize, 0, _("free"), (self.PA_TYPE_FREE | self.PA_TYPE_LAST), ";"]
338                 plist.append(x)
339                 
340         def __FinishedConsole(self, result, retval, extra_args=None):
341                 if retval == 0 and '\n' in result:
342                         tlist = parseCmd(result)
343                         if len(tlist):
344                                 self.__old_part_list = tlist[0][:]
345                                 self.__new_part_list = tlist[0][:]
346
347                         lastPartEnd = 0
348                         count = 2
349                         for x in self.__old_part_list:
350                                 if x[LIST_TYPE] == LIST_TYPE_DEV:
351                                         self.__fullsize = getInt_epart(x[DEV_SIZE])
352                                         name = x[DEV_NAME]
353                                         if len(name) == 0:
354                                                 name = x[DEV_PATH]
355                                         name += " (%s)" % x[DEV_SIZE]
356                                         self.setTitle(name)
357                                 else:
358                                         lastPartEnd = x[PA_END]
359                                         x[PA_TYPE] = self.PA_TYPE_USE
360                                         if count == len(self.__old_part_list):#is letzte part
361                                                 x[PA_TYPE] |= self.PA_TYPE_LAST
362                                         count += 1
363
364                         if lastPartEnd < self.__fullsize:#Wenn noch Frei, Part erstellen
365                                 self.__addFreePart(self.__old_part_list, lastPartEnd)
366                                 self.__addFreePart(self.__new_part_list, lastPartEnd)
367                         
368                         self.__Filllist()
369
370         def KeyBlue(self):
371                 if len(self.__comlist):
372                         self.session.openWithCallback(self.__getPartInfo, Cpartexe, self.__comlist)
373
374         def KeyRed(self):
375                 sel = self["list"].getCurrent()
376                 if sel and sel[1] and sel[5][PA_TYPE] & self.PA_TYPE_LAST and bool(sel[5][PA_TYPE] & self.PA_TYPE_FREE) == False:
377                         try:
378                                 self.__new_part_list.remove(sel[5])#aktuelle part löschen
379                                 for x in self.__new_part_list:
380                                         if x[LIST_TYPE] == LIST_TYPE_PAR:
381                                                 if x[PA_TYPE] & self.PA_TYPE_FREE:#letzte Freie suchen und auch löschen
382                                                         self.__new_part_list.remove(x)
383                                                         break
384                                                 else:
385                                                         x[PA_TYPE] = self.PA_TYPE_USE
386                                 
387                                 lastPartEnd = 0
388                                 if len(self.__new_part_list) > 1:#von letzter Part, TYp setzen und Ende ermitteln
389                                         self.__new_part_list[len(self.__new_part_list) - 1][PA_TYPE] = self.PA_TYPE_USE | self.PA_TYPE_LAST
390                                         lastPartEnd = self.__new_part_list[len(self.__new_part_list) - 1][PA_END]
391                                 
392                                 if lastPartEnd < self.__fullsize:#Wenn noch Frei, Part erstellen
393                                         self.__addFreePart(self.__new_part_list, lastPartEnd)
394                                 #for x in self.__new_part_list:
395                                 #       if x[LIST_TYPE]==LIST_TYPE_PAR:
396                                 #               print x
397                         except:
398                                 print "[eParted] <remove part>"
399                         self.__Filllist()
400                         
401         def KeyGreen(self):
402                 sel = self["list"].getCurrent()
403                 if sel and sel[5] and sel[5][PA_TYPE] & self.PA_TYPE_FREE and sel[5][PA_START] < sel[5][PA_END] and len(self.__new_part_list) < 6:
404                         self.session.openWithCallback(self.__CallbackAddPart, AddPart, sel[5][PA_END] - sel[5][PA_START], self.__unit, len(self.__new_part_list) - 1)
405                         
406         def __CallbackAddPart(self, val=None):
407                 if val:
408                         for x in self.__new_part_list:
409                                 if x[LIST_TYPE] == LIST_TYPE_PAR:
410                                         if x[PA_TYPE] & self.PA_TYPE_FREE:
411                                                 x[PA_SIZE] = val[0]
412                                                 x[PA_FS] = val[1]
413                                                 x[PA_END] = x[PA_START] + x[PA_SIZE]
414                                                 x[PA_TYPE] = self.PA_TYPE_USE | self.PA_TYPE_LAST
415                                                 if x[PA_END] < self.__fullsize:#Wenn noch Frei, Part erstellen
416                                                         self.__addFreePart(self.__new_part_list, x[PA_END])
417                                                 break
418                                         else:
419                                                 x[PA_TYPE] = self.PA_TYPE_USE
420                         self.__Filllist()
421                         
422         def __addPart2Comlist(self, list, val, mkpart=True):
423                 #print val
424                 partnr = val[PA_NR]
425                 if mkpart:
426                         fs = val[PA_FS]
427                         com = "parted -s -a optimal %s mkpart primary %s %s%s %s%s" % (self.__devpath, fs, val[PA_START], self.__unit, val[PA_END], self.__unit)
428                         list.append((com , _("create partition %s") % partnr, None))
429                 
430                 mountdev = None
431                 if val[PA_FS] == "linux-swap":
432                         mkfs = "/sbin/mkswap"
433                 elif val[PA_FS] == "fat16":
434                         mkfs = "/usr/sbin/mkfs.msdos -F 16"
435                 elif val[PA_FS] == "fat32":
436                         mkfs = "/sbin/mkfs.vfat"
437                 else:
438                         mkfs = "/sbin/mkfs." + val[PA_FS]
439                         mountdev = self.__devpath + partnr
440                         if val[PA_FS] == "xfs":
441                                 mkfs += " -f"
442
443                 com = "%s %s%s" % (mkfs, self.__devpath, partnr)
444                 list.append((com , _("make filesystem '%s' on partition %s (%d %s)") % (val[PA_FS], partnr, val[PA_SIZE], self.__unit), mountdev))
445                 
446         def __delPart2Comlist(self, list, val):
447                 partnr = val[PA_NR]
448                 dev = "%s%s" % (self.__devpath, partnr)
449                 mp = ismounted(dev)
450                 if mp is not None:
451                         if myExecute("umount %s" % mp, self.session):
452                                 return
453                 list.insert(0, ("parted -s -a none %s rm %s" % (self.__devpath, partnr), _("delete partition %s") % partnr, None))
454
455         def __createCommandList(self):
456                 self.__comlist = []
457                 #welche parts sollen gelöscht werden
458                 for x in range(len(self.__old_part_list)):
459                         if self.__old_part_list[x][LIST_TYPE] == LIST_TYPE_PAR:
460                                 if bool(self.__old_part_list[x][PA_TYPE] & self.PA_TYPE_FREE) == False:
461                                         if len(self.__new_part_list) > x:
462                                                 if self.__old_part_list[x][PA_SIZE] != self.__new_part_list[x][PA_SIZE]:
463                                                         #print self.__old_part_list[x], self.__new_part_list[x]
464                                                         self.__delPart2Comlist(self.__comlist, self.__old_part_list[x])
465                                         else:
466                                                 self.__delPart2Comlist(self.__comlist, self.__old_part_list[x])
467
468                 #welche parts sollen erstellt werden
469                 for x in range(len(self.__new_part_list)):
470                         if self.__new_part_list[x][LIST_TYPE] == LIST_TYPE_PAR:
471                                 if bool(self.__new_part_list[x][PA_TYPE] & self.PA_TYPE_FREE) == False:
472                                         if len(self.__old_part_list) > x and bool(self.__old_part_list[x][PA_TYPE] & self.PA_TYPE_FREE) == False:
473                                                 if self.__new_part_list[x][PA_SIZE] != self.__old_part_list[x][PA_SIZE]:
474                                                         #print self.__new_part_list[x], self.__old_part_list[x]
475                                                         self.__addPart2Comlist(self.__comlist, self.__new_part_list[x])
476                                                 else:
477                                                         if self.__new_part_list[x][PA_FS] != self.__old_part_list[x][PA_FS]:
478                                                                 self.__addPart2Comlist(self.__comlist, self.__new_part_list[x], False)
479                                         else:
480                                                 self.__addPart2Comlist(self.__comlist, self.__new_part_list[x])
481                 
482
483                 #for x in self.__comlist: print "[eParted] com =",x
484                 if len(self.__comlist):
485                         self["PixmapBlue"].setPixmapNum(1)
486                         self["LabelBlue"].setText(_("execute"))
487                 else:
488                         self["PixmapBlue"].setPixmapNum(0)
489                         self["LabelBlue"].setText("")
490
491 class Cpartexe(Screen):
492         skin = """<screen position="center,center" size="670,400" title=" ">
493                         <widget source="list" render="Listbox" position="0,0" size="670,360" scrollbarMode="showOnDemand" enableWrapAround="on">
494                         <convert type="TemplatedMultiContent">
495                                 {"template": [
496                                 MultiContentEntryText(pos = (40,5), size = (630, 30), font=0, flags = RT_HALIGN_LEFT, text=0),
497                                 MultiContentEntryPixmapAlphaTest(pos = (5, 5), size = (35,35), png=1),
498                                 ],
499                                 "fonts": [gFont("Regular", 22)],
500                                 "itemHeight": 40
501                                 }
502                         </convert>
503                         </widget>
504                         <widget name="PixmapButton" position="25,370" size="15,16" pixmaps="skin_default/buttons/button_green.png,skin_default/buttons/button_green_off.png" transparent="1" alphatest="on" />
505                         <widget name="LabelButton" position="50,360" size="620,40" font="Regular;19" valign="center" />
506                 </screen>"""
507
508         def __init__(self, session, comlist):
509                 Screen.__init__(self, session)
510
511                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
512                 {
513                         "cancel": self.Exit,
514                         "green": self.KeyGreen,
515                         #"red": self.KeyRed
516                 }, -1)
517
518                 self.setTitle(_("execute"))
519                 self["PixmapButton"] = MultiPixmap()
520                 self["LabelButton"] = Label(_("Start") + " ?")
521
522                 self.mountlist = []
523                 list = []
524                 for x in comlist:
525                         print x
526                         list.append((x[1], None, x[0]))
527                         if x[2] is not None:
528                                 self.mountlist.append(x[2])
529                 self["list"] = List(list)
530                 
531                 self.__Stimer = eTimer()
532                 self.__Stimer.callback.append(self.__exeList)
533                 self.__state = -1
534                 
535         def __getPartitionUUID(self, device):
536                 try:
537                         if os_path.exists("/dev/disk/by-uuid"):
538                                 for uuid in listdir("/dev/disk/by-uuid/"):
539                                         if not os_path.exists("/dev/disk/by-uuid/" + uuid):
540                                                 return None
541                                         if os_path.realpath("/dev/disk/by-uuid/" + uuid) == device:
542                                                 return ("/dev/disk/by-uuid/" + uuid, uuid)
543                         else:
544                                 return (device, device[5:])
545                 except:
546                         print "[eParted] <error get UUID>"
547                 return None
548                 
549         def __mountDevice(self):
550                 for x in self.mountlist:
551                         dev = self.__getPartitionUUID(x)
552                         if dev is not None:
553                                 if os_path.exists("/media/" + dev[1]) == False:
554                                         createDir("/media/" + dev[1], True)
555                                 cmd = "mount %s /media/%s" % (dev[0], dev[1])
556                                 myExecute(cmd, None)
557
558         def Exit(self):
559                 if self.__state < 0:
560                         del self.__Stimer
561                         self.__mountDevice()
562                         self.close()
563                 
564         def __exeList(self):
565                 if len(self["list"].list) > self.__state and self.__state > -1:
566                         res = myExecute(self["list"].list[self.__state][2], self.session)
567                         pic = "test_false.png"
568                         if res == 0:
569                                 pic = "test_true.png"
570
571                         self["list"].list[self.__state] = (self["list"].list[self.__state][0], LoadPixmap(path=SkinDefaultPath + pic), self["list"].list[self.__state][2], self["list"].list[self.__state][2])
572                         self["list"].updateList(self["list"].list)
573                         self["list"].setIndex(self.__state)
574                         
575                         if res == 0:
576                                 self.__state += 1
577                         else:
578                                 self.__state = len(self["list"].list)#bei fehler ans Ende der liste
579                                 self["PixmapButton"].setPixmapNum(0)
580                                 self["LabelButton"].setText(_("quit"))
581                                 
582                         self.__Stimer.start(500, True)
583                 else:
584                         self.__state = -2
585                         self["PixmapButton"].setPixmapNum(0)
586                         self["LabelButton"].setText(_("quit"))
587                 
588         def KeyGreen(self):
589                 if self.__state == -1:
590                         global rereaddevices
591                         rereaddevices = True
592                         self.__state += 1
593                         self["PixmapButton"].setPixmapNum(1)
594                         self["LabelButton"].setText(_("Please Wait"))
595                         self["list"].setIndex(0)
596                         self.__Stimer.start(500, True)
597                 elif self.__state == -2:
598                         self.Exit()
599         
600         #def KeyRed(self):
601         #       self.Exit()