Skip to main content

Delete unused media files from Django project

Project description

Delete unused media files from Django project

build-status-image PyPI

Package provides management command cleanup_unused_media for Django applications.

You can remove all not used media files (files without references from any Django model with FileField or ImageField fields or their inheritances).

Installation

  1. Install django-unused-media: pip install django-unused-media

    Python 2.7, 3.6, 3.7, pypy are tested with tox.

    Django 1.8, 1.9, 1.10, 1.11, 2.0, 2.1, 2.2, 3.0 are tested with tox.

  2. Add django-unused-media to INSTALLED_APPS: python INSTALLED_APPS = ( ... 'django_unused_media', ... )

Usage

To cleanup all unused media files, run management command:

./manage.py cleanup_unused_media

By default command is running in interactive mode. List of files which are going to be removed will be displayed for confirmation. User has to confirm the action.

Options

--noinput, --no-input

Non interactive mode. Command will remove files without any confirmation from the user. Useful for scripts.

./manage.py cleanup_unused_media --noinput

-e, --exclude

To avoid operating on particular files you can use exclude option. - ``*`` as any symbol is supported. - Can use multiple options in one command.

For example, to keep .gitignore and *.png files you can use:

./manage.py cleanup_unused_media -e *.gitignore -e *.png

Also you can exclude entire folder or some files in that folder (path should be relative to settings.MEDIA_ROOT):

./manage.py cleanup_unused_media -e path/to/dir/* -e path/to/dir/my*.doc

--minimum-file-age, seconds

Default = 60 (one minute)

Minimum file age to consider for cleanup. All files younger this age will be skipped.

--remove-empty-dirs

By default script keeps empty dirs in media folder. But with this option all empty directories will be removed after cleaning process automatically.

--dry-run

Dry run without any affect on your data

--verbosity {0,1,2}, -v {0,1,2}

Verbosity level. - 0 - silent - 1 - normal output (default) - 2 - verbose output (list individual files)

Tests

At first make sure that you are in virtualenv if you use it.

Install all dependencies:

make setup

To run tests:

make test

To run static analyser:

make flake8

License

MIT licence

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-unused-media-0.2.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

django_unused_media-0.2.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file django-unused-media-0.2.0.tar.gz.

File metadata

  • Download URL: django-unused-media-0.2.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for django-unused-media-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f7e132103f4875d6e1b6690fe5efda73c5f06eb4c2fbaf420111569d7113ff63
MD5 8e857c4063e49611a889c20d7df44061
BLAKE2b-256 38b214da4fb2aea03fe3a03f1c3f653b295c2a6c60b8bb94932b47f757ab5d49

See more details on using hashes here.

File details

Details for the file django_unused_media-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_unused_media-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for django_unused_media-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86c1ba41780f529f34071f8ba89b83541dd51bc41d9c7f8ae183bcb0331dc422
MD5 978388aa11bd9024f065a24e07051e28
BLAKE2b-256 f41bccc3c50956c3830393c53773fbf7292fb688ae951241c16c7eb5ab84fafa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page