On Tuesday 24 October 2006 16:36, Brian wrote:
> def get_virtual_dep(atom):
>     """returns a resolved virtual dependency.
>     contributed by Jason Stubbs, with a little adaptation"""
>     # Thanks Jason
>     non_virtual_atom = portage.dep_virtual([atom], portage.settings)[0]
>     if atom == non_virtual_atom:
>         # atom,"is a 'new style' virtual (aka regular package)"
>         return atom
>     else:
>         # atom,"is an 'old style' virtual that resolves to:
> non_virtual_atom
>         return non_virtual_atom

This could be simplified to:

def get_virtual_dep(atom):
    """returns a resolved virtual dependency."""
    return portage.dep_virtual([atom], portage.settings)[0]

Hmm.. Actually, there is one problem here.

>>> import portage
>>> portage.dep_virtual(['virtual/mda'], portage.settings)
[['||', 'mail-mta/postfix', 'mail-filter/procmail']]

The values of portage.settings.virtuals are arranged in such a way
that the first value in a key's list is either an installed package
or the package that would be chosen (if no other package in the list
or new package PROVIDEing the virtual was brought in for other
reasons) so you'd probably be better off doing something like:

def get_virtual_dep(atom):
    """returns a resolved virtual dependency."""
    key = portage.dep_getkey(atom)
    virtuals = portage.settings.getvirtuals()
    if key in virtuals:
        return atom.replace(key, virtuals[key][0])
    else:
        return atom

Displaying all known packages for any specific virtual is also a
possibility... I'll leave it up to you on that. ;)

--
Jason Stubbs
-- 
gentoo-portage-dev@gentoo.org mailing list

Reply via email to