All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
python.larbatch_posix.dcache_file Class Reference

Public Member Functions

def __init__
 
def __init__
 
def __del__
 
def close
 
def flush
 
def fileno
 
def __next__
 
def read
 
def readline
 
def readlines
 
def tell
 
def truncate
 
def truncate
 
def write
 
def writelines
 

Public Attributes

 path
 
 mode
 
 local_path
 
 local_file
 

Detailed Description

Definition at line 156 of file larbatch_posix.py.

Constructor & Destructor Documentation

def python.larbatch_posix.dcache_file.__init__ (   self)

Definition at line 160 of file larbatch_posix.py.

161  def __init__(self):
162  self.path = '' # Path of file.
163  self.mode = '' # File mode.
164  self.local_path = '' # Path of local copy of file.
165  self.local_file = None # Open File object of local copy of file.
def python.larbatch_posix.dcache_file.__init__ (   self,
  path,
  mode = 'r',
  buf = -1 
)

Definition at line 168 of file larbatch_posix.py.

169  def __init__(self, path, mode='r', buf=-1):
170 
171  self.path = path
172  self.mode = mode
173  if path.startswith('/pnfs/'):
174  self.local_path = str(uuid.uuid4()) + os.path.basename(path)
175  else:
176  self.local_path = path
177 
178  # Fetch copy of file from dCache, if necessary.
179 
180  if path != self.local_path and (mode.find('r') >= 0 or mode.find('a') >= 0):
181  larbatch_utilities.ifdh_cp(path, self.local_path)
182 
183  # Open local copy of file.
184 
185  self.local_file = __builtins__['open'](self.local_path, mode, buf)
def python.larbatch_posix.dcache_file.__del__ (   self)

Definition at line 188 of file larbatch_posix.py.

189  def __del__(self):
190  self.close()

Member Function Documentation

def python.larbatch_posix.dcache_file.__next__ (   self)

Definition at line 227 of file larbatch_posix.py.

228  def __next__(self):
229  return next(self.local_file)
def python.larbatch_posix.dcache_file.close (   self)

Definition at line 193 of file larbatch_posix.py.

194  def close(self):
195 
196  if self.local_file and not self.local_file.closed:
197 
198  # Close local copy of file.
199 
200  self.local_file.close()
201 
202  # If the local path and real path are different, do some cleanups.
203 
204  if self.path != self.local_path:
205 
206  # If file was opend for writing, transfer local copy to dCache.
207 
208  if self.mode.find('w') >= 0 or self.mode.find('a') >= 0 or self.mode.find('+') >= 0:
209  larbatch_utilities.ifdh_cp(self.local_path, self.path)
210 
211  # Delete the local copy regardless of whether the file was open for
212  # reading or writing.
213 
214  os.remove(self.local_path)
def python.larbatch_posix.dcache_file.fileno (   self)

Definition at line 222 of file larbatch_posix.py.

223  def fileno(self):
224  return self.local_file.fileno()
def python.larbatch_posix.dcache_file.flush (   self)

Definition at line 217 of file larbatch_posix.py.

218  def flush(self):
219  self.local_file.flush()
def python.larbatch_posix.dcache_file.read (   self,
  size = -1 
)

Definition at line 232 of file larbatch_posix.py.

233  def read(self, size=-1):
234  return self.local_file.read(size)
def python.larbatch_posix.dcache_file.readline (   self,
  size = -1 
)

Definition at line 237 of file larbatch_posix.py.

238  def readline(self, size=-1):
239  return self.local_file.readline(size)
def python.larbatch_posix.dcache_file.readlines (   self,
  sizehint = -1 
)

Definition at line 242 of file larbatch_posix.py.

243  def readlines(self, sizehint=-1):
244  return self.local_file.readlines()
def python.larbatch_posix.dcache_file.tell (   self)

Definition at line 247 of file larbatch_posix.py.

248  def tell(self):
249  return self.local_file.tell()
def python.larbatch_posix.dcache_file.truncate (   self)

Definition at line 252 of file larbatch_posix.py.

253  def truncate(self):
254  self.local_file.truncate()
def python.larbatch_posix.dcache_file.truncate (   self,
  pos 
)

Definition at line 257 of file larbatch_posix.py.

258  def truncate(self, pos):
259  self.local_file.truncate(pos)
def python.larbatch_posix.dcache_file.write (   self,
  str 
)

Definition at line 262 of file larbatch_posix.py.

263  def write(self, str):
264  self.local_file.write(str)
def python.larbatch_posix.dcache_file.writelines (   self,
  strs 
)

Definition at line 267 of file larbatch_posix.py.

268  def writelines(self, strs):
269  self.local_file.writelines(strs)
270 
271 # Global functions.
272 
273 
274 # Open file

Member Data Documentation

python.larbatch_posix.dcache_file.local_file

Definition at line 164 of file larbatch_posix.py.

python.larbatch_posix.dcache_file.local_path

Definition at line 163 of file larbatch_posix.py.

python.larbatch_posix.dcache_file.mode

Definition at line 162 of file larbatch_posix.py.

python.larbatch_posix.dcache_file.path

Definition at line 161 of file larbatch_posix.py.


The documentation for this class was generated from the following file: