#!/usr/bin/python # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /local/data/ulm/cvs/history/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)