Python on linux

John Abel jabel at plus.net
Fri Nov 18 15:19:41 CET 2005


Here's one I used a while back.  Returns a dict containing details per 
partition

def _getAvailPartitions():
        validTypes = [ 'ufs', 'nfs', 'reiserfs' ]

        mntTab = file( '/etc/mtab', 'r' )
        drvDetails = {}

        for mntLine in mntTab:
            splitLine = mntLine.split()
            if splitLine[2] in validTypes:
                partDesc = splitLine[1]
                mntPart = os.statvfs( partDesc )
                totalSize, totalFree = mntPart[ statvfs.F_BLOCKS ] , 
mntPart[ statvfs.F_BFREE ]
                totalInode, totalIFree = mntPart[ statvfs.F_FILES ] , 
mntPart[ statvfs.F_FFREE ]
                drvDetails[ partDesc ] = [ mntPart[ statvfs.F_FRSIZE ], 
( totalSize, totalFree ), (totalInode, totalIFree) ]

        return drvDetails


Amol Behl wrote:

>Hi i wanted to know how can i find disk size on linux platform using
>python. Also any info on how i can partition the hard disk, etc will be
>welcome thank you.
>  
>




More information about the Python-list mailing list