From 3203b428288d31b1be9d27e561f83b7b50ff1c20 2013-06-08 14:57:50 From: Lance Edgar Date: 2013-06-08 14:57:50 Subject: [PATCH] Added `files.overwriting_move()` convenience function. --- diff --git a/rattail/files.py b/rattail/files.py index 30fcadc8d104a295460427fd781c7cf55a93a0cd..c7a2c735be69c9904cc3a6dffc7c79b67b8e3323 100644 --- a/rattail/files.py +++ b/rattail/files.py @@ -98,6 +98,19 @@ def locking_copy(src, dst): shutil.copy(src, dst) +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): """ Obtain a resource file path, extracting the resource and/or coercing the