#!/usr/bin/env python

import os, sys

def show_uris(atoms):
	import portage
	portdb = portage.portdb
	settings = portage.config(clone=portage.settings)
	for atom in atoms:
		matches = portdb.match(atom)
		if not matches:
			continue
		if len(matches) > 1:
			matches = [portage.best(matches)]
		cpv = matches[0]
		settings.setcpv(cpv, mydb=portdb)
		useflags = settings["USE"].split()
		uris, files = portdb.getfetchlist(
			cpv, useflags=useflags, mysettings=settings)
		print " ".join(uris)

if __name__ == "__main__":
	if len(sys.argv) == 1:
		print "usage: %s <atom> [atom]..." % os.path.basename(sys.argv[0])
	else:
		show_uris(sys.argv[1:])
