from Components.Label import Label
from Components.ActionMap import ActionMap
from Components.config import config, ConfigSelection, getConfigListEntry, ConfigSubsection, ConfigEnableDisable, ConfigYesNo, ConfigInteger
from Components.ConfigList import ConfigListScreen
from Components.Console import Console
from Components.GUIComponent import GUIComponent
from Components.Harddisk import harddiskmanager, CheckSfdiskVer, enableUdevEvent
from Components.MenuList import MenuList
from Components.Pixmap import Pixmap, MultiPixmap
from Components.Sources.List import List
from Components.Sources.StaticText import StaticText
from Plugins.Plugin import PluginDescriptor
from Screens.MessageBox import MessageBox
from Screens.Screen import Screen
from Screens.VirtualKeyBoard import VirtualKeyBoard
from Tools.BoundFunction import boundFunction
from Tools.LoadPixmap import LoadPixmap
from Tools.Notifications import AddNotificationWithCallback
from Tools.Directories import pathExists, fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_CURRENT_PLUGIN, SCOPE_CURRENT_SKIN, SCOPE_METADIR
from skin import loadSkin
from os import system, makedirs, path, listdir, statvfs, popen
import os
import re
import time
from Components.Sources.StaticText import StaticText
from Components.FileList import FileList
from Screens.InputBox import InputBox
from Components.Input import Input
from Screens.ChoiceBox import ChoiceBox
from enigma import eTimer
from __init__ import _
config.plugins.devicemanager = ConfigSubsection()
config.plugins.devicemanager.mountcheck_enable = ConfigEnableDisable(default=True)
def readFile(filename):
file = open(filename)
data = file.read().strip()
file.close()
return data
def byteConversion(byte):
if type(byte) == str and len(byte) == 0:
return ""
if type(byte) != long:
byte = long(byte)
if byte > 1024*1024*1024:
int_part = byte/1024/1024/1024
dec_part = byte%(1024*1024*1024)/(1024*1024)
return "%d.%d GB"%(int_part, dec_part)
else:
int_part = byte/1024/1024
dec_part = byte%(1024*1024)/1024
return "%d.%d MB"%(int_part, dec_part)
def checkStrValue(value , empty = ""):
if type(value) != str or len(value) == 0:
return empty
return value
class DeviceManagerConfiguration(Screen, ConfigListScreen):
def __init__(self,session):
self.session = session
Screen.__init__(self,session)
self.skinName = "Setup"
self.createConfigList()
ConfigListScreen.__init__(self, self.list, session = self.session)
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("OK"))
self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
{
"ok": self.keySave,
"cancel": self.keyCancel,
"red": self.keyCancel,
"green": self.keySave,
}, -2)
self.onShown.append(self.setWindowTitle)
def setWindowTitle(self):
self.setTitle(_("DeviceManager configuration"))
def createConfigList(self):
self.list = []
self.list.append(getConfigListEntry(_("Enable mount check for HDD : "), config.plugins.devicemanager.mountcheck_enable))
self.list.append(getConfigListEntry(_("Harddisk standby after : "), config.usage.hdd_standby))
class DeviceManager(Screen):
skin = """
{"templates":
{"default": (54,[
MultiContentEntryText(pos = (50, 0), size = (510, 30), font=0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 0), # index 0 is vendor - model
MultiContentEntryText(pos = (50, 32), size = (120, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 1), # index 1 is Device
MultiContentEntryText(pos = (170, 32), size = (120, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 2), # index 2 is Size
MultiContentEntryText(pos = (290, 32), size = (120, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 3), # index 3 is Partitions
MultiContentEntryText(pos = (410, 32), size = (130, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 4), # index 4 is Removable
MultiContentEntryPixmapAlphaTest(pos = (0, 52), size = (590, 2), png = 5), # png 5 is the div pixmap
]),
"partitions": (98, [
MultiContentEntryText(pos = (50, 0), size = (500, 30), font=0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 0), # index 1 is Partition
MultiContentEntryText(pos = (50, 32), size = (500, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 1), # index 2 is Mounted on
MultiContentEntryText(pos = (50, 54), size = (500, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 2), # index 3 UUID
MultiContentEntryText(pos = (50, 76), size = (130, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 3), # index 4 Type
MultiContentEntryText(pos = (180, 76), size = (130, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 4), # index 5 Size_total
MultiContentEntryText(pos = (310, 76), size = (190, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 5), # index 6 Size_free
MultiContentEntryPixmapAlphaTest(pos = (0, 96), size = (590, 2), png = 6), # png 6 is the div pixmap
]),
"mountpoint": (54,[
MultiContentEntryPixmapAlphaTest(pos = (10, 7), size = (30, 30), png = 0), # index 0: picture
MultiContentEntryText(pos = (40, 0), size = (500, 30), font=0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 1), # index 1 name
MultiContentEntryText(pos = (40, 32), size = (500, 20), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 2), # index 2 path
MultiContentEntryPixmapAlphaTest(pos = (0, 52), size = (590, 2), png = 5), # index 5 is the div pixmap
])
},
"fonts": [gFont("Regular", 22),gFont("Regular", 16),gFont("Regular", 28)],
"itemHeight": 54
}
"""
def __init__(self, session):
Screen.__init__(self, session)
self.session = session
self.currList = "default"
self.currDevice = None
self.currPartition = None
self.defaultMountPoint = "/media/hdd"
self.deviceList = []
self["menu"] = List(self.deviceList)
self["key_red"] = Label(_("Close"))
self["key_green"] = Label(" ")
self["key_yellow"] = Label(" ")
self["key_blue"] = Label(" ")
self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions", "MenuActions" ],
{
"ok": self.keyOk,
"cancel": self.keyCancel,
"red": self.keyCancel,
"green": self.keyOk,
"yellow": self.keyYellow,
"blue": self.keyBlue,
"menu": self.keyMenu,
}, -2)
self.DeviceManagerConsole = Console()
self.loadIcon()
if not self.selectionChanged in self["menu"].onSelectionChanged:
self["menu"].onSelectionChanged.append(self.selectionChanged)
self.onLayoutFinish.append(self.showDeviceList)
self.onLayoutFinish.append(self.addPartitionListChange)
self.onClose.append(self.removePartitionListChange)
self.onChangedEntry = []
self.blockDevices = {}
def addPartitionListChange(self):
harddiskmanager.on_partition_list_change.append(self.partitionListChanged)
def removePartitionListChange(self):
harddiskmanager.on_partition_list_change.remove(self.partitionListChanged)
def partitionListChanged(self, action, device):
print "[Device manager] hotplug partitionListChanged"
if self.currList != "default" and device.device[:3] != self.currDevice["blockdev"]:
return
self.showDeviceList()
def loadIcon(self):
self.icon_button_green = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/buttons/button_green.png"))
self.divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/div-h.png"))
def selectionChanged(self):
if self.currList == "partitions":
currentPartition = self.getCurrentPartition()
if currentPartition is not None:
if currentPartition["fstype"] == "":
self["key_blue"].setText("")
elif currentPartition["fstype"][:3] == "ext":
self["key_blue"].setText(_("Check"))
else:
self["key_blue"].setText("")
def showDeviceList(self):
self.deviceList = []
self["key_red"].setText(_("Close"))
self["key_green"].setText(_("Ok"))
self["key_yellow"].setText(" ")
self["key_blue"].setText(_("Initialize"))
deviceinfo.refresh()
for device in deviceinfo.getBlockDevices():
deviceEntry = (
"%s - %s"%(device["vendor"], device["model"]), # vendor : str, model : str, index 0
_("device : %s")%(device["blockdev"]), # str
_("Size : %s")%(byteConversion(device["size"])), # str, bytes
_("Partitions : %s")%(len(device["partitions"])), # list
_("Removable : %s")%(device["removable"] and 'Yes' or 'No'), # bool [True, False]
self.divpng, # png 5
device, # index 6
)
# print "[DeviceManager] deviceEntry : ", deviceEntry
self.deviceList.append(deviceEntry)
self.currList = "default"
self["menu"].style = "default"
self["menu"].setList(self.deviceList)
def showPartitionList(self):
if self.currDevice is None:
return
partitionList = []
for partition in self.currDevice["partitions"]:
partitionInfo = deviceinfo.getPartitionInfo(partition)
partitionEntry = (
_("Partition : /dev/%s")%partition, # index 0
_("Mounted on : %s")%checkStrValue(partitionInfo["mountpoint"], _("not mounted")),
_("UUID : %s")%checkStrValue(partitionInfo["uuid"], _("unknown")),
_("Type : %s")%checkStrValue(partitionInfo["fstype"], _("unknown")),
_("Size : %s")%checkStrValue(byteConversion(partitionInfo["size"]), _("unknown")),
_("Free : %s")%checkStrValue(byteConversion(partitionInfo["free"]), _("unknown")),
self.divpng, # index 6
partitionInfo, # index 7
)
# print "[DeviceManager] partitionEntry : ",partitionEntry
partitionList.append(partitionEntry)
if len(partitionList) != 0:
self["key_red"].setText(_("Devices"))
self["key_green"].setText(_(" "))
self["key_yellow"].setText(_("Format"))
self["key_blue"].setText(_("Check"))
self.currList = "partitions"
self["menu"].style = "partitions"
self["menu"].setList(partitionList)
self.selectionChanged()
else:
self.session.open(MessageBox, _("No partition list found on device.\nPlease click BLUE key and do Initialize to use this device."), MessageBox.TYPE_ERROR, timeout = 10)
def getCurrentDevice(self):
try:
return self["menu"].getCurrent()[6]
except:
return None
def getCurrentPartition(self):
try:
return self["menu"].getCurrent()[7]
except:
return None
def keyOk(self):
# print "keyOk"
if self.currList == "default":
self.currDevice = self.getCurrentDevice()
if self.currDevice is not None:
if len(self.currDevice["partitions"]) == 0:
self.session.open(MessageBox, _("No partition list found on device.\nPlease click BLUE key and do Initialize to use this device."), MessageBox.TYPE_ERROR, timeout = 10)
else:
self.showPartitionList()
else:
self.session.open(MessageBox, _("Device not found."), MessageBox.TYPE_ERROR, timeout = 10)
elif self.currList == "partitions":
pass
else:
pass
def keyCancel(self):
# print "keyCancel"
if self.DeviceManagerConsole is not None:
if len(self.DeviceManagerConsole.appContainers):
for name in self.DeviceManagerConsole.appContainers.keys():
self.DeviceManagerConsole.kill(name)
if self.currList == "partitions":
self.currDevice = None
self.showDeviceList()
else: # currList = "default"
self.close()
def keyYellow(self):
if self.currList == "partitions":
self.choiceBoxFstype()
def keyBlue(self):
if self.currList == "default":
device = self.getCurrentDevice()
if device is not None:
self.session.openWithCallback(self.deviceInitCB, DeviceInit, device["blockdev"], device["size"])
else:
self.session.open(MessageBox, _("Device not found."), MessageBox.TYPE_ERROR, timeout = 10)
elif self.currList == "partitions":
partition = self.getCurrentPartition()
if partition is not None:
self.session.openWithCallback(self.deviceCheckCB, DeviceCheck, partition)
else:
self.session.open(MessageBox, _("Partition info is not found."), MessageBox.TYPE_ERROR, timeout = 10)
def keyMenu(self):
self.session.open(DeviceManagerConfiguration)
def deviceInitCB(self, ret = True):
self.showDeviceList()
def deviceCheckCB(self, ret = True):
self.showPartitionList()
def deviceFormatCB(self, ret = True):
self.showPartitionList()
def choiceBoxFstype(self):
menu = []
menu.append((_("ext2 - recommended for USB flash memory"), "ext2"))
menu.append((_("ext3 - recommended for harddisks"), "ext3"))
menu.append((_("ext4 - experimental"), "ext4"))
menu.append((_("vfat - for USB flash memory"), "vfat"))
self.session.openWithCallback(self.choiceBoxFstypeCB, ChoiceBox, title=_("Choice filesystem."), list=menu)
def choiceBoxFstypeCB(self, choice):
if choice is None:
return
else:
partition = self.getCurrentPartition()
if partition is not None:
self.session.openWithCallback(self.deviceFormatCB, DeviceFormat, partition, choice[1])
else:
self.session.open(MessageBox, _("Partition info is not found."), MessageBox.TYPE_ERROR, timeout = 10)
# Initializing Start...
class DeviceInit(Screen):
skin = """"""
def __init__(self, session, device, devicesize):
Screen.__init__(self, session)
self.session = session
self.deviceInitConsole = Console()
self.device = device
self.devicesize = int(devicesize)
self.inputbox_partitions = 1
self.inputbox_partitionSizeList = []
self.inputbox_partitionSizeTotal = int(self.devicesize/1024/1024)
self.msgWaiting = None
self.msgWaitingMkfs = None
self.devicenumber = 0
self.newpartitions = 0
self.onLayoutFinish.append(self.timerStart)
self.initStartTimer = eTimer()
self.initStartTimer.callback.append(self.confirmMessage)
self.createFSStartTimer = eTimer()
self.createFSStartTimer.callback.append(self.createFilesystemStart)
self.exitMessageTimer = eTimer()
self.exitMessageTimer.callback.append(self.exitMessage)
self.msg = ""
self.fstype = None
self.mkfs_cmd = ""
self.doMkfsTimer = eTimer()
self.doMkfsTimer.callback.append(self.doMkfs)
self.doInitializeTimer = eTimer()
self.doInitializeTimer.callback.append(self.doInitialize)
self.partitionType = "MBR"
self.maxPartNum = 4
self.inputbox_partitionSizeRemain = self.inputbox_partitionSizeTotal
self.unit = "MB"
self.onClose.append(enableUdevEvent)
def timerStart(self):
enableUdevEvent(False)
self.initStartTimer.start(100,True)
def confirmMessage(self):
message = _("Do you really want to initialize the device?\nAll data on the device will be lost!")
self.session.openWithCallback(self.confirmed, MessageBox, message)
def confirmed(self, ret):
if ret:
self.InitializeStart()
else:
self.exit()
def exit(self, ret = True):
self.close()
def unmountAll(self, device):
mounts = file('/proc/mounts').read().split('\n')
cmd = ""
# umount all
for line in mounts:
if not line.startswith("/dev/" + device):
continue
cmd += "umount %s ;"% line.split()[0]
print "[DeviceManager] %s"%cmd
os.system(cmd)
#recheck if umounted
mounts = file('/proc/mounts').read().split('\n')
for line in mounts:
if line.startswith("/dev/" + device):
return False
return True
def InitializeStart(self):
if self.devicesize >= ( 2.2 * 1000 * 1000 * 1000 * 1000 ): # 2.2TB
self.partitionType = "GPT"
self.maxPartNum = 20
self.inputbox_partitionSizeRemain = 100
self.unit = "%"
self.InputPartitionSize_step1()
def InputPartitionSize_step1(self):
self.session.openWithCallback(self.InputPartitionSize_step1_CB, InputBox, title=_("How many partitions do you want?(1-%d)" % self.maxPartNum), text="1", maxSize=False, type=Input.NUMBER)
def InputPartitionSize_step1_CB(self, ret):
if ret is not None and int(ret) in range(1,self.maxPartNum+1): # MBR 1~4, GPT 1~20
self.inputbox_partitions = int(ret)
self.InputPartitionSize_step2()
else:
self.session.openWithCallback(self.exit, MessageBox, _("The number you entered is wrong!"), MessageBox.TYPE_ERROR, timeout = 10)
def InputPartitionSize_step2(self):
current_partition = len(self.inputbox_partitionSizeList)+1
if self.inputbox_partitionSizeRemain == 0:
self.choiceBoxFstype()
elif current_partition == self.inputbox_partitions:
self.inputbox_partitionSizeList.append(str(self.inputbox_partitionSizeRemain))
self.choiceBoxFstype()
else:
text = str(int(self.inputbox_partitionSizeRemain/(self.inputbox_partitions-len(self.inputbox_partitionSizeList) )))
self.session.openWithCallback(self.InputPartitionSize_step2_CB, InputBox, title=_("Input size of partition %s.(Unit = %s, Max = %d %s)")%(current_partition, self.unit, self.inputbox_partitionSizeRemain, self.unit), text=text, maxSize=False, type=Input.NUMBER)
def InputPartitionSize_step2_CB(self, ret):
if ret is not None:
if self.inputbox_partitionSizeRemain < int(ret) or int(ret) == 0:
self.InputPartitionSize_step2()
else:
self.inputbox_partitionSizeList.append(str(ret))
self.inputbox_partitionSizeRemain -= int(ret)
self.InputPartitionSize_step2()
else:
self.session.openWithCallback(self.exit ,MessageBox, _("The number you entered is wrong!"), MessageBox.TYPE_ERROR, timeout = 10)
def choiceBoxFstype(self):
menu = []
menu.append((_("ext2 - recommended for USB flash memory"), "ext2"))
menu.append((_("ext3 - recommended for harddisks"), "ext3"))
menu.append((_("ext4 - experimental"), "ext4"))
menu.append((_("vfat - for USB flash memory"), "vfat"))
self.session.openWithCallback(self.choiceBoxFstypeCB, ChoiceBox, title=_("Choice filesystem."), list=menu)
def choiceBoxFstypeCB(self, choice):
if choice is None:
self.exit()
else:
self.fstype = choice[1]
if self.fstype not in ["ext2", "ext3", "ext4", "vfat"]:
self.exit()
else:
self.initInitializeConfirm()
def initInitializeConfirm(self):
# print self.inputbox_partitionSizeList
partitionsInfo = ""
for index in range(len(self.inputbox_partitionSizeList)):
print "partition %d : %s %s"%(index+1, str(self.inputbox_partitionSizeList[index]), self.unit)
partitionsInfo += "partition %d : %s %s\n"%(index+1, str(self.inputbox_partitionSizeList[index]), self.unit)
partitionsInfo += "filesystem type : %s"%(self.fstype)
self.session.openWithCallback(self.initInitializeConfirmCB, MessageBoxConfirm, _("%s\nStart Device Inititlization?") % partitionsInfo , MessageBox.TYPE_YESNO)
def initInitializeConfirmCB(self,ret):
if ret:
self.initInitialize()
else:
self.exit()
def initInitialize(self):
if not self.unmountAll(self.device):
self.session.openWithCallback(self.exit, MessageBox, _("umounting failed!Maybe some files in mount point are open"), MessageBox.TYPE_ERROR, timeout = 10)
else:
msg = _("InitInitializing, please wait ...")
msg += _("\nDevice : %s")%self.device
msg += _("\nSize : %s MB\n")%self.inputbox_partitionSizeTotal
for index in range(len(self.inputbox_partitionSizeList)):
msg += _("\npartition %d : %s %s")%(index+1, str(self.inputbox_partitionSizeList[index]), self.unit)
self.msgWaiting = self.session.openWithCallback(self.msgWaitingCB, MessageBox_2, msg, type = MessageBox.TYPE_INFO, enable_input = False)
self.doInitializeTimer.start(500,True)
def doInitialize(self):
def CheckPartedVer():
cmd = 'parted --version'
lines = os.popen(cmd).readlines()
for l in lines:
if l.find("parted (GNU parted)") != -1:
ver = l.split()[3].strip()
break
try:
ver = float(ver)
except:
print "[DeviceManager] check parted version Failed!"
return 0
return ver
partitions = len(self.inputbox_partitionSizeList) # get num of partition
set = ""
setAlign = ""
partedVer = CheckPartedVer()
if partedVer >= 2.1: # align option is supported in version 2.1 or later
setAlign = "--align optimal"
if self.devicesize < 1024 * 1000 * 1000: # 1GB
setAlign = "-a min"
else:
setAlign = "-a opt"
if self.partitionType == "GPT": # partition type is GPT
parttype = 'gpt'
else:
parttype = 'msdos'
if partitions == 1:
cmd = 'parted %s /dev/%s --script mklabel %s mkpart primary 0%% 100%%' % (setAlign, self.device, parttype)
else: # has multiple partitions
p_current = 0
for p in range(partitions):
if p == 0:
p_start = p_current
p_end = int( (long(self.inputbox_partitionSizeList[p]) * 100) / self.inputbox_partitionSizeTotal )
p_current = p_end
elif p > 0 and partitions > (p + 1):
p_start = p_current
p_end = int( (long(self.inputbox_partitionSizeList[p]) * 100) / self.inputbox_partitionSizeTotal )+ p_start
p_current = p_end
elif partitions == (p + 1):
p_start = p_current
p_end = 100
if p_start == p_end:
p_end +=1
if p_end > 100:
continue
set += 'mkpart primary ext2 %d%% %d%% ' % (p_start, p_end)
cmd = 'parted %s /dev/%s --script mklabel %s %s' % (setAlign, self.device, parttype, set)
self.deviceInitConsole.ePopen(cmd, self.initInitializeFinished)
def initInitializeFinished(self, result, retval, extra_args = None):
if retval == 0:
if self.partitionType == "MBR":
sfdiskVer = CheckSfdiskVer()
if sfdiskVer < 2.26: # sfdisk -R option is deprecated at sfdiskVer >= 2.26
cmd = 'sfdisk -R /dev/%s; sleep 5' % (self.device)
elif path.exists('/usr/sbin/partprobe'):
cmd = 'partprobe /dev/%s; sleep 5' % (self.device)
elif path.exists('/usr/sbin/partx'):
cmd = 'partx -u /dev/%s; sleep 5' % (self.device)
else:
cmd = 'sfdisk -R /dev/%s; sleep 5' % (self.device)
else: # is GPT
cmd = "sleep 5"
self.deviceInitConsole.ePopen(cmd, self.initInitializingRefreshFinished)
else:
errorMsg = "initInitializing device Error at /dev/%s"%self.device
self.msgWaiting.run_close(False, errorMsg)
def initInitializingRefreshFinished(self, result, retval, extra_args = None):
cmd = "/bin/umount /dev/%s*" % (self.device)
self.deviceInitConsole.ePopen(cmd, self.initInitializingUmountFinished)
def initInitializingUmountFinished(self, result, retval, extra_args = None):
partitions = open("/proc/partitions")
self.devicenumber = 0
self.newpartitions = 0
for part in partitions:
res = re.sub("\s+", " ", part).strip().split(" ")
if res and len(res) == 4 and res[3][:3] == self.device:
if len(res[3]) > 3 and res[3][:2] == "sd":
self.newpartitions += 1
partitions.close()
partNum = len(self.inputbox_partitionSizeList) # get num of partition
if self.newpartitions != partNum:
errorMsg = "Partitioning device Error at /dev/%s"%self.device
self.msgWaiting.run_close(False, errorMsg)
else:
self.msgWaiting.run_close(True)
# self.createFilesystem(self.newpartitions)
def createFilesystem(self, newpartitions):
self.devicenumber = self.devicenumber + 1
fulldevicename = "/dev/" + self.device + str(self.devicenumber)
shortdevicename = self.device + str(self.devicenumber)
# get partition size
partitions = open("/proc/partitions")
for part in partitions:
res = re.sub("\s+", " ", part).strip().split(" ")
if res and len(res) == 4:
if res[3] == shortdevicename:
partitionsize = int(res[2])
break
partitions.close()
if self.fstype == "ext4":
cmd = "mkfs.ext4 -F "
if partitionsize > 2 * 1024 * 1024: # 2GB
cmd += "-T largefile "
cmd += "-O extent,flex_bg,large_file,uninit_bg -m1 " + fulldevicename
elif self.fstype == "ext3":
cmd = "mkfs.ext3 -F "
if partitionsize > 2 * 1024 * 1024:
cmd += "-T largefile "
cmd += "-m0 " + fulldevicename
elif self.fstype == "ext2":
cmd = "mkfs.ext2 -F "
if partitionsize > 2 * 1024 * 1024:
cmd += "-T largefile "
cmd += "-m0 " + fulldevicename
elif self.fstype == "vfat":
if partitionsize > 4 * 1024 * 1024 * 1024:
cmd = "mkfs.vfat -I -S4096 " + fulldevicename
else:
cmd = "mkfs.vfat -I " + fulldevicename
if partitionsize > 2 * 1024 * 1024: # if partiton size larger then 2GB, use FAT32
cmd += " -F 32"
else:
self.createFilesystemFinished(None, -1, (self.device, fulldevicename))
return
msg = _("Create filesystem, please wait ...")
msg += _("\nPartition : %s") % (fulldevicename)
msg += _("\nFilesystem : %s") % (self.fstype)
msg += _("\nDisk Size : %s MB") % (self.inputbox_partitionSizeTotal)
msg += _("\nPartition Size : %d %s\n") % (int(self.inputbox_partitionSizeList[self.devicenumber-1]), self.unit)
self.msgWaitingMkfs = self.session.openWithCallback(self.msgWaitingMkfsCB, MessageBox_2, msg, type = MessageBox.TYPE_INFO, enable_input = False)
self.mkfs_cmd = cmd
self.doMkfsTimer.start(500,True)
def doMkfs(self):
fulldevicename = "/dev/" + self.device + str(self.devicenumber)
self.deviceInitConsole.ePopen(self.mkfs_cmd, self.createFilesystemFinished, (self.device, fulldevicename))
def createFilesystemFinished(self, result, retval, extra_args = None):
device = extra_args[0]
fulldevicename = extra_args[1]
if retval == 0:
self.msgWaitingMkfs.run_close(True)
else:
errorMsg = _("Creating filesystem Error")
if fulldevicename is not None:
errorMsg += _(" at /dev/%s")%fulldevicename
self.msgWaitingMkfs.run_close(False, errorMsg)
def createFilesystemStart(self):
self.createFilesystem(self.newpartitions)
def msgWaitingCB(self, ret, msg=""):
if ret:
self.createFSStartTimer.start(100,True)
else:
self.success = False
self.msg = msg
self.exitMessageTimer.start(100,True)
def msgWaitingMkfsCB(self, ret, msg=""):
if self.devicenumber < self.newpartitions:
self.createFSStartTimer.start(100,True)
else:
if ret == True:
self.success = True
self.msg = _("Device Initialization finished sucessfully!")
self.exitMessageTimer.start(100,True)
else:
self.success = False
self.msg = msg
self.exitMessageTimer.start(100,True)
def exitMessage(self):
if self.success:
self.session.openWithCallback(self.exit, MessageBox, self.msg, MessageBox.TYPE_INFO, timeout = 10)
else:
self.session.openWithCallback(self.exit, MessageBox, self.msg, MessageBox.TYPE_ERROR, timeout = 10)
# Initializing end
# device check start..
class DeviceCheck(Screen):
skin = """"""
def __init__(self, session, partition):
Screen.__init__(self, session)
self.session = session
self.deviceCheckConsole = Console()
self.partition = partition
self.onLayoutFinish.append(self.timerStart)
self.checkStartTimer = eTimer()
self.checkStartTimer.callback.append(self.confirmMessage)
self.umountTimer = eTimer()
self.umountTimer.callback.append(self.doUnmount)
def timerStart(self):
self.checkStartTimer.start(100,True)
def confirmMessage(self):
fssize = self.partition["size"]
if long(fssize) > 1024*1024*1024*16:
message = _("Do you really want to check the filesystem?\nThis could take lots of time!")
self.session.openWithCallback(self.confirmed, MessageBox, message)
else:
self.deviceCheckStart()
def confirmed(self, ret):
print "confirmed : ",ret
if ret:
self.deviceCheckStart()
else:
self.exit()
def deviceCheckStart(self):
print "deviceCheckStart "
print "partition : ", self.partition
device = self.partition["partition"]
fstype = self.partition["fstype"]
fssize = self.partition["size"]
if device is not None and fstype.startswith("ext"):
msg = _("Check filesystem, please wait ...")
msg += _("\nDevice : /dev/%s")%(device)
msg += _("\nFilesystem : %s")%(fstype)
self.msgWaiting = self.session.openWithCallback(self.msgWaitingCB, MessageBox_2, msg, type = MessageBox.TYPE_INFO, enable_input = False)
self.umountTimer.start(500,True)
else:
self.exit()
def doUnmount(self):
device = self.partition["partition"]
mountpoint = self.partition["mountpoint"]
fstype = self.partition["fstype"]
if mountpoint != "":
self.doUmountFsck(device, mountpoint, fstype)
else:
self.umountFsckFinished("NORESULT", 0, (device, mountpoint, fstype))
def doUmountFsck(self, device, mountpoint, fstype):
cmd = "umount /dev/%s" % device
self.deviceCheckConsole.ePopen(cmd, self.umountFsckFinished, (device, mountpoint, fstype))
def umountFsckFinished(self, result, retval, extra_args = None):
device = extra_args[0]
mountpoint = extra_args[1]
fstype = extra_args[2]
if retval == 0:
cmd = "fsck." + fstype + " -f -p /dev/" + device
self.deviceCheckConsole.ePopen(cmd, self.fsckFinished, extra_args)
else:
errorMsg = _("Can not umount device /dev/%s.\nMaybe some files of the filesystem are open")%device
self.msgWaiting.run_close(False,errorMsg)
def fsckFinished(self, result, retval, extra_args = None):
device = extra_args[0]
mountpoint = extra_args[1]
if retval == 0:
text = _("Filesystem check finished sucessfully")
self.msgWaiting.run_close(True, text)
else:
text = _("Error checking disk. The disk or filesystem may be damaged")
self.msgWaiting.run_close(False, text)
def msgWaitingCB(self, ret, msg):
if ret:
self.session.open(MessageBox, msg, MessageBox.TYPE_INFO, timeout = 10)
else:
self.session.open(MessageBox, msg, MessageBox.TYPE_ERROR, timeout = 10)
partition = self.partition["partition"]
mountpoint = self.partition["mountpoint"]
fstype = self.partition["fstype"]
if mountpoint != "":
if fstype == "ntfs":
cmd = "ntfs-3g /dev/" + partition + " " + mountpoint
else:
cmd = "mount /dev/" + partition + " " + mountpoint
self.deviceCheckConsole.ePopen(cmd, self.mountPartitionFinished)
else:
self.exit()
def mountPartitionFinished(self, result, retval, extra_args = None):
self.exit()
def exit(self):
self.close()
#device check end
#device format start
class DeviceFormat(Screen):
skin = """"""
def __init__(self, session, partition, newfstype):
Screen.__init__(self, session)
self.session = session
self.deviceFormatConsole = Console()
self.partition = partition
self.newfstype = newfstype
self.unmountedList = []
self.onLayoutFinish.append(self.timerStart)
self.formatStartTimer = eTimer()
self.formatStartTimer.callback.append(self.DeviceFormatStart)
self.umountTimer = eTimer()
self.umountTimer.callback.append(self.doUnmount)
self.onClose.append(enableUdevEvent)
def timerStart(self):
enableUdevEvent(False)
self.formatStartTimer.start(100,True)
def DeviceFormatStart(self):
print "DeviceFormatStart : ", self.partition,
print "Filesystem : ",self.newfstype
device = self.partition["partition"]
devicepath = "/dev/"+device
fssize = self.partition["size"]
newfstype = self.newfstype
msg = _("Format filesystem, please wait ...")
msg += _("\nDevice : %s")%(devicepath)
msg += _("\nFilesystem : %s")%(newfstype)
msg += _("\nSize : %s")%(byteConversion(fssize))
self.msgWaiting = self.session.openWithCallback(self.msgWaitingCB, MessageBox_2, msg, type = MessageBox_2.TYPE_INFO, enable_input = False, msgBoxID = None)
self.umountTimer.start(500,True)
def doUnmount(self):
mountpoint = self.partition["mountpoint"]
if mountpoint != "":
self.doumountPartition()
else:
self.umountPartitionFinished("NORESULT", 0)
def doumountPartition(self):
oldfstype = self.partition["fstype"]
newfstype = self.newfstype
if newfstype == oldfstype:
device = self.partition["partition"]
else:
device = self.partition["partition"][:3]
cmd = ""
mounts = file('/proc/mounts','r')
for line in mounts.readlines():
if line.startswith("/dev/%s"%device):
cmd += "umount %s;"%line.split()[0]
self.unmountedList.append([line.split()[0], line.split()[1]])
self.deviceFormatConsole.ePopen(cmd, self.umountPartitionFinished)
def umountPartitionFinished(self, result, retval, extra_args = None):
partition = self.partition["partition"]
oldfstype = self.partition["fstype"]
newfstype = self.newfstype
if retval == 0:
if oldfstype == newfstype:
self.changePartitionIDFinished("NORESULT", 0)
else:
sfdiskVer = CheckSfdiskVer()
if sfdiskVer >= 2.26:
cmd = "sfdisk --part-type /dev/%s %s" % (partition[:3], partition[3:])
else:
cmd = "sfdisk --change-id /dev/%s %s" % (partition[:3], partition[3:])
if newfstype[:3] == "ext":
cmd += " 83"
else:
cmd += " c"
self.deviceFormatConsole.ePopen(cmd, self.changePartitionIDFinished)
else:
errorMsg = _("Can not umount device /dev/%s.\nMaybe some files of the filesystem are open")%partition[:3]
self.msgWaiting.run_close(False,errorMsg)
def changePartitionIDFinished(self, result, retval, extra_args = None):
device = self.partition["partition"][:3]
mountpoint = self.partition["mountpoint"]
oldfstype = self.partition["fstype"]
newfstype = self.newfstype
if retval == 0:
if oldfstype == newfstype:
self.refreshPartitionFinished("NORESULT", 0)
else:
sfdiskVer = CheckSfdiskVer()
if sfdiskVer < 2.26: # sfdisk -R option is deprecated at sfdiskVer >= 2.26
cmd = "sfdisk -R /dev/%s; sleep 5" % (device)
elif path.exists('/usr/sbin/partprobe'):
cmd = 'partprobe /dev/%s; sleep 5' % (device)
elif path.exists('/usr/sbin/partx'):
cmd = 'partx -u /dev/%s; sleep 5' % (device)
else:
cmd = "sfdisk -R /dev/%s; sleep 5" % (device)
self.deviceFormatConsole.ePopen(cmd, self.refreshPartitionFinished)
else:
if result and result.find("Use GNU Parted") > 0:
print "[DeviceManager] /dev/%s use GNU Parted!" % device
self.refreshPartitionFinished("NORESULT", 0)
else:
errorMsg = _("Can not change the partition ID for %s")%device
self.msgWaiting.run_close(False,errorMsg)
def refreshPartitionFinished(self, result, retval, extra_args = None):
print "refreshPartitionFinished!"
partition = self.partition["partition"]
mountpoint = self.partition["mountpoint"]
size = int(self.partition["size"])/1024/1024
oldfstype = self.partition["fstype"]
newfstype = self.newfstype
if retval == 0:
if newfstype == "ext4":
cmd = "mkfs.ext4 -F "
if size > 2 * 1024:
cmd += "-T largefile "
cmd += "-O extent,flex_bg,large_file,uninit_bg -m1 /dev/" + partition
elif newfstype == "ext3":
cmd = "mkfs.ext3 -F "
if size > 2 * 1024:
cmd += "-T largefile "
cmd += "-m0 /dev/" + partition
elif newfstype == "ext2":
cmd = "mkfs.ext2 -F "
if size > 2 * 1024:
cmd += "-T largefile "
cmd += "-m0 /dev/" + partition
elif newfstype == "vfat":
if size > 4 * 1024 * 1024:
cmd = "mkfs.vfat -I -S4096 /dev/" + partition
else:
cmd = "mkfs.vfat -I /dev/" + partition
if size > 2 * 1024: # if partiton size larger then 2GB, use FAT32
cmd += " -F 32"
self.deviceFormatConsole.ePopen(cmd, self.mkfsFinished)
else:
errorMsg = _("Can not format device /dev/%s.\nrefresh partition information failed!")%partition
self.msgWaiting.run_close(False,errorMsg)
def mkfsFinished(self, result, retval, extra_args = None):
print "mkfsFinished!"
partition = self.partition["partition"]
if retval == 0:
cmd = ""
if len(self.unmountedList) == 0:
self.doMountFinished("NORESULT",0)
for x in self.unmountedList:
cmd += "mount %s %s;"%(x[0], x[1])
self.deviceFormatConsole.ePopen(cmd, self.doMountFinished)
else:
text = _("Make filesystem Error /dev/%s.\nPlease check your device.")%partition
self.msgWaiting.run_close(False, text)
def doMountFinished(self, result, retval, extra_args = None):
print "doMountFinished!"
text = _("Format finished sucessfully.")
self.msgWaiting.run_close(True, text)
def msgWaitingCB(self, ret, msg):
if ret:
self.session.openWithCallback(self.exit, MessageBox, msg, MessageBox.TYPE_INFO, timeout = 10)
else:
self.session.openWithCallback(self.exit, MessageBox, msg, MessageBox.TYPE_ERROR, timeout = 10)
def exit(self, ret):
self.close()
#device format end
class DeviceInfo():
def __init__(self):
self.blockDeviceList = []
def getBlockDevices(self):
return self.blockDeviceList
def refresh(self):
self.blockDeviceList = []
self.getBlockDeviceList()
def getBlockDeviceList(self):
print "get block device Infomations..."
for blockdev in listdir("/sys/block"):
(error, blacklisted, removable, partitions, size, model, vendor) = self.getBlockDeviceInfo(blockdev)
if not blacklisted and not error:
# print "%s : error %s, blacklisted %s, removable %s, partitions %s, size %s"%(blockdev, error, blacklisted, removable, partitions, size)
blockDevice = {}
blockDevice["blockdev"] = blockdev # str
blockDevice["removable"] = removable # bool [True, False]
blockDevice["partitions"] = partitions # list
blockDevice["size"] = size # str
blockDevice["model"] = model # str
blockDevice["vendor"] = vendor # str
self.blockDeviceList.append(blockDevice)
def SortPartList(self, partList):
length = len(partList)-1
sorted = False
while sorted is False:
sorted = True
for idx in range(length):
if int(partList[idx][3:]) > int(partList[idx+1][3:]):
sorted = False
partList[idx] , partList[idx+1] = partList[idx+1], partList[idx]
def getBlockDeviceInfo(self, blockdev):
devpath = "/sys/block/" + blockdev
error = False
removable = False
blacklisted = False
partitions = []
size =""
model = ""
vendor = ""
try:
dev = int(readFile(devpath + "/dev").split(':')[0])
if dev in (7, 31) or blockdev[0:2] != 'sd': # 7: loop, 31 : mtdblock
blacklisted = True
return error, blacklisted, removable, partitions, size, model, vendor
removable = bool(int(readFile(devpath + "/removable")))
size = str(int(readFile(devpath + "/size").strip())*512)
model = readFile(devpath + "/device/model")
vendor = readFile(devpath + "/device/vendor")
for partition in listdir(devpath):
if partition[:len(blockdev)] != blockdev:
continue
partitions.append(partition)
self.SortPartList(partitions)
except IOError:
error = True
return error, blacklisted, removable, partitions, size, model, vendor
def getPartitionInfo(self, partition):
mountPoint = self.getPartitionMountpoint(partition)
(uuid , fsType) = self.getPartitionBlkidInfo(partition)
size_total = self.getPartitionSize(partition)
size_free = ""
if mountPoint != "":
size_free = self.getPartitionFree(mountPoint)
partitionInfo = {}
partitionInfo["partition"] = partition
partitionInfo["mountpoint"] = mountPoint
partitionInfo["uuid"] = uuid
partitionInfo["fstype"] = fsType
partitionInfo["size"] = size_total
partitionInfo["free"] = size_free
return partitionInfo
def getPartitionMountpoint(self, partition):
mounts = file('/proc/mounts').read().split('\n')
for x in mounts:
if not x.startswith('/'):
continue
devpath, mountpoint, = x.split()[:2]
if mountpoint.startswith('/autofs'):
continue
if path.basename(devpath) == partition:
return mountpoint
return ""
def getPartitionBlkidInfo(self, partition):
parttionDev = "/dev/"+str(partition)
uuid = ""
partitionType = ""
cmd = "blkid -c /dev/null "+str(parttionDev)
try:
line = popen(cmd).readline().strip()
if not line.startswith(parttionDev):
return (uuid, partitionType)
# print "Blikd %s : %s"%(parttionDev, line)
if line.find(" UUID=") != -1:
uuid = line.split(" UUID=")[1].split(' ')[0]
if line.find(" TYPE=") != -1:
partitionType = line.split(" TYPE=")[1].split(' ')[0].strip('"')
except:
print "get blkid info error (%s)"%cmd
return (uuid, partitionType)
def getPartitionSize(self, partition):
devpath = "/sys/block/%s/%s"%( str(partition[:3]), str(partition) )
try:
size = readFile(devpath + "/size")
return str(int(size)*512)
except:
return ""
def getPartitionFree(self, mountPoint):
try:
stat = statvfs(mountPoint)
size_free = stat.f_bfree*stat.f_bsize
return size_free
except:
return ""
def checkMountPoint(self, check_mountpoint):
res = []
try:
mounts = file('/proc/mounts').read().split('\n')
for x in mounts:
if not x.startswith('/'):
continue
devpath, mountpoint = x.split()[:2]
if mountpoint == check_mountpoint:
res.append(devpath)
except:
pass
return res
def checkMountDev(self, device):
res = []
try:
mounts = file('/proc/mounts').read().split('\n')
for x in mounts:
if not x.startswith('/'):
continue
devpath, mountpoint = x.split()[:2]
if devpath == device:
res.append(mountpoint)
except:
pass
return res
def isMounted(self, devpath, mountpoint):
try:
mounts = file('/proc/mounts').readlines()
for x in mounts:
if not x.startswith('/'):
continue
_devpath, _mountpoint = x.split()[:2]
if devpath == _devpath and mountpoint == _mountpoint:
return True
except:
pass
return False
def isMounted_anymp(self, devpath):
try:
mounts = open('/proc/mounts', 'r').readlines()
for x in mounts:
if not x.startswith('/'):
continue
_devPart, _mountpoint = x.split()[:2]
if devpath == _devPart:
return True
except:
pass
return False
# check partition type is extended or swap.
def checkSwapExtended(self, partition):
blockName = partition[:-1]
partNum = partition[-1]
data = os.popen("parted /dev/%s print" % blockName).readlines()
for x in data:
info = x.strip().split()
if len(info) > 0 and info[0] == str(partNum):
if len(info) >= 5 and info[4].find('extended') != -1: # check Type is extended
return True
elif len(info) >= 6 and info[5].find('swap') != -1: # check File System is swap
return True
return False
def isMountable(self, partition):
if self.checkSwapExtended(partition):
return False
try:
if self.isMounted_anymp('/dev/'+partition):
return True
elif os.access('/autofs/'+partition, 0):
return True
except:
pass
return False
def isFstabAutoMounted(self, uuid, devpath, mountpoint):
# print " >> isFstabMounted, uuid : %s, devpath : %s, mountpoint : %s"%(uuid, devpath, mountpoint)
if mountpoint[-1] == '/':
mountpoint = mountpoint[:-1]
data = file('/etc/fstab').read().split('\n')
for line in data:
if not line.startswith('/'):
continue
dev, mp, ms = line.split()[0:3]
if uuid is not None and dev.startswith('UUID'):
if dev.split('=')[1] == uuid.strip("\"") and mp == mountpoint and ms == 'auto':
# print " >> line : ", line
return True
elif dev == devpath and mp == mountpoint and ms == 'auto':
# print " >> line : ", line
return True
return False
def umountByMountpoint(self, mountpoint):
if mountpoint is None:
return False
try:
if path.ismount(mountpoint):
cmd = "umount " + mountpoint
print "[DeviceManager] ", cmd
os.system(cmd)
except:
print "Umount by mountpoint failed!"
if not path.ismount(mountpoint):
return True
return False
def umountByDevpath(self, devpath):
cmd = "umount " + devpath
print "[DeviceManager] ", cmd
os.system(cmd)
deviceinfo = DeviceInfo()
class MountpointBrowser(Screen):
skin="""
"""
def __init__(self, session):
Screen.__init__(self, session)
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("Select"))
self["key_yellow"] = StaticText(_("Create directory"))
self["key_blue"] = StaticText("Delete directory")
directory = "/media/"
inhibitDirs = ["/autofs", "/mnt", "/hdd", "/bin", "/boot", "/dev", "/etc", "/home", "/lib", "/proc", "/sbin", "/share", "/sys", "/tmp", "/usr", "/var"]
self.filelist = FileList(directory, matchingPattern="", inhibitDirs = inhibitDirs)
self["filelist"] = self.filelist
self["shortcuts"] = ActionMap(["ColorActions"],
{
"red": self.exit,
"green": self.select,
"yellow": self.createDirectory,
"blue": self.deleteDirectory,
}, -2)
self["OkCancelActions"] = ActionMap(["OkCancelActions"],
{
"cancel": self.exit,
"ok": self.ok,
}, -2)
def ok(self):
if self.filelist.canDescent():
self.filelist.descent()
def select(self):
if self["filelist"].getCurrentDirectory() is not None:
if self.filelist.canDescent() and self["filelist"].getFilename() and self["filelist"].getFilename().startswith(self["filelist"].getCurrentDirectory()):
self.filelist.descent()
currDir = self["filelist"].getCurrentDirectory()
self.close(currDir)
else:
self.close(self["filelist"].getFilename())
def createDirectory(self):
self.session.openWithCallback(self.createDirectoryCB, VirtualKeyBoard, title = (_("Input mount point path.")), text = "")
def createDirectoryCB(self, retval = None):
newdir=None
try:
if retval is not None:
newdir = self["filelist"].getCurrentDirectory()+'/'+retval
if not path.exists(newdir):
os.system("mkdir %s"%newdir)
self.filelist.refresh()
except:
if newdir:
self.session.open(MessageBox, _("Create directory failed!\n%s")%newdir, MessageBox.TYPE_ERROR, timeout = 10)
def deleteDirectory(self):
delDir=None
try:
if self["filelist"].getCurrentDirectory() is not None:
if self.filelist.canDescent() and self["filelist"].getFilename() and self["filelist"].getFilename().startswith(self["filelist"].getCurrentDirectory()):
delDir = self["filelist"].getFilename()
if path.exists(delDir):
os.system("rmdir '%s'"%delDir)
if path.exists(delDir):
self.session.open(MessageBox, _("Delete directory failed!\nMaybe directory is not empty."), MessageBox.TYPE_ERROR, timeout = 10)
self.filelist.refresh()
except:
if delDir:
self.session.open(MessageBox, _("Delete directory failed!\n%s")%newdir, MessageBox.TYPE_ERROR, timeout = 10)
def exit(self):
self.close(False)
class MessageBoxConfirm(MessageBox):
skin = """
"""
dmconfigfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/DeviceManager/devicemanager.cfg")
def callBackforDeviceManager(session, callback_result = False):
if callback_result == True:
session.open(DeviceManager)
def checkMounts(session):
try:
noMountable_dev = ""
for blockdev in listdir("/sys/block"):
devpath = "/sys/block/" + blockdev
dev = int(readFile(devpath + "/dev").split(':')[0])
if dev in (7, 31) or blockdev[0:2] != 'sd': # 7: loop, 31 : mtdblock
continue
partitions = []
noMountable_partitions = []
for partition in listdir(devpath):
if not partition.startswith(blockdev):
continue
if deviceinfo.checkSwapExtended(partition):
continue
partitions.append(partition)
if deviceinfo.isMounted_anymp('/dev/' + partition):
continue
if os.access('/autofs/'+partition, 0) is False:
noMountable_partitions.append(partition)
if len(partitions) == 0 or len(noMountable_partitions) != 0:
if noMountable_dev != "":
noMountable_dev += ' '
noMountable_dev += blockdev
if noMountable_dev != "":
print "Umountable partitions found."
InfoText = _("No mountable devices found.! (%s)\nDo you want to open DeviceManager and do initialize or format this device?\n\n(Open 'Menu->Setup->System -> Harddisk -> DeviceManager'\n and press MENU button to deactivate this check.)")%noMountable_dev
AddNotificationWithCallback(
boundFunction(callBackforDeviceManager, session),
MessageBox, InfoText, timeout = 60, default = False
)
except:
print "checkMounts failed!"
def sessionstart(reason, **kwargs):
if reason == 0:
if kwargs.has_key("session") and config.plugins.devicemanager.mountcheck_enable.value == True:
session = kwargs["session"]
checkMounts(session)
elif reason == 1:
pass
def autostart(reason, **kwargs):
if reason == 0:
try:
# at first enigma2 start
if config.misc.firstrun.value:
print "[DeviceManager] autostart : check devices at first start"
if not path.exists("/media/hdd"):
cmd = "mkdir -p /media/hdd"
print "CMD : ", cmd
os.system(cmd)
except:
print "[DeviceManager] autostart failed!"
elif reason == 1:
pass
def menu(menuid, **kwargs):
if menuid == "system":
return [(_("DeviceManager"), main, "device_manager", 50)]
return []
def main(session, **kwargs):
session.open(DeviceManager)
def Plugins(path, **kwargs):
return [
PluginDescriptor(name = _("DeviceManager"), description = _("manage block devices of your VU+"), where = PluginDescriptor.WHERE_MENU,fnc=menu),
PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, needsRestart = True, fnc = sessionstart),
PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, needsRestart = True, fnc = autostart)
]
class MessageBox_2(MessageBox):
def __init__(self, session, text, type = MessageBox.TYPE_YESNO, timeout = -1, close_on_any_key = False, default = True, enable_input = True, msgBoxID = None):
MessageBox.__init__(self, session, text, type, timeout, close_on_any_key, default, enable_input, msgBoxID)
self.skinName = "MessageBox"
self.closeTimer = eTimer()
self.closeTimer.callback.append(self.msg_close)
self.devicemanager_ret = False
self.devicemanager_msg = ""
def msg_close(self):
self.close(self.devicemanager_ret, self.devicemanager_msg)
def run_close(self, ret, msg=""):
self.devicemanager_ret = ret
self.devicemanager_msg = msg
self.closeTimer.start(100,True)
def createSummary(self):
return MessageBox_2_Summary
class MessageBox_2_Summary(Screen):
skin="""
"""
def __init__(self, session, parent):
w,h = session.summary_desktop.size().width(), session.summary_desktop.size().height()
self.skin = self.skin % (w, h, w, h, h/7)
Screen.__init__(self, session, parent = parent)