def copy_to_tmp(source):
"""
Copies ``source`` to a temporary directory, and returns the copied location.
"""
tmp_dir = tempfile.mkdtemp()
# Use pathlib because os.path.basename is different depending on whether
# the path ends in a /
p = pathlib.Path(source)
new_dir = os.path.join(tmp_dir, p.name)
if os.path.isdir(source):
shutil.copytree(source, new_dir)
else:
shutil.copy2(source, new_dir)
return new_dir
评论列表
文章目录