socialnerds/hive
socialnerds
/
hive
Archived
1
0
Fork 0

added partition dectection draft

This commit is contained in:
David 2012-05-15 11:12:02 +02:00
parent 52cb4c4087
commit cb4a846d72
1 changed files with 25 additions and 11 deletions

View File

@ -1,26 +1,40 @@
#!/usr/bin/python2.7
import os
file = open("/proc/partitions", "r")
file = file.read()
# getting all local partitions (regardless if mounted or not)
partitions = []
for line in file.split("\n"):
if "sd" in line or "hd" in line:
partitions.append(line.split()[3])
print "partitions on this system: %s" %(partitions)
#import os
# given paths(mountpoints)
path=("/boot", "/", "/home/")
#path=("/boot", "/", "/home/")
#output head
print "mountpoints\tfree megabytes"
print "------------------------------"
#print "mountpoints\tfree megabytes"
#print "------------------------------"
#work path tuple
for mountpoint in path:
#for mountpoint in path:
#check if given path is a mountpoint
if os.path.ismount(mountpoint):
# if os.path.ismount(mountpoint):
#create statvfs object
fs = os.statvfs(mountpoint)
# fs = os.statvfs(mountpoint)
#calculate free megabytes
freembytes = fs.f_bavail * fs.f_bsize / 1024**2.0
# freembytes = fs.f_bavail * fs.f_bsize / 1024**2.0
#output
print "%s\t\t%.1f MB" %(mountpoint, freembytes)
else:
print "error: given path is not a mountpoint"
# print "%s\t\t%.1f MB" %(mountpoint, freembytes)
# else:
# print "error: given path is not a mountpoint"
# end of file