Queries and Subjects¶
Facilitates lookup of packages in a
Sackbased on given criteria. Query actually does not consult the information in the
Sackuntil it is evaluated. The evaluation happens either explicitly using
run()or by iterating the query, for example:
q = base.sack.query() i = q.installed() i = i.filter(name='pepper') packages = list(i) # i only gets evaluated here a = q.available() a = a.filter(name='pepper') for pkg in a: # a only gets evaluated here print(pkg.name)
Notice that none of the filtering methods mutates the state of the
Querybut produces a new object instead.
Return a new query limiting the original query to the not-installed packages, that is packages available from the repositories.
Return a new query that limits the result only to packages that can be downgrade candidates to other packages in the current set. Downgrade candidate has the same name, lower EVR and the architecture of the original and the downgrade candidate are suitable for a downgrade. Specifically, the filtering does not take any steps to establish that the downgrade candidate can actually be installed.
Return a new query that limits the result only to installed packages of same name and different version. Optional argument exclude accepts a list of package names that will be excluded from result.
Return a new query that limits the result to installed packages that are not present in any repo
Return a new query limiting the original query to the key/value pairs from kwargs. Multiple kwargs can be passed, the filter then works by applying all of them together (logical AND). Values inside of list or query are cumulative (logical OR).
Allowed keys are:
key value type value meaning arch string match against packages’ architecture downgrades boolean see
downgrades(). Defaults to
Truelimits to empty result set. Defaults to
epoch integer match against packages’ epoch. file string match against packages’ files latest boolean see
latest(). Defaults to
name string match against packages’ names release string match against packages’ releases reponame string match against packages repositories’ names version string match against packages’ versions obsoletes Query match packages that obsolete any package from query pkg Query match against packages in query pkg* list match against hawkey.Packages in list provides string match against packages’ provides provides* Hawkey.Reldep match against packages’ provides requires string match against packages’ requirements requires* Hawkey.Reldep match against packages’ requirements sourcerpm string match against packages’ source rpm upgrades boolean see
upgrades(). Defaults to
*The key can also accept a list of values with specified type.
The key name can be supplemented with a relation-specifying suffix, separated by
key suffix value type semantics eq any exact match; This is the default if no suffix is specified. glob string shell-style wildcard match gt integer the actual value is greater than specified gte integer the actual value is greater than or equal to specified lt integer the actual value is less than specified lte integer the actual value is less than or equal to specified neq any does not equal substr string the specified value is contained in the actual value
For example, the following creates a query that matches all packages containing the string “club” in its name:
q = base.sack.query().filter(name__substr="club")
Return a new query that limits the result to the installed packages only.
Return a new query that limits the result to
limithighest version of packages per package name and per architecture. In case the limit is negative number, it excludes the number of latest versions according to limit.
Return a new query that limits the result only to packages that can be upgrade candidates to at least one package in the current set. Upgrade candidate has the same name, higher EVR and the architectures of the original and the upgrade candidate package are suitable for an upgrade. Specifically, the filtering does not take any steps to establish that the upgrade candidate can actually be installed.
As explained on the DNF man page, users of the CLI are able to select packages for an operation in different formats, leaving seemingly arbitrary parts out of the spec and even using globbing characters. This class implements a common approach to parsing such input and produce a
Querylisting all packages matching the input or a
Selectorselecting a single package that best matches the input given a transaction operation.
get_best_query(sack, with_nevra=True, with_provides=True, with_filenames=True, forms=None)¶
Queryyielding packages matching the given input. The result of the returned query can be an empty set if no package matches. sack is the
Sackthat the returned query will search. with_nevra enable search by nevra, with_provides indicates whether besides package names also packages’ provides are searched for a match, and with_filenames indicates whether besides package provides also packages’ file provides are searched for a match. forms is a list of pattern forms from hawkey. Leaving the parameter to
Noneresults in using a reasonable default list of forms.
get_best_selector(sack, forms=None, obsoletes=True, reponame=None, reports=False)¶
Selectorthat will select a single best-matching package when used in a transaction operation. sack and forms have the same meaning as in
obsoletes, selector will also contain packages that obsoletes requested packages (default is True). If
reponame, the selection of available packages is limited to packages from that repo (default is False). Attribute
reportsis deprecated and not used any more. Will be removed on 2018-01-01.
Return generator for every possible nevra. Each possible nevra is represented by NEVRA class (libdnf) that has attributes name, epoch, version, release, arch. forms have the same meaning as in
Example how to use it when it is known that string could be full NEVRA or NEVR:
subject = dnf.subjet.Subject("my_nevra_string") possible_nevra = subject.get_nevra_possibilities(forms=[hawkey.FORM_NEVRA, hawkey.FORM_NEVR])
To print all possible names use:
for nevra in possible_nevra: print(nevra.name)