Tem a ver com a diferença entre correspondência contra a versão instalada de um pacote e correspondência contra qualquer versão de um pacote. De documentação :
There is a subtle, but important, distinction between matching a pattern against a package, and matching it against all the versions of that package. When a pattern is matched against a package, each of its terms is matched against the package, and so each term will match if any version of the package matches. In contrast, when a pattern is matched against each version of a package, it will successfully match if it matches when all its terms are matched against the same version of the package.
For example: suppose that version
3.0-1
of the packageaardvark
is installed, but that version4.0-1
is available. Then the search expression?version(4\.0-1)?installed
matches aardvark, because?version(4\.0-1)
matches against version4.0-1
of aardvark, while?installed
matches against version3.0-1
. On the other hand, this expression does not match against all the versions ofaardvark
, because no single version is installed and also has a version number of4.0-1
.
A documentação
para ?and
lê:
?and(pattern1, pattern2), pattern1 pattern2
Matches packages that match both pattern1 and pattern2.
Note que isto corresponde a pacotes , não versões do pacote . Então, esta consulta:
aptitude search '?and(?installed, ?origin(backports))'
procurará a interseção de pacotes instalados
e pacotes com uma origem que corresponda à expressão regular backports
.
Na verdade, é o mesmo resultado que esta consulta:
aptitude search '?installed?origin(backports)'
A documentação
para ?narrow
lê:
?narrow(filter, pattern), ~S filter pattern
This term "narrows" the search to package versions matching filter. In particular, it matches any package version which matches both filter and pattern. The string value of the match is the string value of pattern.
Observe que isso funciona em versões , não em pacotes.
Então é por isso que essa consulta mostra apenas pacotes
que são instalados com uma versão que corresponda a backports
:
aptitude search '?narrow(?installed, ?origin(backports))'
Isso também é documentado
em ?any-version
:
?any-version(pattern)
Matches a package if any one of its versions matches the enclosed pattern.
Note: This term is closely related to
?narrow
. In fact,?any-version(pattern1 pattern2)
is exactly the same as?narrow(pattern1, pattern2)
.Note: To be precise, as with any other pattern, it is not packages but versions of the packages which are matched. For
aptitude search
and other uses it does not make much difference, butaptitude versions
will only show the versions that match, not all versions of the package for which any version matches.
Assim, todas essas consultas fornecem o mesmo resultado:
aptitude versions '?and(?installed, ?origin(backports))'
aptitude versions '?installed?origin(backports)'
aptitude versions '?narrow(?installed, ?origin(backports))'
Se você encontrar a linguagem de consulta para aptitude
confusa (como eu),
você pode preferir usar uma abordagem diferente,
como as ligações do Python para libapt
.
Funciona assim:
import apt
apt_cache = apt.Cache()
for pkg in apt_cache:
if pkg.is_installed:
for pkg_origin in pkg.installed.origins:
if pkg_origin.origin == 'Debian Backports':
print(pkg.name)