mirror of
https://github.com/niess/python-appimage.git
synced 2025-07-28 00:01:13 +02:00
Initial commit
This commit is contained in:
24
python_appimage/tmp.py
Normal file
24
python_appimage/tmp.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from contextlib import contextmanager as contextmanager
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from .fs import remove_tree
|
||||
from .log import debug
|
||||
|
||||
|
||||
__all__ = ['TemporaryDirectory']
|
||||
|
||||
|
||||
@contextmanager
|
||||
def TemporaryDirectory():
|
||||
'''Create a temporary directory (Python 2 wrapper)
|
||||
'''
|
||||
tmpdir = tempfile.mkdtemp(prefix='python-appimage-')
|
||||
debug('MKDIR', tmpdir)
|
||||
pwd = os.getcwd()
|
||||
os.chdir(tmpdir)
|
||||
try:
|
||||
yield tmpdir
|
||||
finally:
|
||||
os.chdir(pwd)
|
||||
remove_tree(tmpdir)
|
Reference in New Issue
Block a user