Clean obsolete binary packages

    destructive
        Only keep minimum for reinstallation

    package_names
        Protect all versions of installed packages. Only meaningful if used
        with destructive=True

    time_limit <time>
        Don't delete distfiles files modified since <time>
        <time> is an amount of time: "1y" is "one year", "2w" is
        "two weeks", etc. Units are: y (years), m (months), w (weeks),
        d (days) and h (hours).

    exclude_file
        Path to exclusion file. Default is /etc/eclean/packages.exclude
        This is the same default eclean-pkg uses. Use None if this file
        exists and you want to ignore.

    Returns a dict containing the cleaned binary packages:

    .. code-block:: python

        {'cleaned': {<dist file>: <size>},
         'total_cleaned': <size>}

    CLI Example:

    .. code-block:: bash

        salt '*' gentoolkit.eclean_pkg destructive=True

def eclean_pkg(destructive=False, package_names=False, time_limit=0,
               exclude_file='/etc/eclean/packages.exclude'):
    '''
    Clean obsolete binary packages

    destructive
        Only keep minimum for reinstallation

    package_names
        Protect all versions of installed packages. Only meaningful if used
        with destructive=True

    time_limit <time>
        Don't delete distfiles files modified since <time>
        <time> is an amount of time: "1y" is "one year", "2w" is
        "two weeks", etc. Units are: y (years), m (months), w (weeks),
        d (days) and h (hours).

    exclude_file
        Path to exclusion file. Default is /etc/eclean/packages.exclude
        This is the same default eclean-pkg uses. Use None if this file
        exists and you want to ignore.

    Returns a dict containing the cleaned binary packages:

    .. code-block:: python

        {'cleaned': {<dist file>: <size>},
         'total_cleaned': <size>}

    CLI Example:

    .. code-block:: bash

        salt '*' gentoolkit.eclean_pkg destructive=True
    '''
    if exclude_file is None:
        exclude = None
    else:
        try:
            exclude = _parse_exclude(exclude_file)
        except excludemod.ParseExcludeFileException as e:
            ret = {e: 'Invalid exclusion file: {0}'.format(exclude_file)}
            return ret

    if time_limit != 0:
        time_limit = cli.parseTime(time_limit)

    clean_size = 0
    # findPackages requires one arg, but does nothing with it.
    # So we will just pass None in for the required arg
    clean_me = search.findPackages(None, destructive=destructive,
                                   package_names=package_names,
                                   time_limit=time_limit, exclude=exclude,
                                   pkgdir=search.pkgdir)

    cleaned = dict()

    def _eclean_progress_controller(size, key, *args):
        cleaned[key] = _pretty_size(size)
        return True

    if clean_me:
        cleaner = clean.CleanUp(_eclean_progress_controller)
        clean_size = cleaner.clean_pkgs(clean_me, search.pkgdir)

    ret = {'cleaned': cleaned,
           'total_cleaned': _pretty_size(clean_size)}
    return ret