-import os
+from os import system, listdir, statvfs, popen
-from Tools.Directories import *
+from Tools.Directories import SCOPE_HDD, resolveFilename
+from Tools.CList import CList
def tryOpen(filename):
try:
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
def numPartitions(self):
try:
- idedir = os.listdir(self.devidex)
+ idedir = listdir(self.devidex)
except OSError:
return -1
numPart = -1
def unmount(self):
cmd = "/bin/umount " + self.devidex + "part*"
- res = os.system(cmd)
+ res = system(cmd)
return (res >> 8)
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
def mkfs(self):
cmd = "/sbin/mkfs.ext3 -T largefile -m0 " + self.devidex + "part1"
- res = os.system(cmd)
+ res = system(cmd)
return (res >> 8)
def mount(self):
cmd = "/bin/mount -t ext3 " + self.devidex + "part1 /hdd"
- res = os.system(cmd)
+ res = system(cmd)
return (res >> 8)
def createMovieFolder(self):
- res = os.system("mkdir " + resolveFilename(SCOPE_HDD))
+ res = system("mkdir " + resolveFilename(SCOPE_HDD))
return (res >> 8)
errorList = [ _("Everything is fine"), _("Creating partition failed"), _("Mkfs failed"), _("Mount failed"), _("Create movie folder failed"), _("Unmount failed")]
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:
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:
self.partitions = [ ]
+ self.on_partition_list_change = CList()
+
for hddNum in range(8):
if existHDD(hddNum):
hdd = Harddisk(hddNum)
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)