def copy_tree(src,tgt, ignore_patterns=None, symlinks=False):
"""Copy the tree at src to tgt. This will first remove tgt if it
already exists."""
if verbose(1):
msgb("COPYTREE", tgt + " <- " + src)
if not os.path.exists(src):
error_msg("SRC TREE DOES NOT EXIST", src)
raise Exception
if os.path.exists(tgt):
if verbose(1):
msgb("Removing existing target tree", tgt)
shutil.rmtree(tgt, ignore_errors=True)
if verbose(1):
msgb("Copying to tree", tgt)
if ignore_patterns:
sp = shutil.ignore_patterns(ignore_patterns)
else:
sp = None
shutil.copytree(src,tgt,ignore=sp, symlinks=symlinks)
if verbose(1):
msgb("Done copying tree", tgt)
评论列表
文章目录