Cleans the local cache of fetched remote packages

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.clean

    jail
        Cleans the package cache in the specified jail

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.clean jail=<jail name or id>

    chroot
        Cleans the package cache in the specified chroot (ignored if ``jail``
        is specified)

    root
        Cleans the package cache in the specified root (ignored if ``jail``
        is specified)

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.clean chroot=/path/to/chroot

    clean_all
        Clean all packages from the local cache (not just those that have been
        superseded by newer versions).

        CLI Example:

        .. code-block:: bash

        salt '*' pkg.clean clean_all=True

    dryrun
        Dry-run mode. This list of changes to the local cache is always
        printed, but no changes are actually made.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.clean dryrun=True

def clean(jail=None,
          chroot=None,
          root=None,
          clean_all=False,
          dryrun=False):
    '''
    Cleans the local cache of fetched remote packages

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.clean

    jail
        Cleans the package cache in the specified jail

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.clean jail=<jail name or id>

    chroot
        Cleans the package cache in the specified chroot (ignored if ``jail``
        is specified)

    root
        Cleans the package cache in the specified root (ignored if ``jail``
        is specified)

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.clean chroot=/path/to/chroot

    clean_all
        Clean all packages from the local cache (not just those that have been
        superseded by newer versions).

        CLI Example:

        .. code-block:: bash

        salt '*' pkg.clean clean_all=True

    dryrun
        Dry-run mode. This list of changes to the local cache is always
        printed, but no changes are actually made.

        CLI Example:

        .. code-block:: bash

            salt '*' pkg.clean dryrun=True
    '''
    opts = ''
    if clean_all:
        opts += 'a'
    if dryrun:
        opts += 'n'
    else:
        opts += 'y'

    cmd = _pkg(jail, chroot, root)
    cmd.append('clean')
    if opts:
        cmd.append('-' + opts)
    return __salt__['cmd.run'](
        cmd,
        output_loglevel='trace',
        python_shell=False
    )