buildframework/helium/sf/python/pythoncore/lib/freedisk.py
changeset 628 7c4a911dc066
parent 587 85df38eb4012
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    37 """
    37 """
    38 
    38 
    39 
    39 
    40 
    40 
    41 def print_space_report(drive, space_required):
    41 def print_space_report(drive, space_required):
    42     """
    42     """ Compares the required space with current free space on the provided drive.
    43     compares the required space with current free space on the provided drive
       
    44     """
    43     """
    45     try:
    44     try:
    46         if sys.platform == "win32":
    45         if sys.platform == "win32":
    47             import win32file # pylint: disable-msg=F0401
    46             import win32file # pylint: disable=F0401
    48             free_bytes = win32file.GetDiskFreeSpaceEx(drive)[0]
    47             free_bytes = win32file.GetDiskFreeSpaceEx(drive)[0]
    49         elif 'java' in sys.platform:
    48         elif 'java' in sys.platform:
    50             import java.io # pylint: disable-msg=F0401
    49             import java.io # pylint: disable=F0401
    51             free_bytes = java.io.File(drive).getFreeSpace()
    50             free_bytes = java.io.File(drive).getFreeSpace()
    52         else:
    51         else:
    53             import os
    52             import os
    54             import statvfs
    53             import statvfs
    55             # pylint: disable-msg=E1101
    54             # pylint: disable=E1101
    56             stats = os.statvfs(drive)
    55             stats = os.statvfs(drive)
    57             free_bytes = stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAIL]
    56             free_bytes = stats[statvfs.F_BSIZE] * stats[statvfs.F_BAVAIL]
    58             
    57             
    59     except Exception, err_type:
    58     except (IOError, win32file.error), err_type:
    60         print "ERROR: Either specified drive doesn't exist or an unknown error"
    59         print "ERROR: Either specified drive doesn't exist or an unknown error"
    61         print str(err_type)
    60         print str(err_type)
    62         print HELP_STRING
    61         print HELP_STRING
    63         sys.exit(-2)
    62         sys.exit(-2)
    64 
    63 
    74         print "Not enough free space, exiting"
    73         print "Not enough free space, exiting"
    75         sys.exit(-1)
    74         sys.exit(-1)
    76 
    75 
    77     
    76     
    78 def main():
    77 def main():
    79     """
    78     """ Gets and parse options and verifies the option values.
    80     Gets and parse options and verifies the option values
       
    81     """
    79     """
    82     try:
    80     try:
    83         opts = getopt.getopt(sys.argv[1:], "hs:d:", \
    81         opts = getopt.getopt(sys.argv[1:], "hs:d:", \
    84                                    ["space=", "drive=", "help"])[0]
    82                                    ["space=", "drive=", "help"])[0]
    85     except getopt.GetoptError:
    83     except getopt.GetoptError: