Gentoo Archives: gentoo-portage-dev

From: Jason Stubbs <jstubbs@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] virtuals and dependencies dispaly
Date: Wed, 25 Oct 2006 14:59:55
Message-Id: 200610262339.59825.jstubbs@gentoo.org
In Reply to: Re: [gentoo-portage-dev] virtuals and dependencies dispaly by Brian
1 On Tuesday 24 October 2006 16:36, Brian wrote:
2 > def get_virtual_dep(atom):
3 > """returns a resolved virtual dependency.
4 > contributed by Jason Stubbs, with a little adaptation"""
5 > # Thanks Jason
6 > non_virtual_atom = portage.dep_virtual([atom], portage.settings)[0]
7 > if atom == non_virtual_atom:
8 > # atom,"is a 'new style' virtual (aka regular package)"
9 > return atom
10 > else:
11 > # atom,"is an 'old style' virtual that resolves to:
12 > non_virtual_atom
13 > return non_virtual_atom
14
15 This could be simplified to:
16
17 def get_virtual_dep(atom):
18 """returns a resolved virtual dependency."""
19 return portage.dep_virtual([atom], portage.settings)[0]
20
21 Hmm.. Actually, there is one problem here.
22
23 >>> import portage
24 >>> portage.dep_virtual(['virtual/mda'], portage.settings)
25 [['||', 'mail-mta/postfix', 'mail-filter/procmail']]
26
27 The values of portage.settings.virtuals are arranged in such a way
28 that the first value in a key's list is either an installed package
29 or the package that would be chosen (if no other package in the list
30 or new package PROVIDEing the virtual was brought in for other
31 reasons) so you'd probably be better off doing something like:
32
33 def get_virtual_dep(atom):
34 """returns a resolved virtual dependency."""
35 key = portage.dep_getkey(atom)
36 virtuals = portage.settings.getvirtuals()
37 if key in virtuals:
38 return atom.replace(key, virtuals[key][0])
39 else:
40 return atom
41
42 Displaying all known packages for any specific virtual is also a
43 possibility... I'll leave it up to you on that. ;)
44
45 --
46 Jason Stubbs
47 --
48 gentoo-portage-dev@g.o mailing list