socialnerds/hive
socialnerds
/
hive
Archived
1
0
Fork 0

better partititon detection

This commit is contained in:
David 2012-05-15 11:31:00 +02:00
parent cb4a846d72
commit 9df4fb1d8c
1 changed files with 13 additions and 9 deletions

View File

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