# HG changeset patch # User Jeff Hammel # Date 1321397588 28800 # Node ID fb05b7616bd8794d26c756cfcffc6383a528adeb # Parent 87c22bbcda2b9f25b97dd479b0596a89bdcc5b4b begin stubbing own copytree function :( diff -r 87c22bbcda2b -r fb05b7616bd8 fetch.py --- 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)