lsst.daf.persistence 22.0.1-5-g6a31054+ce3c596283
Classes | Functions
lsst.daf.persistence.safeFileIo Namespace Reference

Classes

class  DoNotWrite
 
class  FileForWriteOnceCompareSameFailure
 
class  SafeLockedFileForWrite
 

Functions

def safeMakeDir (directory)
 
def setFileMode (filename)
 
def FileForWriteOnceCompareSame (name)
 
def SafeFile (name)
 
def SafeFilename (name)
 
def SafeLockedFileForRead (name)
 

Function Documentation

◆ FileForWriteOnceCompareSame()

def lsst.daf.persistence.safeFileIo.FileForWriteOnceCompareSame (   name)
Context manager to get a file that can be written only once and all other writes will succeed only if
they match the initial write.

The context manager provides a temporary file object. After the user is done, the temporary file becomes
the permanent file if the file at name does not already exist. If the file at name does exist the
temporary file is compared to the file at name. If they are the same then this is good and the temp file
is silently thrown away. If they are not the same then a runtime error is raised.

Definition at line 65 of file safeFileIo.py.

◆ SafeFile()

def lsst.daf.persistence.safeFileIo.SafeFile (   name)
Context manager to create a file in a manner avoiding race conditions

The context manager provides a temporary file object. After the user is done,
we move that file into the desired place and close the fd to avoid resource
leakage.

Definition at line 106 of file safeFileIo.py.

◆ SafeFilename()

def lsst.daf.persistence.safeFileIo.SafeFilename (   name)
Context manager for creating a file in a manner avoiding race conditions

The context manager provides a temporary filename with no open file descriptors
(as this can cause trouble on some systems). After the user is done, we move the
file into the desired place.

Definition at line 128 of file safeFileIo.py.

◆ SafeLockedFileForRead()

def lsst.daf.persistence.safeFileIo.SafeLockedFileForRead (   name)
Context manager for reading a file that may be locked with an exclusive lock via
SafeLockedFileForWrite. This will first acquire a shared lock before returning the file. When the file is
closed the shared lock will be unlocked.

Parameters
----------
name : string
    The file name to be opened, may include path.

Yields
------
file object
    The file to be read from.

Definition at line 148 of file safeFileIo.py.

◆ safeMakeDir()

def lsst.daf.persistence.safeFileIo.safeMakeDir (   directory)
Make a directory in a manner avoiding race conditions

Definition at line 39 of file safeFileIo.py.

◆ setFileMode()

def lsst.daf.persistence.safeFileIo.setFileMode (   filename)
Set a file mode according to the user's umask

Definition at line 50 of file safeFileIo.py.