示例#1
0
    def _search(self, args):
        """Search for simple text tags in a package object."""

        TRANS_TBL = collections.OrderedDict((
            ('name', C_('long', 'Name')),
            ('summary', C_('long', 'Summary')),
            ('description', C_('long', 'Description')),
            ('url', _('URL')),
        ))

        def _translate_attr(attr):
            try:
                return TRANS_TBL[attr]
            except:
                return attr

        def _print_section_header(exact_match, attrs, keys):
            trans_attrs = map(_translate_attr, attrs)
            # TRANSLATORS: separator used between package attributes (eg. Name & Summary & URL)
            trans_attrs_str = _(' & ').join(trans_attrs)
            if exact_match:
                # TRANSLATORS: %s  - translated package attributes,
                #              %%s - found keys (in listed attributes)
                section_text = _('%s Exactly Matched: %%s') % trans_attrs_str
            else:
                # TRANSLATORS: %s  - translated package attributes,
                #              %%s - found keys (in listed attributes)
                section_text = _('%s Matched: %%s') % trans_attrs_str
            formatted = self.base.output.fmtSection(section_text %
                                                    ", ".join(keys))
            print(ucd(formatted))

        counter = dnf.match_counter.MatchCounter()
        for arg in args:
            self._search_counted(counter, 'name', arg)
            self._search_counted(counter, 'summary', arg)

        if self.opts.all:
            for arg in args:
                self._search_counted(counter, 'description', arg)
                self._search_counted(counter, 'url', arg)
        else:
            needles = len(args)
            pkgs = list(counter.keys())
            for pkg in pkgs:
                if len(counter.matched_needles(pkg)) != needles:
                    del counter[pkg]

        used_attrs = None
        matched_needles = None
        exact_match = False
        print_section_header = False
        limit = None
        if not self.base.conf.showdupesfromrepos:
            limit = self.base.sack.query().filterm(pkg=counter.keys()).latest()
        for pkg in counter.sorted(reverse=True, limit_to=limit):
            if used_attrs != counter.matched_keys(pkg):
                used_attrs = counter.matched_keys(pkg)
                print_section_header = True
            if matched_needles != counter.matched_needles(pkg):
                matched_needles = counter.matched_needles(pkg)
                print_section_header = True
            if exact_match != (counter.matched_haystacks(pkg)
                               == matched_needles):
                exact_match = counter.matched_haystacks(pkg) == matched_needles
                print_section_header = True
            if print_section_header:
                _print_section_header(exact_match, used_attrs, matched_needles)
                print_section_header = False
            self.base.output.matchcallback(pkg, counter.matched_haystacks(pkg),
                                           args)

        if len(counter) == 0:
            logger.info(_('No matches found.'))
    libdnf.transaction.TransactionItemAction_REINSTALL,
]

# packages that got removed from the system
BACKWARD_ACTIONS = [
    libdnf.transaction.TransactionItemAction_DOWNGRADED,
    libdnf.transaction.TransactionItemAction_OBSOLETED,
    libdnf.transaction.TransactionItemAction_UPGRADED,
    libdnf.transaction.TransactionItemAction_REMOVE,
    # TODO: REINSTALLED may and may not belong here; the same NEVRA is in FORWARD_ACTIONS already
    #    libdnf.transaction.TransactionItemAction_REINSTALLED,
]

ACTIONS = {
    # TRANSLATORS: This is for a single package currently being downgraded.
    PKG_DOWNGRADE: C_('currently', 'Downgrading'),
    PKG_DOWNGRADED: _('Cleanup'),
    # TRANSLATORS: This is for a single package currently being installed.
    PKG_INSTALL: C_('currently', 'Installing'),
    PKG_OBSOLETE: _('Obsoleting'),
    PKG_OBSOLETED: _('Obsoleting'),
    # TRANSLATORS: This is for a single package currently being reinstalled.
    PKG_REINSTALL: C_('currently', 'Reinstalling'),
    PKG_REINSTALLED: _('Cleanup'),
    # TODO: 'Removing'?
    PKG_REMOVE: _('Erasing'),
    # TRANSLATORS: This is for a single package currently being upgraded.
    PKG_UPGRADE: C_('currently', 'Upgrading'),
    PKG_UPGRADED: _('Cleanup'),
    PKG_CLEANUP: _('Cleanup'),
    PKG_VERIFY: _('Verifying'),