human
Complete this python program:
def latest_version(*names, **kwargs):
assistant
#Here is the Python program you requested.

    """Return the latest version of the named package available for upgrade or
    installation. If more than one package name is specified, a dict of
    name/version pairs is returned.
    If the latest version of a given package is already installed, an empty
    string will be returned for that package.
    A specific repo can be requested using the ``fromrepo`` keyword argument,
    and the ``disableexcludes`` option is also supported.
    .. versionadded:: 2014.7.0
    Support for the ``disableexcludes`` option
    CLI Example:
    .. code-block:: bash
    salt \*\ pkg.latest_version <package name>
    salt \*\ pkg.latest_version <package name> fromrepo=epel-testing
    salt \*\ pkg.latest_version <package name> disableexcludes=main
    salt \*\ pkg.latest_version <package1> <package2> <package3> ...
    """
    refresh = salt.utils.is_true(kwargs.pop('refresh', True))
    if (len(names) == 0):
        return ''
    repo_arg = _get_repo_options(**kwargs)
    exclude_arg = _get_excludes_option(**kwargs)
    if refresh:
        refresh_db(**kwargs)
    cur_pkgs = list_pkgs(versions_as_list=True)
    cmd = [_yum(), '--quiet']
    cmd.extend(repo_arg)
    cmd.extend(exclude_arg)
    cmd.extend(['list', 'available'])
    cmd.extend(names)
    out = __salt__['cmd.run_all'](cmd, output_loglevel='trace', ignore_retcode=True, python_shell=False)
    if (out['retcode'] != 0):
        if out['stderr']:
            if (not all([(x in cur_pkgs) for x in names])):
                log.error('Problem    encountered    getting    latest    version    for    the    following    package(s):    %s.    Stderr    follows:    \n%s', ',    '.join(names), out['stderr'])
        updates = []
    else:
        updates = sorted(_yum_pkginfo(out['stdout']), key=(lambda pkginfo: _LooseVersion(pkginfo.version)), reverse=True)
    def _check_cur(pkg):
        if (pkg.name in cur_pkgs):
            for installed_version in cur_pkgs[pkg.name]:
                if salt.utils.compare_versions(ver1=installed_version, oper='>=', ver2=pkg.version, cmp_func=version_cmp):
                    return False
            return True
        else:
            return True
    ret = {}
    for name in names:
        try:
            arch = name.rsplit('.', 1)[(-1)]
            if (arch not in salt.utils.pkg.rpm.ARCHES):
                arch = __grains__['osarch']
        except ValueError:
            arch = __grains__['osarch']
        for pkg in (x for x in updates if (x.name == name)):
            if ((pkg.arch == 'noarch') or (pkg.arch == arch) or salt.utils.pkg.rpm.check_32(pkg.arch)):
                if _check_cur(pkg):
                    ret[name] = pkg.version
                    break
        else:
            ret[name] = ''
    if (len(names) == 1):
        return ret[names[0]]
    return ret