changeset 46:fb05b7616bd8

begin stubbing own copytree function :(
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 15 Nov 2011 14:53:08 -0800
parents 87c22bbcda2b
children 72d461e2ccbd
files fetch.py
diffstat 1 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/fetch.py	Tue Nov 15 14:30:16 2011 -0800
+++ b/fetch.py	Tue Nov 15 14:53:08 2011 -0800
@@ -19,6 +19,27 @@
         if os.path.isfile(os.path.join(dir, executable)):
             return os.path.join(dir, executable)
 
+def copytree(src, dst):
+    """
+    replacement for shutil.copytree because of this nonsense from help(shutil.copytree):
+      "The destination directory must not already exist."
+    """
+
+    # if its a file, just copy it
+    if os.path.isfile(src):
+        shutil.copy2(src, dst)
+        return
+
+    # otherwise a directory
+    assert os.path.isdir(src)
+    if os.path.exists(dst):
+        assert os.path.isdir(dst), "%s is a file, %s is a directory" % (src, dst)
+    else:
+        os.makedirs(dst)
+
+    for dirpath, dirnames, filenames in os.walk(src):
+        import pdb; pdb.set_trace()
+
 class Fetcher(object):
     """abstract base class for resource fetchers"""
 
@@ -162,7 +183,7 @@
                 assert os.path.isdir(dest), "source is a directory; destination is a file"
             else:
                 os.makedirs(dest)
-            shutil.copytree(path, dest)
+            copytree(path, dest)
         else:
             if not os.path.exists(dest):
                 directory, filename = os.path.split(dest)