Home | Trees | Indices | Help |
---|
|
1 ################################################################################ 2 # Ganga Project. http://cern.ch/ganga 3 # 4 # $Id: File.py,v 1.2 2008-09-09 14:37:16 moscicki Exp $ 5 ################################################################################ 6 7 from Ganga.GPIDev.Base import GangaObject 8 from Ganga.GPIDev.Schema import * 9 import os 10 11 from Ganga.Utility.files import expandfilename, chmod_executable, is_executable 1214 """Represent the files, both local and remote and provide an interface to transparently get access to them. 15 16 Typically in the context of job submission, the files are copied to the directory where the application 17 runs on the worker node. The 'subdir' attribute influances the destination directory. The 'subdir' feature 18 is not universally supported however and needs a review. 19 20 """ 21 _schema = Schema(Version(1,1), {'name': SimpleItem(defvalue="",doc='path to the file source'), 22 'subdir': SimpleItem(defvalue=os.curdir,doc='destination subdirectory (a relative path)'), 23 'executable': SimpleItem(defvalue=False,hidden=True,transient=True, 24 doc='specify if executable bit should be set when the file is created (internal framework use)')}) 25 _category = 'files' 26 _name = "File" 27 #added a subdirectory to the File object. The default is os.curdir, that is "." in Unix. 28 #The subdir is a relative path and will be appended to the pathname when writing out files. 29 # Therefore changing subdir to a anything starting with "/" will still end up relative 30 # to the pathname when the file is copied. 31 # 32 # There is no protection on putting the parent directory. So ".." is legal and will make 33 # the file end up in the parent directory. - AM88 89 # add File objects to the configuration scope (i.e. it will be possible to write instatiate File() objects via config file) 90 import Ganga.Utility.Config 91 Ganga.Utility.Config.config_scope['File'] = File 92 93 from Ganga.GPIDev.Base.Filters import allComponentFilters 94 95 import re 96 #regex [[PROTOCOL:][SETYPE:]..[<alfanumeric>:][/]]/filename 97 urlprefix=re.compile('^(([a-zA-Z_][\w]*:)+/?)?/') 9835 super(File, self).__init__() 36 37 if not name is None: 38 assert(type(name) is type('')) 39 self.name = name 40 41 if not subdir is None: 42 self.subdir = subdir4345 if len(args) == 1 and type(args[0]) == type(''): 46 v = args[0] 47 import os.path 48 expanded = expandfilename(v) 49 if not urlprefix.match(expanded): # if it is not already an absolute filename 50 self.name = os.path.abspath(expanded) 51 else: #bugfix #20545 52 self.name = expanded 53 else: 54 super(File,self).__construct__(args)5557 """return a relative location of a file in a sandbox: subdir/name""" 58 from Ganga.Utility.files import real_basename 59 return self.subdir+os.sep+real_basename(self.name)6062 """check if the file exists (as specified by 'name')""" 63 import os.path 64 return os.path.isfile(expandfilename(self.name))6567 """create a file in a local filesystem as 'outname', maintain 68 the original permissions """ 69 import shutil 70 71 shutil.copy(expandfilename(self.name),outname) 72 if self.executable: 73 chmod_executable(outname)7476 """Get the representation of the file. Since the a 77 SimpleStreamer uses __repr__ for persistency it is important 78 to return a valid python expression which fully reconstructs 79 the object. """ 80 81 return "File(name='%s',subdir='%s')"%(self.name,self.subdir)8284 """ return true if a file is create()'ed with executable 85 permissions, i.e. the permissions of the existing 'source' 86 file are checked""" 87 return self.executable or is_executable(expandfilename(self.name))100 if type(v) is type(''): 101 # use proxy class to enable all user conversions on the value itself 102 # but return the implementation object (not proxy) 103 return File._proxyClass(v)._impl 104 return None105 106 allComponentFilters['files'] = string_file_shortcut 107 108 ## JUNK ------------------------- 109 ## This is just a first idea and exact details how to implement such transparent access will be resolved later. 110 ## For example path resolution levels could imply: 111 ## - UNCHANGED_PATH = 0 # path 'a' is left as is 112 ## - ABSOLUTE_PATH = 1 # path 'a' is turned into '$CWD/a' 113 ## - UNIVERSAL_PATH = 2 # path 'a' is turned into 'protocol:$HOST:$CWD/a' 114 ## At GPI Level files are also represented in this way. Special filter implements the string shortcut: 115 ## object.file = 'x' is equivalent to object.file = File('x') 116 ## JUNK ------------------------- 117 118 119 # 120 # 121 # $Log: not supported by cvs2svn $ 122 # Revision 1.1 2008/07/17 16:40:53 moscicki 123 # migration of 5.0.2 to HEAD 124 # 125 # the doc and release/tools have been taken from HEAD 126 # 127 # Revision 1.15 2007/08/24 15:55:03 moscicki 128 # added executable flag to the file, ganga will set the executable mode of the app.exe file (in the sandbox only, the original file is not touched), this is to solve feature request #24452 129 # 130 # Revision 1.14 2007/01/25 16:18:21 moscicki 131 # mergefrom_Ganga-4-2-2-bugfix-branch_25Jan07 (GangaBase-4-14) 132 # 133 # Revision 1.12.2.4 2006/11/27 09:30:10 amuraru 134 # Extended the absolute paths detection in File objects 135 # 136 # Revision 1.12.2.3 2006/10/27 15:34:59 amuraru 137 # *** empty log message *** 138 # 139 # Revision 1.12.2.2 2006/10/27 15:33:59 amuraru 140 # bugs #20545 141 # 142 # Revision 1.12 2006/08/29 12:45:08 moscicki 143 # automatic conversion to absolute path 144 # 145 # Revision 1.11 2006/07/27 20:10:45 moscicki 146 # File to the configuartion symbol scope 147 # 148 # Revision 1.10 2006/02/17 14:21:32 moscicki 149 # fixed exists() method: using expanded file name 150 # 151 # Revision 1.9 2006/02/10 14:21:56 moscicki 152 # added exists() method 153 # docstring cleanup 154 # 155 # Revision 1.8 2005/08/23 17:07:23 moscicki 156 # Added executable flag for FileBuffer. 157 # Added create method for File and FileBuffer. 158 # Added getPathInSandbox() method. 159 # 160 # Revision 1.7 2005/08/10 09:45:36 andrew 161 # Added a subdir to File and FileBuffer objects. Changed the writefile method 162 # in FileWorspace to use the subdirectory 163 # 164 # 165 # 166
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Jun 25 10:35:29 2012 | http://epydoc.sourceforge.net |