X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/ed40f6f85c9c07c3c1224ae20601082c0309a631..7b0d371a7bbfb9e8d624eec9ed97e9a835f75ca7:/lib/python/Components/Harddisk.py diff --git a/lib/python/Components/Harddisk.py b/lib/python/Components/Harddisk.py index fee1ed74..79c0d6f8 100644 --- a/lib/python/Components/Harddisk.py +++ b/lib/python/Components/Harddisk.py @@ -1,6 +1,7 @@ -from os import system +from os import system, listdir, statvfs, popen from Tools.Directories import SCOPE_HDD, resolveFilename +from Tools.CList import CList def tryOpen(filename): try: @@ -82,7 +83,7 @@ class Harddisk: if line.startswith(self.devidex): parts = line.strip().split(" ") try: - stat = os.statvfs(parts[1]) + stat = statvfs(parts[1]) except OSError: continue free = stat.f_bfree/1000 * stat.f_bsize/1000 @@ -92,7 +93,7 @@ class Harddisk: def numPartitions(self): try: - idedir = os.listdir(self.devidex) + idedir = listdir(self.devidex) except OSError: return -1 numPart = -1 @@ -110,7 +111,7 @@ class Harddisk: def createPartition(self): cmd = "/sbin/sfdisk -f " + self.devidex + "disc" - sfdisk = os.popen(cmd, "w") + sfdisk = popen(cmd, "w") sfdisk.write("0,\n;\n;\n;\ny\n") sfdisk.close() return 0 @@ -163,12 +164,13 @@ def existHDD(num): return -1 class Partition: - def __init__(self, mountpoint, description = ""): + def __init__(self, mountpoint, description = "", force_mounted = False): self.mountpoint = mountpoint self.description = description + self.force_mounted = force_mounted def stat(self): - return os.statvfs(self.mountpoint) + return statvfs(self.mountpoint) def free(self): try: @@ -186,6 +188,9 @@ class Partition: def mounted(self): # THANK YOU PYTHON FOR STRIPPING AWAY f_fsid. + # TODO: can os.path.ismount be used? + if self.force_mounted: + return True procfile = tryOpen("/proc/mounts") for n in procfile.readlines(): if n.split(' ')[1] == self.mountpoint: @@ -199,6 +204,8 @@ class HarddiskManager: self.partitions = [ ] + self.on_partition_list_change = CList() + for hddNum in range(8): if existHDD(hddNum): hdd = Harddisk(hddNum) @@ -223,6 +230,21 @@ class HarddiskManager: for x in p: self.partitions.append(Partition(mountpoint = x[0], description = x[1])) + def getAutofsMountpoint(self, device): + return "/autofs/%s/" % (device) + + def addHotplugPartition(self, device, description): + p = Partition(mountpoint = self.getAutofsMountpoint(device), description = description, force_mounted = True) + self.partitions.append(p) + self.on_partition_list_change("add", p) + + def removeHotplugPartition(self, device): + mountpoint = self.getAutofsMountpoint(device) + for x in self.partitions[:]: + if x.mountpoint == mountpoint: + self.partitions.remove(x) + self.on_partition_list_change("remove", x) + def HDDCount(self): return len(self.hdd)