From 5b0182470cfc87502bf576132c41fe3052cff5a2 2013-05-22 23:40:43 From: Lance Edgar Date: 2013-05-22 23:40:43 Subject: [PATCH] Added `temp_path()` function in `files` module. --- diff --git a/rattail/files.py b/rattail/files.py index 39afb785e3c94d2c7cd54cb05f54391f464b234b..30fcadc8d104a295460427fd781c7cf55a93a0cd 100644 --- a/rattail/files.py +++ b/rattail/files.py @@ -28,9 +28,11 @@ This module contains various utility functions for use with the filesystem. """ +import os import os.path import shutil import lockfile +import tempfile from datetime import datetime import pkg_resources @@ -116,3 +118,16 @@ def resource_path(path): if not os.path.isabs(path) and ':' in path: return pkg_resources.resource_filename(*path.split(':')) return path + + +def temp_path(suffix='.tmp', prefix='rattail.', **kwargs): + """ + Returns a path for a temporary file. + + This is a convenience function which wraps ``tempfile.mkstemp()``. The + meaning of the arguments is the same. + """ + + fd, path = tempfile.mkstemp(suffix, prefix, **kwargs) + os.close(fd) + return path