There's always one moment in your live when suddently you need to take a look at what on earth is mounted on your own filesystem. It's a rather tedious task, but luckily here comes python to rescue us :D There's a simple script to ease the complex task of issuing mount command.
It has to do mainly with reading the file /proc/mounts, a text file wich contains all the devices mounted on your pc, their mount points, their filesystem type and finally their mount-mode.
Link to the code in GitHub: mount.py
The first thing this code should do is to define a nice function that will open the file with the function open (), to check for the existance of such file with os.path.exists(), and to return the hole file in just one string, enough for our needs.
11 import os 12 13 def readFile(fileName): 14 """ 15 Simple function to open the file in read-mode and read it entirely. 16 17 :arg fileName: File name (if it's in the same directory) or full path of the file we want to read. 18 19 :return: if the file exists, returns the hole file in a single string. If it doesn't, you're screwed 20 """ 21 if os.path.exists(fileName):#We check of the path given in the argument exists in the filesystem 22 fileRead = open (fileName)#We open the file given in default mode (read-only) 23 content = fileRead.read()#We return a String with the content of all the file in it 24 fileRead.close()#We propperly close the file 25 return content 26 else: #if the path doesn't exists, inform the user 27 return "Something is fucked up, man..."
Then it just has to print the content. I use the multiline string feature to improve code readability. It's more cute, you know.
27 #We print the output 28 print """ 29 ======================= 30 Output of Mount Command 31 ======================= 32 33 #dgplug 34 35 | | | | | | | 36 v v v v v v v 37 38 %s""" %readFile("/proc/mounts")#We call readFile function, wich will return the the hole content of /proc/mounts, wich is the output of mount command. voila!
That's it. We can finally check mount using python. Enjoy