Create temporary files on the same directory of target file
Change-Id: Ibfe9176ef56e5cd087dd7dc0ab6978d8e66b3845
This commit is contained in:
parent
c0b0e6c3bc
commit
1df6547155
@ -42,11 +42,12 @@ def makedirs(name, mode=0o777, exist_ok=True):
|
|||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def open_output_file(filename, mode='w', temp_dir=None, text=False):
|
def open_output_file(filename, mode='w', temp_dir=None, text=False):
|
||||||
basename = os.path.basename(filename)
|
basename = os.path.basename(filename)
|
||||||
|
dirname = os.path.dirname(filename)
|
||||||
prefix, suffix = os.path.splitext(basename)
|
prefix, suffix = os.path.splitext(basename)
|
||||||
prefix += '-'
|
prefix += '-'
|
||||||
temp_fd, temp_filename = tempfile.mkstemp(prefix=prefix,
|
temp_fd, temp_filename = tempfile.mkstemp(prefix=prefix,
|
||||||
suffix=suffix,
|
suffix=suffix,
|
||||||
dir=temp_dir,
|
dir=temp_dir or dirname,
|
||||||
text=text)
|
text=text)
|
||||||
try:
|
try:
|
||||||
with os.fdopen(temp_fd, mode) as temp_stream:
|
with os.fdopen(temp_fd, mode) as temp_stream:
|
||||||
|
Loading…
Reference in New Issue
Block a user