Skip to content

show_empty_media_dirs

show_empty_media_dirs

show_empty_media_dirs(self, clean: Annotated[bool, typer.Option(help=_('Print paths only so they can be piped to other commands'), is_flag=True)] = False) -> None

List empty media directories.

The storage API does not support deletion of directories but at least this way you know what can be removed.

Parameters:

Name Type Description Default
clean bool

Display the list of empty media directories with no formatting or additional text so that it can be piped to another command.

False
Source code in src/prune_media/management/commands/show_empty_media_dirs.py
@app.command()
def show_empty_media_dirs(
    self,
    clean: Annotated[  # noqa: FBT002
        bool,
        typer.Option(
            help=_("Print paths only so they can be piped to other commands"),
            is_flag=True,
        ),
    ] = False,
) -> None:
    """List empty media directories.

    The storage API does not support deletion of directories but at least this
    way you know what can be removed.

    Args:
        clean (bool): Display the list of empty media directories with no formatting or
            additional text so that it can be piped to another command.
    """
    empty_dirs = get_empty_media_directories(storage_backend=default_storage)
    if not empty_dirs:
        if not clean:
            self.echo(_("No empty media directories."))
        raise typer.Exit()
    for empty_dir in empty_dirs:
        self.echo(empty_dir)
    if not clean:
        self.echo(_(f"Found {len(empty_dirs)} empty media directories."))