+ def getCD(self):
+ return self.cd
+
+ def getMountedPartitions(self, onlyhotplug = False):
+ parts = [x for x in self.partitions if (x.is_hotplug or not onlyhotplug) and x.mounted()]
+ devs = set([x.device for x in parts])
+ for devname in devs.copy():
+ if not devname:
+ continue
+ dev, part = self.splitDeviceName(devname)
+ if part and dev in devs: # if this is a partition and we still have the wholedisk, remove wholedisk
+ devs.remove(dev)
+
+ # return all devices which are not removed due to being a wholedisk when a partition exists
+ return [x for x in parts if not x.device or x.device in devs]
+
+ def splitDeviceName(self, devname):
+ # this works for: sdaX, hdaX, sr0 (which is in fact dev="sr0", part=""). It doesn't work for other names like mtdblock3, but they are blacklisted anyway.
+ dev = devname[:3]
+ part = devname[3:]
+ for p in part:
+ if not p.isdigit():
+ return devname, 0
+ return dev, part and int(part) or 0
+
+ def getUserfriendlyDeviceName(self, dev, phys):
+ dev, part = self.splitDeviceName(dev)
+ description = "External Storage %s" % dev
+ try:
+ description = readFile("/sys" + phys + "/model")
+ except IOError, s:
+ print "couldn't read model: ", s
+ from Tools.HardwareInfo import HardwareInfo
+ for physdevprefix, pdescription in DEVICEDB.get(HardwareInfo().device_name,{}).items():
+ if phys.startswith(physdevprefix):
+ description = pdescription
+
+ # not wholedisk and not partition 1
+ if part and part != 1:
+ description += " (Partition %d)" % part
+ return description
+
+ def addMountedPartition(self, device, desc):
+ already_mounted = False
+ for x in self.partitions[:]:
+ if x.mountpoint == device:
+ already_mounted = True
+ if not already_mounted:
+ self.partitions.append(Partition(mountpoint = device, description = desc))
+
+ def removeMountedPartition(self, mountpoint):
+ for x in self.partitions[:]:
+ if x.mountpoint == mountpoint:
+ self.partitions.remove(x)
+ self.on_partition_list_change("remove", x)