AUTHORS:
Remove the directory SAGE_TMP.
TESTS:
This is automatically run when Sage exits, test this by running a separate session of Sage:
sage: from sage.tests.cmdline import test_executable
sage: child_SAGE_TMP, err, ret = test_executable(["sage", "-c", "print SAGE_TMP"])
sage: err, ret
('', 0)
sage: os.path.exists(child_SAGE_TMP)
False
The parent directory should exist:
sage: parent_SAGE_TMP = os.path.normpath(child_SAGE_TMP + '/..')
sage: os.path.isdir(parent_SAGE_TMP)
True
Return the next available canonical filename for a plot/graphics file.
Create and return a temporary directory in $HOME/.sage/temp/hostname/pid/
The temporary directory is deleted automatically when Sage exits.
INPUT:
OUTPUT:
The absolute path of the temporary directory created, with a trailing slash (or whatever the path separator is on your OS).
EXAMPLES:
sage: d = tmp_dir('dir_testing_', '.extension')
sage: d # random output
'/home/username/.sage/temp/hostname/7961/dir_testing_XgRu4p.extension/'
sage: os.chdir(d)
sage: _ = open('file_inside_d', 'w')
Temporary directories are unaccessible by other users:
sage: os.stat(d).st_mode & 0o077
0
Create and return a temporary file in $HOME/.sage/temp/hostname/pid/
The temporary file is deleted automatically when Sage exits.
Warning
If you need a particular file extension always use tmp_filename(ext=".foo"), this will ensure that the file does not yet exist. If you were to use tmp_filename()+".foo", then you might overwrite an existing file!
INPUT:
OUTPUT:
The absolute path of the temporary file created.
EXAMPLES:
sage: fn = tmp_filename('just_for_testing_', '.extension')
sage: fn # random
'/home/username/.sage/temp/hostname/8044/just_for_testing_tVVHsn.extension'
sage: _ = open(fn, 'w')
Temporary files are unaccessible by other users:
sage: os.stat(fn).st_mode & 0o077
0