elitalobo Mount v2 20130712-142304


Posted:

Mount v2

Task Write a file mount.py which when executed as ./mount.py gives the same output as mount command. For this we require to read /proc/mounts.

Code Description

readfile Function

  1. s=open("/proc/mounts") opens the file mount.py
  2. f=s.read() reads the content of the file /proc/mounts
  3. z=f.split("n") splits the output into individual lines
  4. changefile(z) calls the changefile function
  5. s.close() close /proc/mount file

changefile Function

  1. p=len(z) counts no of lines
  2. a=z[i].split(" ") splits each line into list of words
  3. a.insert(1,"on") inserts "on" in 1st position
  4. a.insert(3,"type") inserts "type" in 3rd position
  5. a.insert(5,"(") inserts open brackett in 5th position
  6. del a[-2] deletes the second last word
  7. del a[-1] deletes the last word
  8. a.append(")") appends a closed bracket at the end of the list
  9. w=" ".join(a) joins words in the list by " "
  10. print w prints each line

link to the code ` link <https://github.com/elitalobo/HomeTask1/tree/master/mount>`_

Contents © 2013 dgplug - Powered by Nikola
Share
UA-42392315-1