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
|
||||
def open_output_file(filename, mode='w', temp_dir=None, text=False):
|
||||
basename = os.path.basename(filename)
|
||||
dirname = os.path.dirname(filename)
|
||||
prefix, suffix = os.path.splitext(basename)
|
||||
prefix += '-'
|
||||
temp_fd, temp_filename = tempfile.mkstemp(prefix=prefix,
|
||||
suffix=suffix,
|
||||
dir=temp_dir,
|
||||
dir=temp_dir or dirname,
|
||||
text=text)
|
||||
try:
|
||||
with os.fdopen(temp_fd, mode) as temp_stream:
|
||||
|
Loading…
Reference in New Issue
Block a user