def _find_download_targets(name=None,
                           version=None,
                           pkgs=None,
                           normalize=True,
                           skip_suggestions=False,
                           ignore_epoch=False,
                           **kwargs):
    '''
    Inspect the arguments to pkg.downloaded and discover what packages need to
    be downloaded. Return a dict of packages to download.
    '''
    cur_pkgs = __salt__['pkg.list_downloaded'](**kwargs)
    if pkgs:
        to_download = _repack_pkgs(pkgs, normalize=normalize)

        if not to_download:
            # Badly-formatted SLS
            return {'name': name,
                    'changes': {},
                    'result': False,
                    'comment': 'Invalidly formatted pkgs parameter. See '
                               'minion log.'}
    else:
        if normalize:
            _normalize_name = \
                __salt__.get('pkg.normalize_name', lambda pkgname: pkgname)
            to_download = {_normalize_name(name): version}
        else:
            to_download = {name: version}

        cver = cur_pkgs.get(name, {})
        if name in to_download:
            # Package already downloaded, no need to download again
            if cver and version in cver:
                return {'name': name,
                        'changes': {},
                        'result': True,
                        'comment': 'Version {0} of package \'{1}\' is already '
                                   'downloaded'.format(version, name)}

            # if cver is not an empty string, the package is already downloaded
            elif cver and version is None:
                # The package is downloaded
                return {'name': name,
                        'changes': {},
                        'result': True,
                        'comment': 'Package {0} is already '
                                   'downloaded'.format(name)}

    version_spec = False
    if not skip_suggestions:
        try:
            problems = _preflight_check(to_download, **kwargs)
        except CommandExecutionError:
            pass
        else:
            comments = []
            if problems.get('no_suggest'):
                comments.append(
                    'The following package(s) were not found, and no '
                    'possible matches were found in the package db: '
                    '{0}'.format(
                ', '.join(sorted(problems['no_suggest']))
                    )
                )
            if problems.get('suggest'):
                for pkgname, suggestions in \
                        six.iteritems(problems['suggest']):
                    comments.append(
                        'Package \'{0}\' not found (possible matches: '
                        '{1})'.format(pkgname, ', '.join(suggestions))
                    )
            if comments:
                if len(comments) > 1:
                    comments.append('')
                return {'name': name,
                        'changes': {},
                        'result': False,
                        'comment': '. '.join(comments).rstrip()}

    # Find out which packages will be targeted in the call to pkg.download
    # Check current downloaded versions against specified versions
    targets = {}
    problems = []
    for pkgname, pkgver in six.iteritems(to_download):
        cver = cur_pkgs.get(pkgname, {})
        # Package not yet downloaded, so add to targets
        if not cver:
            targets[pkgname] = pkgver
            continue
        # No version specified but package is already downloaded
        elif cver and not pkgver:
            continue

        version_spec = True
        try:
            if not _fulfills_version_string(cver.keys(), pkgver, ignore_epoch=ignore_epoch):
                targets[pkgname] = pkgver
        except CommandExecutionError as exc:
            problems.append(exc.strerror)
            continue

    if problems:
        return {'name': name,
                'changes': {},
                'result': False,
                'comment': ' '.join(problems)}

    if not targets:
        # All specified packages are already downloaded
        msg = (
            'All specified packages{0} are already downloaded'
            .format(' (matching specified versions)' if version_spec else '')
        )
        return {'name': name,
                'changes': {},
                'result': True,
                'comment': msg}

    return targets
Inspect the arguments to pkg.downloaded and discover what packages need to
    be downloaded. Return a dict of packages to download.