

def for_each_package_specs(ns, pkg_specs, info, func, repoid=None, just_on_installed=True):
    '\n    Iterate over package specification strings, find them on remote host,\n    make them into ``LMI_SoftwareIdentity``, and pass them to given function.\n\n    :param list pkg_specs: Package specification strings.\n    :param string info: What is done with package. This is used in log messages.\n    :param callable func: Any callable taking instance of\n        ``LMI_SoftwareIdentity`` as the first and only argument.\n    :param string repoid: Optional repository id used in a search\n        for corresponding software identity.\n    :param boolean just_on_installed: Skip uninstalled software identities\n        found.\n    :returns: Pair with list containing a subset of ``pkg_specs`` with items,\n        that were processed successfuly and a list of errors for other packages.\n    :rtype: tuple\n    '
    done_on = []
    failed = []
    for pkg_spec in pkg_specs:
        if just_on_installed:
            identities = [i.to_instance() for i in software.find_package(ns, pkg_spec=pkg_spec, repoid=repoid)]
            identities = [p for p in identities if software.is_package_installed(p)]
        else:
            identities = list(software.find_package(ns, pkg_spec=pkg_spec, repoid=repoid))
        if (len(identities) < 1):
            if just_on_installed:
                msg = ('No such installed package "%s".' % pkg_spec)
            else:
                msg = ('Failed to find package "%s".' % pkg_spec)
            LOG().warn((msg + ' Skipping.'))
            failed.append(msg)
            continue
        if (len(identities) > 1):
            LOG().debug('More than one package found for "%s": %s', pkg_spec, ', '.join((software.get_package_nevra(i) for i in identities)))
        try:
            func(identities[(- 1)])
            done_on.append(pkg_spec)
        except errors.LmiFailed as err:
            failed.append(err)
    return (done_on, failed)

dataset/ETHPy150Open openlmi/openlmi-scripts/commands/software/lmi/scripts/software/cmd.py for_each_package_specs/original