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