Creating self-deleting temp folders with python's contextmanager:
Code:
from contextlib import contextmanager
@contextmanager
def make_temp_directory():
import tempfile
import shutil
temp_dir = tempfile.mkdtemp()
yield temp_dir
shutil.rmtree(temp_dir)
Then in your plugin, you can simply do something like:
Code:
with make_temp_directory() as temp_dir:
do
stuff
with
things
in
the
temp_dir
It's not perfect, but barring any untrapped errors (or platform-specific permission problems), "temp_dir" will delete itself after completion of the with statement.