From 6ff7ff09b58ab3ba55d1dfa7399d96931d977dea Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 8 Nov 2012 17:10:21 -0800 Subject: [PATCH] add files.overwriting_move() --- edbob/files.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/edbob/files.py b/edbob/files.py index 3cab3b4..f60f542 100644 --- a/edbob/files.py +++ b/edbob/files.py @@ -100,6 +100,19 @@ def count_lines(path): 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): """ Returns a resource file path. ``path`` is assumed either to be a package