jztools.rentemp#

Functions

RenTempDir(target[, delete, fail])

Generates the target directory with a temporary name, and attempts to move (rename) it to the target name on exit.

RenTempFile(target[, delete, overwrite, partial])

Ensures the file is consistent (e.g., no intermediate states / partial writes) by first writing to a temporary file and then moving to the final destination.

RenTempFiles(targets, *args, **kwargs)

skip_exists()

Exceptions

RenTempDirExists(when, *args, **kwargs)

RenTempExistsException

RenTempFileExists

exception jztools.rentemp.RenTempExistsException#

Bases: Exception

exception jztools.rentemp.RenTempFileExists#

Bases: RenTempExistsException

exception jztools.rentemp.RenTempDirExists(when, *args, **kwargs)#

Bases: RenTempExistsException

jztools.rentemp.RenTempFile(target, delete=True, overwrite=False, partial=False, **file_kwargs)#

Ensures the file is consistent (e.g., no intermediate states / partial writes) by first writing to a temporary file and then moving to the final destination.

If two threads target the same destination simultaneously, there is no guarantee of which one wins.

Might leave a residual temporary file (option delete=True attempts to clean it up).

jztools.rentemp.RenTempDir(target, delete=True, fail=True)#

Generates the target directory with a temporary name, and attempts to move (rename) it to the target name on exit. If the target directory already existed, raises an RenTempDirExists exception, with when attribute indicating whether the exception was raised before or after yielding. Note that directory renaming can succeed when the target directory is.

Parameters:
  • target – Target directory name to create on exit.

  • delete – If an error occurs and a temporary target directory was created, delete it.

  • fail – If True (the default) and the target directory already existed, raise RenTempDirExists. If False, return the target directory.