Package Ganga :: Package GPIDev :: Package Lib :: Package File :: Module FileBuffer'
[hide private]
[frames] | no frames]

Source Code for Module Ganga.GPIDev.Lib.File.FileBuffer'

 1  ################################################################################ 
 2  # Ganga Project. http://cern.ch/ganga 
 3  # 
 4  # $Id: FileBuffer.py,v 1.1 2008-07-17 16:40:53 moscicki Exp $ 
 5  ################################################################################ 
 6   
 7  import os 
8 -class FileBuffer:
9 """ FileBuffer represents a file in memory which has not been yet created. 10 This is a handy way of creating small wrapper scripts to be generated on the fly. 11 """ 12 13 # Added a subdir (see File.py for comments) - AM
14 - def __init__(self,name,contents,subdir=os.curdir,executable=0):
15 """ name is the name of the file to be created 16 contents is the text with file contents or a file-object which will be read() 17 executable indicates if a file is create()'ed with executable permissions 18 """ 19 self.name = name 20 self._contents = contents 21 self.subdir=subdir 22 self.executable=executable
23
24 - def getPathInSandbox(self):
25 """return a relative location of a file in a sandbox: subdir/name""" 26 from Ganga.Utility.files import real_basename 27 return self.subdir+os.sep+real_basename(self.name)
28
29 - def getContents(self):
30 """return a string with the contents of the file buffer""" 31 if type(self._contents) is type(''): 32 return self._contents 33 else: 34 return self._contents.read()
35
36 - def create(self,outname):
37 """create a file in a local filesystem as 'outname' """ 38 file(outname,'w').write(self.getContents()) 39 40 if self.executable: 41 from Ganga.Utility.files import chmod_executable 42 chmod_executable(outname)
43 44
45 - def isExecutable(self):
46 """ return true if a file is create()'ed with executable permissions""" 47 return self.executable
48 49 50 51 # 52 # 53 # 54 # $Log: not supported by cvs2svn $ 55 # Revision 1.5 2007/08/28 08:26:35 moscicki 56 # fixed typo 57 # 58 # Revision 1.4 2005/08/23 17:07:23 moscicki 59 # Added executable flag for FileBuffer. 60 # Added create method for File and FileBuffer. 61 # Added getPathInSandbox() method. 62 # 63 # Revision 1.3 2005/08/10 09:45:36 andrew 64 # Added a subdir to File and FileBuffer objects. Changed the writefile method 65 # in FileWorspace to use the subdirectory 66 # 67 # 68 # 69 # 70