We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e36ea3e commit af2009eCopy full SHA for af2009e
feincms/management/commands/medialibrary_orphans.py
@@ -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