Example #1
0
    def _search_descriptions(self, descriptions, entropy_client, entropy_repository, quiet, verbose):

        key_sorter = lambda x: entropy_repository.retrieveAtom(x)
        found = 0
        for desc in descriptions:

            pkg_ids = entropy_repository.searchDescription(desc, just_id=True)
            if not pkg_ids:
                continue

            found += len(pkg_ids)
            for pkg_id in sorted(pkg_ids, key=key_sorter):
                if quiet:
                    entropy_client.output(entropy_repository.retrieveAtom(pkg_id))
                else:
                    print_package_info(
                        pkg_id, entropy_client, entropy_repository, extended=verbose, strict_output=False, quiet=False
                    )

            if not quiet:
                toc = []
                toc.append(("%s:" % (blue(_("Keyword")),), purple(desc)))
                toc.append(
                    (
                        "%s:" % (blue(_("Found")),),
                        "%s %s" % (len(pkg_ids), brown(ngettext("entry", "entries", len(pkg_ids)))),
                    )
                )
                print_table(entropy_client, toc)

        return found
Example #2
0
    def _required(self, entropy_client, inst_repo):
        """
        Solo Query Required command.
        """
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose
        libraries = self._nsargs.libraries

        if not quiet:
            entropy_client.output(darkgreen(_("Required Packages Search")), header=darkred(" @@ "))

        key_sorter = lambda x: inst_repo.retrieveAtom(x)
        for library in libraries:
            results = inst_repo.searchNeeded(library, like=True)

            for pkg_id in sorted(results, key=key_sorter):
                print_package_info(
                    pkg_id,
                    entropy_client,
                    inst_repo,
                    installed_search=True,
                    strict_output=True,
                    extended=verbose,
                    quiet=quiet,
                )

            if not quiet:
                toc = []
                entity_str = ngettext("package", "packages", len(results))
                toc.append(("%s:" % (blue(_("Library")),), purple(library)))
                toc.append(("%s:" % (blue(_("Found")),), "%s %s" % (len(results), brown(entity_str))))
                print_table(entropy_client, toc)

        return 0
Example #3
0
    def _search_mimetype(self, entropy_client, inst_repo, associate=False):
        """
        Solo Query Mimetype command.
        """
        installed = self._nsargs.installed
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose
        settings = entropy_client.Settings()
        inst_repo_id = inst_repo.repository_id()
        if associate:
            mimetypes = self._nsargs.files
        else:
            mimetypes = self._nsargs.mimes

        if not quiet:
            entropy_client.output(darkgreen(_("Searching Mimetype")), header=darkred(" @@ "))

        found = False
        for mimetype in mimetypes:

            if associate:
                # consider mimetype a file path
                mimetype = get_file_mime(mimetype)
                if mimetype is None:
                    continue

            if not quiet:
                entropy_client.output(bold(mimetype), header=blue("  # "))

            if installed:

                matches = [(x, inst_repo_id) for x in entropy_client.search_installed_mimetype(mimetype)]
            else:
                matches = entropy_client.search_available_mimetype(mimetype)

            if matches:
                found = True

            key_sorter = lambda x: entropy_client.open_repository(x[1]).retrieveAtom(x[0])
            for pkg_id, pkg_repo in sorted(matches, key=key_sorter):
                repo = entropy_client.open_repository(pkg_repo)
                print_package_info(pkg_id, entropy_client, repo, extended=verbose, quiet=quiet)

            if not quiet:
                entry_str = ngettext("entry", "entries", len(matches))
                toc = []
                toc.append(("%s:" % (blue(_("Keyword")),), purple(mimetype)))
                toc.append(("%s:" % (blue(_("Found")),), "%s %s" % (len(matches), brown(entry_str))))
                print_table(entropy_client, toc)

        if not quiet and not found:
            entropy_client.output(darkgreen("%s." % (_("No matches"),)), header=darkred(" @@ "))

        return 0
Example #4
0
    def _license(self, entropy_client):
        """
        Solo Query License command.
        """
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose
        licenses = self._nsargs.licenses
        settings = entropy_client.Settings()

        if not quiet:
            entropy_client.output(darkgreen(_("License Search")), header=darkred(" @@ "))

        found = False
        repo_number = 0
        for repo_id in entropy_client.repositories():
            repo_number += 1
            repo_data = settings["repositories"]["available"][repo_id]

            if not quiet:
                header = (
                    const_convert_to_unicode("  #")
                    + const_convert_to_unicode(repo_number)
                    + const_convert_to_unicode(" ")
                )
                entropy_client.output("%s" % (bold(repo_data["description"]),), header=blue(header))

            repo = entropy_client.open_repository(repo_id)
            key_sorter = lambda x: repo.retrieveAtom(x)
            for mylicense in licenses:

                results = repo.searchLicense(mylicense, just_id=True)
                if not results:
                    continue

                found = True
                for pkg_id in sorted(results, key=key_sorter):
                    print_package_info(pkg_id, entropy_client, repo, extended=verbose, strict_output=quiet, quiet=quiet)

                if not quiet:
                    res_txt = ngettext("entry", "entries", len(results))
                    toc = []
                    toc.append(("%s:" % (blue(_("Keyword")),), purple(mylicense)))
                    toc.append(("%s:" % (blue(_("Found")),), "%s %s" % (len(results), brown(res_txt))))

                    print_table(entropy_client, toc)

        if not quiet and not found:
            entropy_client.output(darkgreen("%s." % (_("No matches"),)), header=darkred(" @@ "))

        return 0
Example #5
0
    def _search(self, entropy_client, inst_repo, string):
        """
        Solo Search string command.
        """
        results = self._search_string(
            entropy_client, inst_repo, string)

        for pkg_id, pkg_repo in results:
            repo = entropy_client.open_repository(pkg_repo)
            print_package_info(
                pkg_id, entropy_client, repo,
                extended = self._verbose,
                installed_search = repo is inst_repo,
                quiet = self._quiet)

        return results
Example #6
0
    def _tags(self, entropy_client):
        """
        Solo Query Tags command.
        """
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose
        tags = self._nsargs.tags
        settings = entropy_client.Settings()

        if not quiet:
            entropy_client.output(darkgreen(_("Tag Search")), header=darkred(" @@ "))

        found = False
        # search inside each available database
        repo_number = 0

        for repo_id in entropy_client.repositories():
            repo_number += 1
            repo_data = settings["repositories"]["available"][repo_id]

            if not quiet:
                header = (
                    const_convert_to_unicode("  #")
                    + const_convert_to_unicode(repo_number)
                    + const_convert_to_unicode(" ")
                )
                entropy_client.output("%s" % (bold(repo_data["description"]),), header=blue(header))

            repo = entropy_client.open_repository(repo_id)
            for tag in tags:

                results = repo.searchTaggedPackages(tag)
                key_sorter = lambda x: repo.retrieveAtom(x)
                for pkg_id in sorted(results, key=key_sorter):
                    found = True
                    print_package_info(pkg_id, entropy_client, repo, extended=verbose, strict_output=quiet, quiet=quiet)

                if not quiet:
                    toc = []
                    entity_str = ngettext("entry", "entries", len(results))
                    toc.append(("%s:" % (blue(_("Keyword")),), purple(tag)))
                    toc.append(("%s:" % (blue(_("Found")),), "%s %s" % (len(results), brown(entity_str))))
                    print_table(entropy_client, toc)

        if not quiet and not found:
            entropy_client.output(darkgreen("%s." % (_("No matches"),)), header=darkred(" @@ "))
        return 0
Example #7
0
    def _search(self, entropy_client, string):
        """
        Solo Search string command.
        """
        results = self._search_string(
            entropy_client, string)

        inst_repo = entropy_client.installed_repository()
        inst_repo_class = inst_repo.__class__
        for pkg_id, pkg_repo in results:
            dbconn = entropy_client.open_repository(pkg_repo)
            from_client = isinstance(dbconn, inst_repo_class)
            print_package_info(
                pkg_id, entropy_client, dbconn,
                extended = self._verbose,
                installed_search = from_client,
                quiet = self._quiet)

        return results
Example #8
0
    def _match(self, entropy_client, inst_repo, string):
        """
        Solo Search string command.
        """
        results = self._match_string(entropy_client, inst_repo, string)

        for pkg_id, pkg_repo in results:
            repo = entropy_client.open_repository(pkg_repo)

            print_package_info(
                pkg_id, entropy_client, repo,
                show_download_if_quiet = self._showdownload,
                show_repo_if_quiet = self._showrepo,
                show_desc_if_quiet = self._showdesc,
                show_slot_if_quiet = self._showslot,
                extended = self._verbose,
                installed_search = repo is inst_repo,
                quiet = self._quiet)

        return results
Example #9
0
    def _revisions(self, entropy_client, inst_repo):
        """
        Solo Query Revisions command.
        """
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose
        revisions = self._nsargs.revisions
        settings = entropy_client.Settings()

        if not quiet:
            entropy_client.output(darkgreen(_("Revision Search")), header=darkred(" @@ "))

        found = False
        key_sorter = lambda x: inst_repo.retrieveAtom(x)

        for revision in revisions:
            results = inst_repo.searchRevisionedPackages(revision)

            found = True
            for pkg_id in sorted(results, key=key_sorter):
                print_package_info(
                    pkg_id,
                    entropy_client,
                    inst_repo,
                    extended=verbose,
                    strict_output=quiet,
                    installed_search=True,
                    quiet=quiet,
                )

            if not quiet:
                toc = []
                entity_str = ngettext("entry", "entries", len(results))
                toc.append(("%s:" % (blue(_("Keyword")),), purple(revision)))
                toc.append(("%s:" % (blue(_("Found")),), "%s %s" % (len(results), brown(entity_str))))
                print_table(entropy_client, toc)

        if not quiet and not found:
            entropy_client.output(darkgreen("%s." % (_("No matches"),)), header=darkred(" @@ "))
        return 0
Example #10
0
    def _revdeps(self, entropy_client, inst_repo):
        """
        Solo Query Revdeps command.
        """
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose
        packages = self._nsargs.packages
        settings = entropy_client.Settings()

        if not quiet:
            entropy_client.output(darkgreen(_("Reverse Dependencies Search")), header=darkred(" @@ "))

        include_build_deps = False
        excluded_dep_types = None
        if include_build_deps:
            excluded_dep_types.append(etpConst["dependency_type_ids"]["bdepend_id"])

        for package in packages:

            repository_id = inst_repo.repository_id()
            package_id, _inst_rc = inst_repo.atomMatch(package)

            match_in_repo = False
            repo_masked = False

            if package_id == -1:
                match_in_repo = True
                package_id, repository_id = entropy_client.atom_match(package)

            if package_id == -1:
                package_id, repository_id = entropy_client.atom_match(package, mask_filter=False)
                if package_id != -1:
                    repo_masked = True

            if package_id == -1:
                continue

            repo = inst_repo
            if match_in_repo:
                repo = entropy_client.open_repository(repository_id)

            found_atom = repo.retrieveAtom(package_id)
            if repo_masked:
                package_id_masked, idmasking_reason = repo.maskFilter(package_id)

            search_results = repo.retrieveReverseDependencies(package_id, exclude_deptypes=excluded_dep_types)

            key_sorter = lambda x: repo.retrieveAtom(x)
            for pkg_id in sorted(search_results, key=key_sorter):
                print_package_info(
                    pkg_id,
                    entropy_client,
                    repo,
                    installed_search=True,
                    strict_output=quiet,
                    extended=verbose,
                    quiet=quiet,
                )

            if quiet:
                continue

            masking_reason = ""
            if repo_masked:
                masking_reason = ", %s" % (settings["pkg_masking_reasons"].get(idmasking_reason),)
            repo_masked_str = const_convert_to_unicode(repo_masked)
            mask_str = bold(repo_masked_str) + masking_reason

            toc = []
            toc.append(("%s:" % (blue(_("Keyword")),), purple(package)))
            toc.append(("%s:" % (blue(_("Matched")),), teal(found_atom)))
            toc.append(("%s:" % (blue(_("Masked")),), mask_str))

            if match_in_repo:
                where = "%s %s" % (_("from repository"), repository_id)
            else:
                where = _("from the installed packages repository")

            entry_str = ngettext("entry", "entries", len(search_results))
            toc.append(("%s:" % (blue(_("Found")),), "%s %s %s" % (len(search_results), brown(entry_str), where)))
            print_table(entropy_client, toc)

        return 0
Example #11
0
    def _belongs(self, entropy_client, inst_repo):
        """
        Solo Query Belongs command.
        """
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose
        files = self._nsargs.files

        if not quiet:
            entropy_client.output(darkgreen(_("Belong Search")), header=darkred(" @@ "))

        results = {}
        reverse_symlink_map = entropy_client.Settings()["system_rev_symlinks"]

        for xfile in files:
            outcome = results.setdefault(xfile, set())

            pkg_ids = inst_repo.searchBelongs(xfile)
            if not pkg_ids:
                # try real path if possible
                pkg_ids = inst_repo.searchBelongs(os.path.realpath(xfile))

            if not pkg_ids:
                # try using reverse symlink mapping
                for sym_dir in reverse_symlink_map:
                    if not xfile.startswith(sym_dir):
                        continue

                    for sym_child in reverse_symlink_map[sym_dir]:
                        my_file = sym_child + xfile[len(sym_dir) :]
                        pkg_ids = inst_repo.searchBelongs(my_file)
                        if pkg_ids:
                            break

            outcome.update(pkg_ids)

        key_sorter = lambda x: inst_repo.retrieveAtom(x)

        matches_found = 0

        for xfile, pkg_ids in results.items():

            matches_found += len(pkg_ids)  # can be incorrect

            for pkg_id in sorted(pkg_ids, key=key_sorter):
                if quiet:
                    atom = inst_repo.retrieveAtom(pkg_id)
                    if atom is not None:
                        entropy_client.output(atom, level="generic")
                else:
                    print_package_info(
                        pkg_id, entropy_client, inst_repo, installed_search=True, extended=verbose, quiet=quiet
                    )

            if not quiet:
                entries_txt = ngettext("entry", "entries", len(pkg_ids))
                toc = []
                toc.append(("%s:" % (blue(_("Keyword")),), purple(xfile)))
                toc.append(("%s:" % (blue(_("Found")),), "%s %s" % (len(pkg_ids), brown(entries_txt))))
                print_table(entropy_client, toc)

        return 0