#!/usr/bin/python -O
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-src/portage/bin/fixvirtuals,v 1.3 2004/10/11 04:01:00 jstubbs Exp $

import os,sys
sys.path = ["/usr/lib/portage/pym"]+sys.path

import portage

if portage.secpass!=2:
	print "fixvirtuals: root access required."
	sys.exit(1)

newvirts={}
myvirts=portage.grabdict("/var/cache/edb/virtuals")
myprovides=portage.db["/"]["vartree"].get_all_provides()

for myvirt in myprovides.keys():
	newvirts[myvirt]=[]
	for mycatpkg in myprovides[myvirt]:
		mysplit=portage.catpkgsplit(mycatpkg)
		pkg=mysplit[0]+"/"+mysplit[1]

		try:
			if (newvirts[myvirt].index(pkg)):
				pass
		except SystemExit, e:
			raise  # This needs to be propogated
		except:
			newvirts[myvirt].append(pkg)

portage.writedict(newvirts,"/var/cache/edb/virtuals")
