add files.overwriting_move()

This commit is contained in:
Lance Edgar 2012-11-08 17:10:21 -08:00
parent 76e37f0e75
commit 6ff7ff09b5

View file

@ -100,6 +100,19 @@ def count_lines(path):
return lines return lines
def overwriting_move(src, dst):
"""
Convenience function which is equivalent to ``shutil.move()``, except it
will cause the destination file to be overwritten if it exists.
"""
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
if os.path.exists(dst):
os.remove(dst)
shutil.move(src, dst)
def resource_path(path): def resource_path(path):
""" """
Returns a resource file path. ``path`` is assumed either to be a package Returns a resource file path. ``path`` is assumed either to be a package