summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/compat
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2008-09-23 05:40:19 (GMT)
committerSteven Knight <knight@baldmt.com>2008-09-23 05:40:19 (GMT)
commit8289a8bbf400a3b7e849915519da00961c8b67ad (patch)
treee162be64e5bb4a746b27d3d218c69761f2592e90 /src/engine/SCons/compat
parent01512271df6fe8590c3cd109e4a917696d104e03 (diff)
downloadSCons-8289a8bbf400a3b7e849915519da00961c8b67ad.zip
SCons-8289a8bbf400a3b7e849915519da00961c8b67ad.tar.gz
SCons-8289a8bbf400a3b7e849915519da00961c8b67ad.tar.bz2
1.5 / 2.[012] compatiblity: shutil.move() function.
Diffstat (limited to 'src/engine/SCons/compat')
-rw-r--r--src/engine/SCons/compat/__init__.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py
index 59fdc3e..9a58dc6 100644
--- a/src/engine/SCons/compat/__init__.py
+++ b/src/engine/SCons/compat/__init__.py
@@ -168,6 +168,46 @@ except AttributeError:
del shlex
import_as('_scons_shlex', 'shlex')
+
+import shutil
+try:
+ shutil.move
+except AttributeError:
+ # Pre-2.3 Python has no shutil.move() function.
+ #
+ # Cribbed from Python 2.5.
+ import os
+
+ def move(src, dst):
+ """Recursively move a file or directory to another location.
+
+ If the destination is on our current filesystem, then simply use
+ rename. Otherwise, copy src to the dst and then remove src.
+ A lot more could be done here... A look at a mv.c shows a lot of
+ the issues this implementation glosses over.
+
+ """
+ try:
+ os.rename(src, dst)
+ except OSError:
+ if os.path.isdir(src):
+ if shutil.destinsrc(src, dst):
+ raise Error, "Cannot move a directory '%s' into itself '%s'." % (src, dst)
+ shutil.copytree(src, dst, symlinks=True)
+ shutil.rmtree(src)
+ else:
+ shutil.copy2(src,dst)
+ os.unlink(src)
+ shutil.move = move
+ del move
+
+ def destinsrc(src, dst):
+ src = os.path.abspath(src)
+ return os.path.abspath(dst)[:len(src)] == src
+ shutil.destinsrc = destinsrc
+ del destinsrc
+
+
try:
import subprocess
except ImportError: