from django.core.management.base import BaseCommand
from django.utils.importlib import import_module
from django.conf import settings
import os
import shutil
class Command(BaseCommand):
def handle(self, *args, **options):
basedir = os.path.abspath(os.path.curdir)
for app in settings.INSTALLED_APPS:
m = import_module(app)
media_dir = os.path.join(os.path.dirname(m.__file__), 'app_media')
app_name = app.split('.')[-1]
dest_dir = os.path.join(settings.MEDIA_ROOT, app_name)
if os.path.exists(media_dir):
print "Copying %s/* to %s/" % (media_dir, dest_dir)
shutil.copytree(media_dir, dest_dir)
Comments
Good idea, but would be better handled by symlinking rather than copying. Unless you're on Windows, I guess.
#