fsl.utils.tempdir

This module contains utilities for working with temporary files and directories. It currently contains the following functions:

tempdir

Returns a context manager which creates and returns a temporary directory, and then deletes it on exit.

mkstemp

Wrapper around tempfile.mkstemp.

fsl.utils.tempdir.tempdir(root=None, changeto=True, override=None, prefix=None, delete=True)[source]

Returns a context manager which creates and returns a temporary directory, and then deletes it on exit.

Parameters:
  • root – If provided, specifies a directroy in which to create the new temporary directory. Otherwise the system default is used (see the tempfile.mkdtemp documentation).

  • changeto – If True (the default), current working directory is set to the new temporary directory before yielding, and restored afterwards.

  • override – Don’t create a temporary directory, but use this one instead. This allows tempdir to be used as a context manager when a temporary directory already exists. Implies delete=False.

  • prefix – Create the temporary directory with a name starting with this prefix.

  • delete – If True (the default), the directory is deleted on exit. Otherwise the caller is responsible for deleting the directory.

fsl.utils.tempdir.mkstemp(*args, **kwargs)[source]

Wrapper around tempfile.mkstemp. Does the same as that function, but closes the file, and just returns the file name.