Python program which would print the same output as the mount command.

Standard

Its been about a week since my last blog…coz we are presently not studying anything new in the summer training. We are just practising programs on python.
So, kushal gave us some very cool programs to do like to a program which prints the same output as the mount command.
This was my version (I used fedora disto) :

#!/usr/bin/env python
f=open("/proc/mounts")
f.readline()
for s in f:
    s=s.replace(' 0 0\n','')
    s=s.split()
    s.insert(1,'on')
    s.insert(3,'type')
    s[5]='('+s[5]
    a=s[5].split(',')
    del s[-1]
    s=' '.join(s)
    print s,
    if  a[1]=='seclabel':
        c=1
        for j in a:
            if (j[0]=='n' or j[0]=='r') and j[1]!='r' :
                c=c+1
        a.remove('seclabel')
        a.insert(c,'seclabel')
    a=','.join(a)
    print a + ')'
f.close()

I considered arranging the string ‘seclabel’ or else program would have been smaller.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s