Skip to content

Commit af2009e

Browse files
committed
Simple helper for finding orphaned files from the media library
This does not happen with recent versions of FeinCMS anymore. Files of deleted media files are automatically unlinked too.
1 parent e36ea3e commit af2009e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
3+
from django.core.management.base import NoArgsCommand
4+
from django.utils.encoding import force_unicode
5+
6+
from feincms.module.medialibrary.models import MediaFile
7+
8+
9+
class Command(NoArgsCommand):
10+
help = "Prints all orphaned files in the `media/medialibrary` folder"
11+
12+
def handle_noargs(self, **options):
13+
mediafiles = list(MediaFile.objects.values_list('file', flat=True))
14+
15+
# TODO make this smarter, and take MEDIA_ROOT into account
16+
for base, dirs, files in os.walk('media/medialibrary'):
17+
for f in files:
18+
full = os.path.join(base[6:], f)
19+
if force_unicode(full) not in mediafiles:
20+
print os.path.join(base, f)

0 commit comments

Comments
 (0)