Note
This documentation is for OMERO 5.2. This version is now in maintenance mode and will only be updated in the event of critical bugs or security concerns. OMERO 5.3 is expected in the first quarter of 2017.
Class to be used by Working with OMERO and server components to allow a uniform creation of temporary files and folders with a best-effort guarantee of deleting the resources on exit. The manager searches three locations in order, taking the first which allows lockable write-access (See #1653):
For the user “ralph”,
from omero.util.temp_files import create_path
path = create_path("omero",".tmp")
or
import omero.util.TempFileManager
File file = TempFileManager.create_path("omero",".tmp")
both produce a file under the directory:
/tmp/omero_ralph/$PID/omero$RANDOM.tmp
where $PID is the current process id and $RANDOM is some random sequence of alphanumeric characters.
If remove_path is called on the return value of create_path, then the temporary resources will be cleaned up immediately. Otherwise, when the Java or Python process exits, they will be deleted. This is achieved in Java through Runtime#addShutdownHook(Thread) and in Python via atexit.register().
If an entire directory with a unique directory is needed, pass “true” as the “folder” argument of the create_path method:
create_path("omero", ".tmp", folder = True)
and
TempFileManager.create_path("omero", ".tmp", true);
Note
All contents of the generated directory will be deleted.
See also