Fix for THEME_STATIC_PATHS by copying sensitively

If more than one path is defined in THEME_STATIC_PATHS, the theme's
static directory in output is deleted and replaced by the following
path's files.

Using `shutil.rmtree` to remove the entire destination tree if overwrite
is `True` assumes that we didn't want anything at all that was there. We
should recurse through the directory and their subdirs instead, leaving
things put there by the previous path where they were.

I lazily copied almost verbatim the solution for recursively copying a
diectory from http://stackoverflow.com/a/1994840.

The reason for this is patch is that without it, my plugin is broken! It
also makes my code a lot less crazy:

a83f066
This commit is contained in:
bmcorser 2013-08-21 19:57:55 +01:00
commit 9d583961e7

View file

@ -275,16 +275,24 @@ def copy(path, source, destination, destination_path=None, overwrite=False):
destination_ = os.path.abspath(
os.path.expanduser(os.path.join(destination, destination_path)))
def recurse(source, destination):
for entry in os.listdir(source):
entry_path = os.path.join(source, entry)
if os.path.isdir(entry_path):
entry_dest = os.path.join(destination, entry)
if os.path.exists(entry_dest):
if not os.path.isdir(entry_dest):
raise IOError('Failed to copy {0} a directory.'
.format(entry_dest))
recurse(entry_path, entry_dest)
else:
shutil.copytree(entry_path, entry_dest)
else:
shutil.copy(entry_path, destination)
if os.path.isdir(source_):
try:
shutil.copytree(source_, destination_)
logger.info('copying %s to %s' % (source_, destination_))
except OSError:
if overwrite:
shutil.rmtree(destination_)
shutil.copytree(source_, destination_)
logger.info('replacement of %s with %s' % (source_,
destination_))
recurse(source_, destination_)
elif os.path.isfile(source_):
dest_dir = os.path.dirname(destination_)