self.onLayoutFinish.append(self.showDeviceList)
self.onLayoutFinish.append(self.addPartitionListChange)
self.onClose.append(self.removePartitionListChange)
-# self.onLayoutFinish.append(self.hotplugInactive)
-# self.onClose.append(self.hotplugActive)
self.onChangedEntry = []
self.blockDevices = {}
return
self.showDeviceList()
- def hotplugInactive(self):
- global devicemanagerhotplugactive
- print "[Device manager] hotplug Inctive"
- devicemanagerhotplugactive = False
-
- def hotplugActive(self):
- global devicemanagerhotplugactive
- print "[Device manager] hotplug Active"
- devicemanagerhotplugactive = True
-
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 showPartitionList(self):
if self.currDevice is None:
return
- self["key_red"].setText(_("Devices"))
- self["key_green"].setText(_("Mount"))
- self["key_yellow"].setText(_("Format"))
- self["key_blue"].setText(_("Check"))
partitionList = []
for partition in self.currDevice["partitions"]:
partitionInfo = deviceinfo.getPartitionInfo(partition)
)
# print "[DeviceManager] partitionEntry : ",partitionEntry
partitionList.append(partitionEntry)
- self.currList = "partitions"
- self["menu"].style = "partitions"
- self["menu"].setList(partitionList)
- self.selectionChanged()
+ if len(partitionList) != 0:
+ self["key_red"].setText(_("Devices"))
+ self["key_green"].setText(_("Mount"))
+ 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 showMountPointSetup(self):
if self.currDevice is None or self.currPartition is None:
return
+ partition = self.currPartition["partition"]
+ if not os.access("/autofs/%s"%partition,0):
+ self.session.open(MessageBox, _("This partition is not mountable.\nYou need to check or format this partition."), MessageBox.TYPE_ERROR, timeout = 10)
+ return
self["key_red"].setText(_("Partitions"))
self["key_green"].setText(_("Ok"))
self["key_yellow"].setText("")
# print "keyOk"
if self.currList == "default":
self.currDevice = self.getCurrentDevice()
- self.showPartitionList()
+ 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()
elif self.currList == "partitions":
currMountPoint = self.getCurrentPartition()["mountpoint"]
currUuid = self.getCurrentPartition()["uuid"]
self.currPartition = self.getCurrentPartition()
self.showMountPointSetup()
else:
- self.doUmount(currMountPoint)
- self.showPartitionList()
+ self.doUmount(currMountPoint, self.showPartitionList)
elif self.currList == "mountpoint":
# self["menu"].getCurrent() : (green_button, "menu description", "mount point description, "default", mountpoint, self.divpng)
currEntry = self["menu"].getCurrent()[3]
self.session.openWithCallback(self.deviceFormatCB, DeviceFormat, partition, choice[1])
# about mount funcs..
- def doUmount(self, mountpoint):
+ def doUmount(self, mountpoint, callback):
cmd = "umount %s"%mountpoint
print "[DeviceManager] cmd : %s"%cmd
- self.DeviceManagerConsole.ePopen(cmd, self.doUmountFinished, mountpoint)
-
- def doUmountFinished(self, result, retval, extra_args = None):
- mountpoint = extra_args
- if retval == 0:
-# update current mount state ,devicemanager.cfg
+ os.system(cmd)
+ if not path.ismount(mountpoint):
devicemanagerconfig.updateConfigList()
else:
self.session.open(MessageBox, _("Can't umount %s. \nMaybe device or resource busy.")%mountpoint, MessageBox.TYPE_ERROR, timeout = 10)
+ callback()
def getDefaultMountPoint(self):
return self.defaultMountPoint
def doMount(self, partition, mountpoint):
try:
+# check mountpoint is in partition list.
+ if mountpoint != self.getDefaultMountPoint():
+ for p in harddiskmanager.partitions:
+ if p.mountpoint == mountpoint:
+ self.session.open(MessageBox, _("Can not use this mount point.(%s) \nPlease select another mount point.")%mountpoint, MessageBox.TYPE_ERROR, timeout = 10)
+ return
+#
device = partition["partition"]
- fstype = partition["fstype"]
+ filesystem = partition["fstype"]
+ uuid = partition["uuid"]
if mountpoint.endswith("/"):
mountpoint = retval[:-1]
if mountpoint.find(' ') != -1:
mountpoint = mountpoint.replace(' ','-')
- dev = deviceinfo.checkMountPoint(mountpoint)
- if dev is None:
- if not path.exists(mountpoint):
- print "[deviceManager] make dir %s"%mountpoint
- makedirs(mountpoint)
- if fstype == "ntfs":
- cmd = "ntfs-3g /dev/%s %s" % (device, mountpoint)
- else:
- cmd = "mount /dev/%s %s" % (device, mountpoint)
- os.system(cmd)
- print "[DeviceManager] cmd : %s"%cmd
+ devpath = "/dev/"+device
+ if deviceinfo.isMounted(devpath, mountpoint):
+ print "[DeviceManager] '%s -> %s' is already mounted."%(devpath, mountpoint)
+ return
+
+# check current device mounted on another mountpoint.
+ mp_list = deviceinfo.checkMountDev(devpath)
+ for mp in mp_list:
+ if mp != mountpoint and path.ismount(mp):
+ deviceinfo.umountByMountpoint(mp)
+# check another device mounted on configmountpoint
+ devpath_list = deviceinfo.checkMountPoint(mountpoint)
+ for devpath_ in devpath_list:
+ if devpath_ != devpath:
+ self.session.open(MessageBox, _("Mount Failed!\nCurrent path is already mounted by \"%s\"")%devpath_list[0], MessageBox.TYPE_ERROR, timeout = 10)
+ return
+# do mount
+ print "[DeviceManagerHotplugDevice] doMount"
+ if not path.exists(mountpoint):
+ os.system("mkdir %s"%mountpoint)
+ if path.exists(mountpoint):
+ if not path.ismount(mountpoint):
+ if filesystem == "ntfs":
+ cmd = "ntfs-3g %s %s"%(devpath, mountpoint)
+ elif filesystem is None:
+ cmd = "mount %s %s"%(devpath, mountpoint)
+ else:
+ cmd = "mount -t %s %s %s"%(filesystem, devpath, mountpoint)
+ print "[DeviceManager] cmd : %s"%cmd
+ self.DeviceManagerConsole.ePopen(cmd, self.doMountFinished, (devpath, mountpoint) )
+ except:
+ self.session.open(MessageBox, _("Mount Failed!\n(%s -> %s)")%(device, mountpoint), MessageBox.TYPE_ERROR, timeout = 10)
+
+ def doMountFinished(self, result, retval, extra_args = None):
+ (devpath, mountpoint) = extra_args
+ if retval == 0:
+ if not deviceinfo.isMounted(devpath, mountpoint):
+# print "[DeviceManager] %s doMount failed!"%devpath
+ self.session.open(MessageBox, _("Mount Failed!\n(%s -> %s)")%(devpath, mountpoint), MessageBox.TYPE_ERROR, timeout = 10)
+ return
+ else:
+# make movie directory
if mountpoint == "/media/hdd":
movieDir = mountpoint + "/movie"
if not pathExists(movieDir):
self.showPartitionList()
# update current mount state ,devicemanager.cfg
devicemanagerconfig.updateConfigList()
- else:
- self.session.open(MessageBox, _("Mount Failed!\nCurrent path is already mounted by \"%s\"")%dev, MessageBox.TYPE_ERROR, timeout = 10)
- except:
- self.session.open(MessageBox, _("Mount Failed!(%s -> %s)")%(device, mountpoint), MessageBox.TYPE_ERROR, timeout = 10)
def MountpointBrowserCB(self, retval = None):
if retval and retval is not None:
self.exitMessageTimer = eTimer()
self.exitMessageTimer.callback.append(self.exitMessage)
self.msg = ""
+ self.fstype = None
def timerStart(self):
self.initStartTimer.start(100,True)
if not line.startswith("/dev/" + device):
continue
cmd += "umount %s ;"% line.split()[0]
- os.system(cmd)
+ print "[DeviceManager] %s"%cmd
+ os.system(cmd)
#recheck if umounted
mounts = file('/proc/mounts').read().split('\n')
for line in mounts:
def InputPartitionSize_step2(self):
current_partition = len(self.inputbox_partitionSizeList)+1
if self.inputbox_partitionSizeRemain == 0:
- self.initInitializeConfirm()
+ self.choiceBoxFstype()
elif current_partition == self.inputbox_partitions:
self.inputbox_partitionSizeList.append(str(self.inputbox_partitionSizeRemain))
- self.initInitializeConfirm()
+ 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.(Max = %d MB)")%(current_partition,self.inputbox_partitionSizeRemain ), text=text, maxSize=False, type=Input.NUMBER)
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 Bytes"%(index+1, str(self.inputbox_partitionSizeList[index]))
partitionsInfo += "partition %d : %s MB\n"%(index+1, str(self.inputbox_partitionSizeList[index]))
+ partitionsInfo += "filesystem type : %s"%(self.fstype)
self.session.openWithCallback(self.initInitializeConfirmCB, MessageBoxConfirm, _("%s\nStart Device Inititlization?") % partitionsInfo , MessageBox.TYPE_YESNO)
def initInitializeConfirmCB(self,ret):
break
partitions.close()
- if partitionsize > 64 * 1024 * 1024:
- cmd = "/sbin/mkfs.ext3 "
- filesystem = "ext3"
+ if self.fstype == "ext4":
+ cmd = "/sbin/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 = "/sbin/mkfs.ext3 -F "
+ if partitionsize > 2 * 1024 * 1024:
+ cmd += "-T largefile "
+ cmd += "-m0 " + fulldevicename
+ elif self.fstype == "ext2":
+ cmd = "/sbin/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 = "/usr/sbin/mkfs.vfat -I -S4096 " + fulldevicename
+ else:
+ cmd = "/usr/sbin/mkfs.vfat -I " + fulldevicename
else:
- cmd = "/sbin/mkfs.ext2 "
- filesystem = "ext2"
-
- if partitionsize > 2 * 1024 * 1024:
- cmd += "-T largefile "
- cmd += "-m0 " + fulldevicename
+ self.createFilesystemFinished(None, -1, (self.device, fulldevicename))
+ return
msg = _("Create filesystem, please wait ...")
msg += _("\nPartition : %s") % (fulldevicename)
- msg += _("\nFilesystem : %s") % (filesystem)
+ msg += _("\nFilesystem : %s") % (self.fstype)
msg += _("\nSize : %d MB\n")%int(self.inputbox_partitionSizeList[self.devicenumber-1])
self.msgWaitingMkfs = self.session.openWithCallback(self.msgWaitingMkfsCB, MessageBox_2, msg, type = MessageBox.TYPE_INFO, enable_input = False)
self.deviceInitConsole.ePopen(cmd, self.createFilesystemFinished, (self.device, fulldevicename))
if ret == True:
self.success = True
self.msg = _("Device Initialization finished sucessfully!")
+ self.updateDeviceInfo()
self.exitMessageTimer.start(100,True)
else:
self.success = False
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)
-
+
+ def updateDeviceInfo(self):
+# update devicemanager configs
+ devicemanagerconfig.updateConfigList()
+
# Initializing end
# device check start..
self.onLayoutFinish.append(self.timerStart)
self.formatStartTimer = eTimer()
self.formatStartTimer.callback.append(self.DeviceFormatStart)
+ self.setHotplugDisabled = False
def timerStart(self):
self.formatStartTimer.start(100,True)
def DeviceFormatStart(self):
+ devicemanagerhotplug.setHotplugActive(False)
+ self.setHotplugDisabled = True
print "DeviceFormatStart : ", self.partition,
print "Filesystem : ",self.newfstype
device = self.partition["partition"]
self.session.openWithCallback(self.exit, MessageBox, msg, MessageBox.TYPE_ERROR, timeout = 10)
def exit(self, ret):
+ if self.setHotplugDisabled == True:
+ devicemanagerhotplug.setHotplugActive(True)
+ self.setHotplugDisabled = False
self.close()
#device format end
return ""
def checkMountPoint(self, check_mountpoint):
+ res = []
try:
mounts = file('/proc/mounts').read().split('\n')
for x in mounts:
continue
devpath, mountpoint = x.split()[:2]
if mountpoint == check_mountpoint:
- return devpath
+ res.append(devpath)
except:
pass
- return None
+ 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').read().split('\n')
+ 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 isMountable(self, partition):
+ autofsPath = "/autofs/"+partition.device
+ mountable = False
+ try:
+ os.listdir(autofsPath)
+ mountable = True
+ except:
+ pass
+ return mountable
+
+ 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()
devicemanagerconfig = DeviceManagerConfig()
-devicemanagerhotplugactive = True
-def DeviceManagerhotplugDeviceStart(action, device):
- global devicemanagerhotplugactive
- if devicemanagerhotplugactive:
- DeviceManagerHotplugDevice(action, device)
+class deviceManagerHotplug:
+ def __init__(self):
+ self.hotplugActive = True
+
+ def setHotplugActive(self,value=True):
+ if value:
+ self.hotplugActive = True
+ else:
+ self.hotplugActive = False
+
+ def printDebug(self):
+ for p in harddiskmanager.partitions:
+ print " # partition : %s %s %s %s %s(mp, des, f_mounted, is_hot, dev)"%(p.mountpoint, p.description, p.force_mounted, p.is_hotplug,p.device)
+
+ def doMount(self, uuid, devpath, mountpoint, filesystem):
+# check current device mounted on another mountpoint.
+ mp_list = []
+ mp_list = deviceinfo.checkMountDev(devpath)
+ for mp in mp_list:
+ if mp != mountpoint and path.ismount(mp):
+ deviceinfo.umountByMountpoint(mp)
+# check another device mounted on configmountpoint
+ devpath_list = []
+ devpath_list = deviceinfo.checkMountPoint(mountpoint)
+ for devpath_ in devpath_list:
+ if devpath_ != devpath:
+ print "[DeviceManager] Mount Failed. (Another device is already mounted)"
+ return
+# do mount
+# print "[DeviceManager] doMount"
+ if not path.exists(mountpoint):
+ os.system("mkdir %s"%mountpoint)
+ if path.exists(mountpoint):
+ if not path.ismount(mountpoint):
+ if filesystem == "ntfs":
+ cmd = "ntfs-3g %s %s"%(devpath, mountpoint)
+ elif filesystem is None:
+ cmd = "mount %s %s"%(devpath, mountpoint)
+ else:
+ cmd = "mount -t %s %s %s"%(filesystem, devpath, mountpoint)
+ print "[DeviceManager] cmd : %s"%cmd
+ os.system(cmd)
+ if not deviceinfo.isMounted(devpath, mountpoint):
+ print "[DeviceManager] %s doMount failed!"%devpath
+ return
+ else:
+# Update partition Info, add
+ self.addPartitionAutofsMountpoint(devpath, mountpoint)
-def DeviceManagerHotplugDevice(action, device):
- if not config.plugins.devicemanager.hotplug_enable.value:
- return
- print "[DeviceManager Hotplug Device] action : %s, device : %s"%(action, device.device)
+ def doUmount(self, device, mountpoint):
+ devpath = "/dev/"+device
+ mountpoints = deviceinfo.checkMountDev(devpath)
+ if len(mountpoints) == 0:
+ return
+ for mp in mountpoints:
+ cmd = "umount %s"%devpath
+ print "[DeviceManager] cmd : %s"%cmd
+ os.system(cmd)
- try:
- if action == 'add' and device.is_hotplug and len(device.device) == 3:
- if device.device.startswith("sd"):
- newdevice = "/dev/" + device.device
- cmd = "sleep 3 && blkid -c /dev/null " + newdevice + "*"
- data = popen(cmd).read().split('\n')
-# print "[DeviceManagerHotplugDevice] blkid data : ",data
- for line in data:
- uuid = ""
- partitionType = ""
- if line.startswith(newdevice):
- 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('"')
- mountdev = line.split(':')[0]
- devicemanagerconfig.loadConfig()
- configList = devicemanagerconfig.getConfigList()
- for c in configList:
- if uuid == c[0].strip():
- mountpoint = c[1].strip()
- if not os.path.ismount(mountpoint):
- if partitionType == "ntfs":
- cmd = "ntfs-3g %s %s"%(mountdev, mountpoint)
- else:
- cmd = "mount %s %s"%(mountdev, mountpoint)
- print "[DeviceManagerHotplugDevice] try..'%s'"%cmd
- os.system(cmd)
-
- elif action == 'remove' and device.device is not None and len(device.device) == 3:
- mounts = file('/proc/mounts').read().split('\n')
- for x in mounts:
- if not x.startswith('/'):
- continue
- if x.startswith("/dev/"+device.device):
- cmd = "umount "+x.split()[0]
- print "[DeviceManagerHotplugDevice] try.. '%s'"%cmd
- os.system(cmd)
- except:
- print "[DeviceManagerHotplug] hotplugDevice error."
+ def addHotPlugDevice(self, partition):
+ device = partition.device
+ devpath = "/dev/"+device
+# get BlkidInfo
+ (uuid, filesystem) = deviceinfo.getPartitionBlkidInfo(device)
+ if uuid == "":
+# retry..
+ os.system("sleep 1")
+ (uuid, filesystem) = deviceinfo.getPartitionBlkidInfo(device)
+ if uuid == "":
+ print "[DeviceManagerHotplug] getBlkidInfo failed!"
+ return
+# get configList
+ devicemanagerconfig.loadConfig()
+ configList = devicemanagerconfig.getConfigList()
+ mountpoint = None
+ for line in configList:
+ if uuid == line[0].strip():
+ mountpoint = line[1].strip()
+ break
+ if mountpoint is None:
+ return
+# do mount
+ if deviceinfo.isMounted(devpath, mountpoint):
+ pass
+# print "[DeviceManagerHotplug] already mounted"
+ else:
+ self.doMount(uuid, devpath, mountpoint, filesystem)
+
+ def removeHotplugDevice(self, partition):
+ self.doUmount(partition.device, partition.mountpoint)
+
+ def getHotplugAction(self, action, partition):
+ if not self.hotplugActive or not config.plugins.devicemanager.hotplug_enable.value:
+ return
+ if partition.device is None or not partition.device.startswith("sd"):
+ return
+ print "[DeviceManagerHotplug] action : %s, device : %s"%(action, partition.device)
+
+ if action == 'add':
+ self.addHotPlugDevice(partition)
+ elif action == 'remove':
+ self.removeHotplugDevice(partition)
+
+ def addPartitionAutofsMountpoint(self, devpath, mountpoint):
+ device = path.basename(devpath)
+ autofsMountpoint = harddiskmanager.getAutofsMountpoint(device)
+# check already appended to partition list
+ for x in harddiskmanager.partitions:
+ if x.mountpoint == autofsMountpoint or x.mountpoint == mountpoint:
+ return
+#
+ from Components.Harddisk import Partition
+ physdev = path.realpath('/sys/block/' + device[:3] + '/device')[4:]
+ description = harddiskmanager.getUserfriendlyDeviceName(device, physdev)
+ p = Partition(mountpoint = autofsMountpoint, description = description, force_mounted = True, device = device)
+ harddiskmanager.partitions.append(p)
+ harddiskmanager.on_partition_list_change("add", p)
+
+ def autoMountOnStartup(self):
+ devicemanagerconfig.loadConfig()
+ configList = devicemanagerconfig.getConfigList()
+# get blkid info
+ blkiddata = []
+ data = os.popen("blkid -c /dev/NULL /dev/sd*").readlines()
+ for line in data:
+ devpath = uuid = filesystem = ""
+ devpath = line.split(':')[0]
+ if line.find(" UUID=") != -1:
+ uuid = line.split(" UUID=")[1].split(' ')[0]
+ if line.find(" TYPE=") != -1:
+ filesystem = line.split(" TYPE=")[1].split(' ')[0].strip('"')
+ blkiddata.append((devpath, uuid, filesystem))
+# check configList
+ for c in configList:
+ uuid_cfg = c[0].strip()
+ mountpoint_cfg = c[1].strip()
+ for (devpath, uuid, filesystem) in blkiddata:
+ if uuid_cfg == uuid:
+# do mount
+ if deviceinfo.isMounted(devpath, mountpoint_cfg):
+# print "[Devicemanager startup] already mounted"
+ self.addPartitionAutofsMountpoint(devpath, mountpoint_cfg)
+ else:
+# print "[autoMountOnStartup] do mount(%s %s %s)"%(devpath, configmountpoint, filesystem)
+ self.doMount(uuid, devpath, mountpoint_cfg, filesystem)
+
+ def umountOnShutdown(self):
+ devicemanagerconfig.loadConfig()
+ configList = devicemanagerconfig.getConfigList()
+# get mount info
+ mounts = []
+ data = file('/proc/mounts').read().split('\n')
+ for x in data:
+ if not x.startswith('/dev/sd'):
+ continue
+ devpath, mountpoint = x.split()[:2]
+ mounts.append((path.basename(devpath), mountpoint))
+# get blkid info
+ data = self.getBlkidInfo()
+# check configList
+ for c in configList:
+ uuid_cfg = c[0].strip()
+ mountpoint_cfg = c[1].strip()
+ device_cfg = None
+ if uuid_cfg in data.keys():
+ device_cfg = data[uuid_cfg]
+ if device_cfg is None:
+ continue
+ for (device, mountpoint) in mounts:
+ if device_cfg == device:
+ if not deviceinfo.isFstabAutoMounted(uuid_cfg, "/dev/"+device_cfg, mountpoint_cfg):
+ self.doUmount(device, mountpoint)
+
+ def getBlkidInfo(self):
+ data = {}
+ blkid_data = os.popen("blkid -c /dev/NULL /dev/sd*").read()
+ for line in blkid_data.split('\n'):
+# print "[DeviceManager] getBlkidInfo line : ",line
+ device = uuid = ""
+ device = path.basename(line.split(':')[0])
+ if line.find(" UUID=") != -1:
+ blkid_uuid = line.split(" UUID=")[1].split(' ')[0]
+ data[blkid_uuid] = device
+ return data
+
+devicemanagerhotplug = deviceManagerHotplug()
+
+def DeviceManagerhotplugDeviceStart(action, device):
+ devicemanagerhotplug.getHotplugAction(action, device)
def callBackforDeviceManager(session, callback_result = False):
if callback_result == True:
def checkMounts(session):
try:
- file = open("/proc/partitions")
- partitions = file.readlines()
- file.close()
- file = open("/proc/mounts")
- mounts = file.readlines()
- file.close()
- not_mounted = False
- for part in partitions:
- res = re.sub("\s+", " ", part).strip().split(" ")
- if res and len(res) == 4:
- if len(res[3]) == 3 and res[3][:2] == "sd":
- device = "/dev/" + res[3]
- print "found device %s"%device
- not_mounted = True
- for line in mounts:
- if line.split()[1].startswith('/autofs'):
- continue
- if line.startswith(device):
- print line
- not_mounted = False
- break
- if not_mounted == True:
- break
-
- if not_mounted == True:
- print "Umounted partitions found."
- InfoText = _("umounted partitions found.!\nDo you want to open DeviceManager and set mount point?\n\n(Open 'Menu->Setup->System -> Harddisk -> DeviceManager'\n and press MENU button to deactivate this check.)")
- AddNotificationWithCallback(
- boundFunction(callBackforDeviceManager, session),
- MessageBox, InfoText, timeout = 60, default = False
- )
+ 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
+ partitions.append(partition)
+ 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!"
if not fileExists(dmconfigfile):
print "[DeviceManager] autostart : check devices at first start"
sda_isremovable = False
-# sdb_isremovable = False
sda_UUID = ""
-# sdb_UUID = ""
os.system("touch %s"%dmconfigfile)
# check sda
sda_data = popen("cat /proc/partitions | grep sda1").read()
sda_UUID = popen("blkid -o value -s UUID /dev/sda1").read().strip('\n')
sda_isremovable = bool(int(readFile("/sys/block/sda/removable")))
print "sda : %s, %s"%(sda_UUID, sda_isremovable)
-# check sdb
-# sdb_data = popen("cat /proc/partitions | grep sdb1").read()
-# if sdb_data != '':
-# sdb_UUID = popen("blkid -o value -s UUID /dev/sdb1").read().strip('\n')
-# sdb_isremovable = bool(int(readFile("/sys/block/sdb/removable")))
-# print "sdb : %s, %s"%(sdb_UUID, sdb_isremovable)
cfg = ""
if sda_data != '':
-# if sdb_data != '':
-# if not sda_isremovable:
-# cfg += '"%s":/media/hdd\n'%sda_UUID
-# cfg += '"%s":/media/usb\n'%sdb_UUID
-# else:
-# if not sdb_isremovable:
-# cfg += '"%s":/media/hdd\n'%sdb_UUID
-# cfg += '"%s":/media/usb\n'%sda_UUID
-# else:
-# cfg += '"%s":/media/hdd\n'%sda_UUID
-# cfg += '"%s":/media/usb\n'%sdb_UUID
-# else:
-# cfg += '"%s":/media/hdd\n'%sda_UUID
cfg += '"%s":/media/hdd\n'%sda_UUID
confFile = open(dmconfigfile,'w')
confFile.write(cfg)
confFile.close()
-# if not path.exists("/media/usb"):
-# os.system("mkdir -p /media/usb")
if not path.exists("/media/hdd"):
os.system("mkdir -p /media/hdd")
-
-# check at first enigma2 start - end
- devicemanagerconfig.loadConfig()
- configList = devicemanagerconfig.getConfigList()
- if len(configList) != 0:
- print "[DeviceManager] automount from device manager configs"
- cmd = "blkid -c /dev/null /dev/sd*"
- data = popen(cmd).read().split('\n')
- for line in data:
- device = ""
- uuid = ""
- filesystem = ""
- device = line.split(':')[0]
- if line.find(" UUID=") != -1:
- uuid = line.split(" UUID=")[1].split(' ')[0]
- if line.find(" TYPE=") != -1:
- filesystem = line.split(" TYPE=")[1].split(' ')[0].strip('"')
- for line in configList:
- configuuid = line[0].strip()
- configmountpoint = line[1].strip()
- if configuuid == uuid and path.exists(configmountpoint) and not path.ismount(configmountpoint):
- if filesystem == "ntfs":
- cmd = "ntfs-3g %s %s"%(device, configmountpoint)
- else:
- cmd = "mount -t %s %s %s"%(filesystem, device, configmountpoint)
- print "[DeviceManager] ",cmd
- os.system(cmd)
- break
+# auto mount
+ devicemanagerhotplug.autoMountOnStartup()
except:
print "[DeviceManager] autostart failed!"
+ elif reason == 1:
+ devicemanagerhotplug.umountOnShutdown()
def menu(menuid, **kwargs):
- if menuid == "harddisk":
- return [(_("DeviceManager"), main, "device_manager", 1)]
+ if menuid == "system":
+ return [(_("DeviceManager"), main, "device_manager", 50)]
return []
def main(session, **kwargs):
<screen name="MessageBox_2_Summary" position="0,0" size="256,64" id="1">
<widget source="parent.Text" render="Label" position="0,0" size="256,64" font="Regular;13" halign="center" valign="center" />
</screen>
- """
\ No newline at end of file
+ """
+