mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
23 lines
396 B
Python
23 lines
396 B
Python
import contextlib
|
|
import os
|
|
import shutil
|
|
import tempfile
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def temp_dir():
|
|
path = tempfile.mkdtemp(dir=os.environ.get('TEMP'))
|
|
try:
|
|
yield path
|
|
finally:
|
|
shutil.rmtree(path)
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def autoremoved_file(path):
|
|
try:
|
|
with open(path, 'w') as handle:
|
|
yield handle
|
|
finally:
|
|
os.unlink(path)
|