1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/usr/bin/python
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id: /var/cvsroot/gentoo-src/portage/bin/pkgmerge.new,v 1.7 2004/10/04 13:56:50 vapier Exp $
import os,string,sys
sys.path = ["/usr/lib/portage/pym"]+sys.path
import portage,xpak
#beautiful directed graph functions
def dig_addnode(digraph,mykey,myprovides):
if not digraph.has_key(mykey):
if myprovides==None:
digraph[mykey]=[0,[]]
else:
digraph[mykey]=[0,[myprovides]]
digraph[myprovides][0]=digraph[myprovides][0]+1
return
digraph[mykey]=[digraph[mykey][0],digraph[mykey][1].append(myprovides)]
def dig_delnode(digraph,mykey):
if not digraph.has_key(mykey):
return
for x in digraph[mykey][1]:
digraph[x][0]=digraph[x][0]-1
del digraph[mykey]
def dig_firstzero(digraph):
for x in digraph.keys():
if digraph[x][0]==0:
return x
return None
#build our package digraph
def digraph_create(digraph,mykey,myprovides=None):
mytbz2=xpak.tbz2(bintree.getname(mykey))
mydep=mytbz2.getelements("RDEPEND")
dig_addnode(digraph,mykey,myprovides)
mycheck=roottree.depcheck(string.join(mydep," "))
if mycheck[0]==0:
print "!!! Error: RDEPEND string formatted incorrectly:",mydep
return None
for x in mycheck[1]:
mymatch=bintree.dep_bestmatch(x)
if mymatch=="":
print "!!! Error: can't resolve dependency --",x
return None
if not digraph_create(digraph,mymatch,mykey):
return None
return 1
#main program loop
myvirtuals=portage.getvirtual(portage.root)
roottree=portage.vartree(portage.root,myvirtuals)
bintree=portage.binarytree("/",myvirtuals)
pretend=0
if len(sys.argv)>=2:
if sys.argv[1]=="--pretend":
print "These are the packages that I would merge, in order:"
pretend=1
del sys.argv[1]
elif sys.argv[1]=="--help":
print "Usage: pkgmerge [--pretend] pkg1.tbz2 [pkg2.tbz2]..."
sys.exit(1)
for mypkg in sys.argv[1:]:
digraph={}
mytbz2=xpak.tbz2(mypkg)
mykey=mytbz2.getelements("CATEGORY")[0]+"/"+mypkg[:-5]
digraph_create(digraph,mykey)
while (len(digraph)):
mykey=dig_firstzero(digraph)
if not mykey:
print "!!! Error: circular dependencies"
sys.exit(1)
mytbz2=bintree.getname(mykey)
if pretend:
print mytbz2
else:
portage.pkgmerge(mytbz2)
dig_delnode(digraph,mykey)
|