Skip to content

Commit

Permalink
Support for retrieving mounted file systems
Browse files Browse the repository at this point in the history
  • Loading branch information
amitsaha committed Jan 6, 2013
1 parent eda652d commit f6bb3a7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
8 changes: 8 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@
print dev + ': ' + 'Recieved (MB): ' + str(net_devs[dev].rx) + \
' Transmitted (MB): ' + str(net_devs[dev].tx)


#mounted file systems
print 'Physical File Systems Mounted::'
print pylinux.mounts()

print 'All File Systems Mounted::'
print pylinux.mounts(nodev=False)

45 changes: 38 additions & 7 deletions pylinux/pylinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ def totalmem():

return readproc.meminfo()['MemTotal']

def num_disks():
''' TODO '''
pass

def disk_stats():
''' TODO '''
pass

## dynamic information
def last_boot():
Expand Down Expand Up @@ -117,3 +110,41 @@ def netdevs():
module '''

return readproc.netdevs()

def mounts(nodev=True):
''' Return current filesystem usage stats .
uses df utility command
nodev=True for getting physical FSs
False for all
'''

# Get the loaded FSs
loaded_fs=[]
with open('/proc/filesystems') as f:
for line in f:
line=line.split('\n')[0]
if nodev:
if line.split('\t')[0]=='':
loaded_fs.append(line.split('\t')[1])
else:
loaded_fs.append(line.split('\t')[1])

# build up file system list for df
df_fs=[]
for fs in loaded_fs:
df_fs.extend(['-t',fs])

# Get the mounted file systems
df_cmd = ['df','-k','-T']
df_cmd.extend(df_fs)
df = subprocess.check_output(df_cmd)

# TODO: just return a list of mounted partitions for now
# in the following format:
# Filesystem Type 1K-blocks Used Available Use% Mounted on
# /dev/sda2 ext4 51614140 14499996 36589880 29% /
# ..
# Perhaps group them into a dictionary and return..

return df

0 comments on commit f6bb3a7

Please sign in to comment.