def test_remove_empty_dirs_not_empty(self): self._media_create(u'sub1/sub2/sub3/notused.txt') remove_empty_dirs() expect(self._media_exists(u'sub1/sub2/sub3/notused.txt')).to_be_true() expect(self._media_exists(u'sub1/sub2/sub3')).to_be_true() expect(self._media_exists(u'sub1/sub2')).to_be_true() expect(self._media_exists(u'sub1')).to_be_true()
def test_remove_empty_dirs(self): create_file_and_write(u'sub1/sub2/sub3/notused.txt') remove_unused_media() remove_empty_dirs() expect(exists_media_path(u'sub1/sub2/sub3')).to_be_false() expect(exists_media_path(u'sub1/sub2')).to_be_false() expect(exists_media_path(u'sub1')).to_be_false()
def test_remove_empty_dirs(self): create_file_and_write('sub1/sub2/sub3/notused.txt') remove_unused_media() remove_empty_dirs() expect(exists_media_path('sub1/sub2/sub3')).to_be_false() expect(exists_media_path('sub1/sub2')).to_be_false() expect(exists_media_path('sub1')).to_be_false()
def handle(self, *args, **options): unused_media = get_unused_media(options.get('exclude') or []) if not unused_media: self.stdout.write('Nothing to delete. Exit') return if options.get('interactive'): self.stdout.write('These files will be deleted:') for f in unused_media: self.stdout.write(f) # ask user if six.moves.input( 'Are you sure you want to remove %s unused files? (Y/n)' % len(unused_media)) != 'Y': self.stdout.write('Interrupted by user. Exit.') return for f in unused_media: self.stdout.write('Remove %s' % f) os.remove(os.path.join(settings.MEDIA_ROOT, f)) remove_empty_dirs() self.stdout.write('Done. %s unused files have been removed' % len(unused_media))
def handle(self, *args, **options): exclusions = options.get('exclude', []) folders = options.get('folder', []) unused_media = get_unused_media(exclusions, folders) if not unused_media: self.stdout.write('Nothing to delete. Exit') return if options.get('interactive'): self.stdout.write('These files will be deleted:') for f in unused_media: self.stdout.write(f) # ask user if six.moves.input('Are you sure you want to remove %s unused files? (Y/n)' % len(unused_media)) != 'Y': self.stdout.write('Interrupted by user. Exit.') return for f in unused_media: self.stdout.write('Remove %s' % f) os.remove(os.path.join(settings.MEDIA_ROOT, f)) remove_empty_dirs() self.stdout.write('Done. %s unused files have been removed' % len(unused_media))
def handle(self, *args, **options): unused_media = get_unused_media(options.get('exclude') or []) if not unused_media: self.stdout.write('Nothing to delete. Exit') return if options.get('dry_run'): self._show_files_to_delete(unused_media) self.stdout.write('Dry run. Exit.') return elif options.get('interactive'): self._show_files_to_delete(unused_media) # ask user question = 'Are you sure you want to remove {} unused files? (y/N)'.format( len(unused_media)) if six.moves.input(question).upper() != 'Y': self.stdout.write('Interrupted by user. Exit.') return for f in unused_media: self.stdout.write('Remove %s' % f) os.remove(os.path.join(settings.MEDIA_ROOT, f)) if options.get('remove_empty_dirs'): remove_empty_dirs() self.stdout.write('Done. {} unused files have been removed'.format( len(unused_media)))
def test_remove_empty_dirs(self): self._media_create(u'sub1/sub2/sub3/notused.txt') remove_unused_media() remove_empty_dirs() expect(self._media_exists(u'sub1/sub2/sub3/notused.txt')).to_be_false() expect(self._media_exists(u'sub1/sub2/sub3')).to_be_false() expect(self._media_exists(u'sub1/sub2')).to_be_false() expect(self._media_exists(u'sub1')).to_be_false()