00001
00002
00003
00004
00005
00006
00007
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__ = "2005/07/23 00:08:27"
00014 __updated__ = "$Date: 2006/02/08 15:14:51 $"
00015 __version__ = "$Revision: 1.6 $"
00016 __release__ = "$Name: HEAD $"
00017 __credits__ = "SLAC"
00018
00019 import LICOS.copyright_SLAC
00020
00021
00022 import os
00023
00024 def FreeSpace(filePath=None):
00025 """!\brief freespace(path) -> long.
00026
00027 Return the number of bytes available to the user on the file system
00028 pointed to by path.
00029
00030 \return Disk freespace
00031 """
00032 try:
00033 os.statvfs
00034 except AttributeError:
00035
00036 try:
00037 if filePath is None: filePath = 'C:/'
00038 import win32file
00039 return win32file.GetDiskFreeSpaceEx(filePath)[0]
00040 except Exception, e:
00041 print 'FreeSpace() exception: ', e, ' path ', filePath
00042 return long(-1)
00043 else:
00044
00045 try:
00046 if filePath is None: filePath = '.'
00047 if filePath == '': filePath = '.'
00048 import statvfs
00049 s = os.statvfs(filePath)
00050 return s[statvfs.F_BAVAIL] * long(s[statvfs.F_BSIZE])
00051 except Exception, e:
00052 print 'FreeSpace() exception: ', e
00053 return long(-1)
00054
00055
00056 return long(-1)
00057
00058
00059