47 lines
1.0 KiB
Python
Executable File
47 lines
1.0 KiB
Python
Executable File
#!/usr/bin/python2
|
|
|
|
import os
|
|
|
|
|
|
file = open("/proc/partitions", "r")
|
|
parts = file.read()
|
|
file.close()
|
|
|
|
# getting all local partitions (regardless if mounted or not)
|
|
partitions = []
|
|
blocks = []
|
|
for line in parts.split("\n"):
|
|
if line and "name" not in line and "sr0" not in line:
|
|
if line.split()[2] != "1":
|
|
partitions.append(line.split()[3])
|
|
blocks.append(line.split()[2])
|
|
|
|
print "partitions: %s \nblocks: %s" %(partitions, blocks)
|
|
|
|
|
|
exit()
|
|
|
|
|
|
# given paths(mountpoints)
|
|
path=("/boot", "/", "/dev/sda6")
|
|
|
|
#output head
|
|
print "mountpoints\tfree megabytes"
|
|
print "------------------------------"
|
|
|
|
#work path tuple
|
|
for mountpoint in path:
|
|
#check if given path is a mountpoint
|
|
# if os.path.ismount(mountpoint):
|
|
#create statvfs object
|
|
fs = os.statvfs(mountpoint)
|
|
#calculate free megabytes
|
|
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"
|
|
|
|
|
|
# end of file
|