def _render_installed(package): result = "No" if software.get_backend(ns) == software.BACKEND_YUM and package.InstallDate is not None: result = package.InstallDate.datetime.strftime("%a %b %d/%Y %H:%M") elif software.get_backend(ns) == software.BACKEND_PACKAGEKIT and software.is_package_installed(package): result = "Yes" return result
def execute(self, ns, package, _repoid=None, _installed=False): def _render_installed(package): result = "No" if software.get_backend(ns) == software.BACKEND_YUM and \ package.InstallDate is not None: result = package.InstallDate.datetime.strftime( '%a %b %d/%Y %H:%M') elif software.get_backend(ns) == software.BACKEND_PACKAGEKIT and \ software.is_package_installed(package): result = "Yes" return result properties = [ 'Name', ('Arch', 'Architecture'), 'Version', 'Release', ('Summary', 'Caption'), ('Installed', _render_installed), 'Description' ] pkgs = [ p.to_instance() for p in software.find_package( ns, pkg_spec=package, repoid=_repoid) ] pkgs = [p for p in pkgs if not _installed or \ software.is_package_installed(p)] if len(pkgs) < 1: raise errors.LmiFailed('No such package "%s" found.' % package) if len(pkgs) > 1: LOG().warn('More than one package found for "%s" : %s', package, ', '.join(p.ElementName for p in pkgs)) return (properties, pkgs[-1])
def execute(self, ns, package, _repoid=None, _installed=False): def _render_installed(package): result = "No" if software.get_backend(ns) == software.BACKEND_YUM and package.InstallDate is not None: result = package.InstallDate.datetime.strftime("%a %b %d/%Y %H:%M") elif software.get_backend(ns) == software.BACKEND_PACKAGEKIT and software.is_package_installed(package): result = "Yes" return result properties = [ "Name", ("Arch", "Architecture"), "Version", "Release", ("Summary", "Caption"), ("Installed", _render_installed), "Description", ] pkgs = [p.to_instance() for p in software.find_package(ns, pkg_spec=package, repoid=_repoid)] pkgs = [p for p in pkgs if not _installed or software.is_package_installed(p)] if len(pkgs) < 1: raise errors.LmiFailed('No such package "%s" found.' % package) if len(pkgs) > 1: LOG().warn('More than one package found for "%s" : %s', package, ", ".join(p.ElementName for p in pkgs)) return (properties, pkgs[-1])
def execute(self, ns, package_array, _allow_duplicates=False, _installed=False, _available=False, _repoid=None): if _installed or _available: _installed = not _available else: _installed = None if _installed is None: yield ('NEVRA', 'Installed', 'Summary') else: yield ('NEVRA', 'Summary') for pkg_spec in package_array: for pkg in software.find_package( ns, allow_duplicates=_allow_duplicates, exact_match=False, installed=_installed, pkg_spec=pkg_spec, repoid=_repoid): inst = pkg.to_instance() nevra = software.get_package_nevra(inst) if _installed is None: yield (nevra, 'Yes' if software.is_package_installed(inst) else 'No', inst.Caption) else: yield (nevra, inst.Caption)
def _render_installed(package): result = "No" if software.get_backend(ns) == software.BACKEND_YUM and \ package.InstallDate is not None: result = package.InstallDate.datetime.strftime( '%a %b %d/%Y %H:%M') elif software.get_backend(ns) == software.BACKEND_PACKAGEKIT and \ software.is_package_installed(package): result = "Yes" return result
def for_each_package_specs(ns, pkg_specs, info, func, repoid=None, just_on_installed=True): """ Iterate over package specification strings, find them on remote host, make them into ``LMI_SoftwareIdentity``, and pass them to given function. :param list pkg_specs: Package specification strings. :param string info: What is done with package. This is used in log messages. :param callable func: Any callable taking instance of ``LMI_SoftwareIdentity`` as the first and only argument. :param string repoid: Optional repository id used in a search for corresponding software identity. :param boolean just_on_installed: Skip uninstalled software identities found. :returns: Pair with list containing a subset of ``pkg_specs`` with items, that were processed successfuly and a list of errors for other packages. :rtype: tuple """ 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
def for_each_package_specs(ns, pkg_specs, info, func, repoid=None, just_on_installed=True): """ Iterate over package specification strings, find them on remote host, make them into ``LMI_SoftwareIdentity``, and pass them to given function. :param list pkg_specs: Package specification strings. :param string info: What is done with package. This is used in log messages. :param callable func: Any callable taking instance of ``LMI_SoftwareIdentity`` as the first and only argument. :param string repoid: Optional repository id used in a search for corresponding software identity. :param boolean just_on_installed: Skip uninstalled software identities found. :returns: Pair with list containing a subset of ``pkg_specs`` with items, that were processed successfuly and a list of errors for other packages. :rtype: tuple """ 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
def execute(self, ns, package, _type=None): properties = [('Name'), ('Type', lambda i: software.FILE_TYPES[i.FileType] if i.FileExists else 'Missing'), ('FileSize', lambda i: i.FileSize), ('Passed', lambda i: len(i.FailedFlags) < 1)] if _type is not None: del properties[1] pkgs = list(p.to_instance() for p in software.find_package(ns, pkg_spec=package)) pkgs = [p for p in pkgs if software.is_package_installed(p)] if len(pkgs) < 1: raise errors.LmiFailed('No package matching "%s" found.' % package) if len(pkgs) > 1: LOG().warn('More than one package found for "%s": %s', package, ', '.join(p.ElementName for p in pkgs)) return (properties, software.list_package_files(ns, pkgs[-1], file_type=_type))
def execute(self, ns, package_array, _allow_duplicates=False, _installed=False, _available=False, _repoid=None): if _installed or _available: _installed = not _available else: _installed = None if _installed is None: yield ("NEVRA", "Installed", "Summary") else: yield ("NEVRA", "Summary") for pkg_spec in package_array: for pkg in software.find_package( ns, allow_duplicates=_allow_duplicates, exact_match=False, installed=_installed, pkg_spec=pkg_spec, repoid=_repoid, ): inst = pkg.to_instance() nevra = software.get_package_nevra(inst) if _installed is None: yield (nevra, "Yes" if software.is_package_installed(inst) else "No", inst.Caption) else: yield (nevra, inst.Caption)
def execute(self, ns, package, _type=None): properties = [ ('Name'), ('Type', lambda i: software.FILE_TYPES[i.FileType] if i.FileExists else 'Missing'), ('FileSize', lambda i: i.FileSize), ('Passed', lambda i: len(i.FailedFlags) < 1)] if _type is not None: del properties[1] pkgs = list(p.to_instance() for p in software.find_package( ns, pkg_spec=package)) pkgs = [p for p in pkgs if software.is_package_installed(p)] if len(pkgs) < 1: raise errors.LmiFailed( 'No package matching "%s" found.' % package) if len(pkgs) > 1: LOG().warn('More than one package found for "%s": %s', package, ', '.join(p.ElementName for p in pkgs)) return ( properties , software.list_package_files(ns, pkgs[-1], file_type=_type))