00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2003 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 __facility__ = "Online" 00011 __abstract__ = "GLAST LAT free disk space utility functions" 00012 __author__ = "Jim Panetta <panetta@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = "10/20/2003" 00014 __version__ = "$Revision: 2.1 $" 00015 __credits__ = "SLAC" 00016 00017 import LATTE.copyright_SLAC 00018 00019 00020 import os 00021 00022 def FreeSpace(filePath=None): 00023 """ freespace(path) -> long 00024 Return the number of bytes available to the user on the file system 00025 pointed to by path.""" 00026 try: 00027 os.statvfs # doesn't fail if we're on unix 00028 except AttributeError: 00029 # Win32 implementation 00030 try: 00031 if filePath is None: filePath = 'C:/' # Root level directory 00032 import win32file 00033 return win32file.GetDiskFreeSpaceEx(filePath)[0] 00034 except Exception, e: 00035 print 'FreeSpace() exception: ', e, ' path ', filePath 00036 return long(-1) 00037 else: 00038 # Unix implementation 00039 try: 00040 if filePath is None: filePath = '.' # Current working directory 00041 import statvfs 00042 s = os.statvfs(filePath) 00043 return s[statvfs.F_BAVAIL] * long(s[statvfs.F_BSIZE]) 00044 except Exception, e: 00045 print 'FreeSpace() exception: ', e 00046 return long(-1) 00047 00048 # should never get here 00049 return long(-1) 00050 00051 00052