+ 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):
+ dev = ""
+ part = ""
+ for i in devname:
+ if i in string.digits:
+ part += i
+ else:
+ dev += i
+ 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 = open("/sys/" + phys + "/model").read().strip()
+ except IOError, s:
+ print "couldn't read model (from /sys/" + phys + "/model): ", s
+ for physdevprefix, pdescription in DEVICEDB.items():
+ if phys.startswith(physdevprefix):
+ description = pdescription
+
+ # not wholedisk and not partition 1
+ if part and part != 1:
+ description += " (Partition %d)" % part
+ return description