1 from os import system, listdir, statvfs, popen
3 from Tools.Directories import SCOPE_HDD, resolveFilename
7 procFile = open(filename)
13 return "/proc/ide/hd" + ("a","b","c","d","e","f","g","h","i")[num] + "/"
16 def __init__(self, index):
20 bus = (self.index & 2)
21 target = (self.index & 1)
23 self.prochdx = num2prochdx(index)
24 self.devidex = "/dev/ide/host%d/bus%d/target%d/lun0/" % (host, bus, target)
33 ret = "External (CF) - "
43 procfile = tryOpen(self.prochdx + "capacity")
48 line = procfile.readline()
56 cap = cap / 1000 * 512 / 1000
58 return "%d.%03d GB" % (cap/1024, cap%1024)
61 procfile = tryOpen(self.prochdx + "model")
66 line = procfile.readline()
72 procfile = tryOpen("/proc/mounts")
79 line = procfile.readline()
82 if line.startswith(self.devidex):
83 parts = line.strip().split(" ")
85 stat = statvfs(parts[1])
88 free = stat.f_bfree/1000 * stat.f_bsize/1000
93 def numPartitions(self):
95 idedir = listdir(self.devidex)
99 for filename in idedir:
100 if filename.startswith("disc"):
102 if filename.startswith("part"):
107 cmd = "/bin/umount " + self.devidex + "part*"
111 def createPartition(self):
112 cmd = "/sbin/sfdisk -f " + self.devidex + "disc"
113 sfdisk = popen(cmd, "w")
114 sfdisk.write("0,\n;\n;\n;\ny\n")
119 cmd = "/sbin/mkfs.ext3 -T largefile -m0 " + self.devidex + "part1"
124 cmd = "/bin/mount -t ext3 " + self.devidex + "part1 /hdd"
128 def createMovieFolder(self):
129 res = system("mkdir " + resolveFilename(SCOPE_HDD))
132 errorList = [ _("Everything is fine"), _("Creating partition failed"), _("Mkfs failed"), _("Mount failed"), _("Create movie folder failed"), _("Unmount failed")]
134 def initialize(self):
137 if self.createPartition() != 0:
143 if self.mount() != 0:
146 if self.createMovieFolder() != 0:
152 mediafile = tryOpen(num2prochdx(num) + "media")
157 line = mediafile.readline()
160 if line.startswith("disk"):
166 def __init__(self, mountpoint, description = ""):
167 self.mountpoint = mountpoint
168 self.description = description
171 return statvfs(self.mountpoint)
176 return s.f_bavail * s.f_bsize
183 return s.f_blocks * s.f_bsize
188 # THANK YOU PYTHON FOR STRIPPING AWAY f_fsid.
189 # TODO: can os.path.ismount be used?
190 procfile = tryOpen("/proc/mounts")
191 for n in procfile.readlines():
192 if n.split(' ')[1] == self.mountpoint:
196 class HarddiskManager:
201 self.partitions = [ ]
203 for hddNum in range(8):
205 hdd = Harddisk(hddNum)
208 # currently, this is just an enumeration of what's possible,
209 # this probably has to be changed to support automount stuff.
210 # still, if stuff is mounted into the correct mountpoints by
211 # external tools, everything is fine (until somebody inserts
212 # a second usb stick.)
214 ("/media/hdd", _("Harddisk")),
215 ("/media/card", _("Card")),
216 ("/media/cf", _("Compact Flash")),
217 ("/media/mmc1", _("MMC Card")),
218 ("/media/net", _("Network Mount")),
219 ("/media/ram", _("Ram Disk")),
220 ("/media/usb", _("USB Stick")),
221 ("/", _("Internal Flash"))
225 self.partitions.append(Partition(mountpoint = x[0], description = x[1]))
233 hdd = hd.model() + " ("
239 list.append((hdd, hd))
243 def getMountedPartitions(self):
244 return [x for x in self.partitions if x.mounted()]
246 harddiskmanager = HarddiskManager()