FreeSpace.py

Go to the documentation of this file.
00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2005
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__     = "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          # doesn't fail if we're on unix
00034   except AttributeError:
00035     # Win32 implementation
00036     try:
00037       if filePath is None: filePath = 'C:/'  # Root level directory
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     # Unix implementation
00045     try:
00046       if filePath is None: filePath = '.'    # Current working directory
00047       if filePath == '': filePath = '.'    # Current working directory
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   # should never get here
00056   return long(-1)
00057 
00058 
00059 

Generated on Thu Apr 27 20:52:41 2006 for LICOS L02-01-00 by doxygen 1.4.6-NO