#!/usr/bin/python
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/portage/bin/ebuild,v 1.12 2003/10/13 07:43:38 carpaski Exp $

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

def getroot():
	try:
		a=os.environ["ROOT"]
	except:
		return "/"
	return os.path.normpath(a+"/")

os.environ["PORTAGE_CALLER"]="ebuild"
		
if len(sys.argv)<=2:
	print "expecting two arguments."
	sys.exit(1)

import portage
import getopt

debug=0
	
opts,pargs=getopt.getopt(sys.argv[1:],'',['debug'])
for opt in opts:
	if opt[0]=='--debug':
		debug=1 

for x in pargs[1:]:
	try:
		a=portage.doebuild(pargs[0],x,getroot(),debug=debug)
	except KeyboardInterrupt:
		print "(interrupted by user -- ctrl-C?)"
		a=1
	except IOError:
		a=1
		print "ebuild: this ebuild generated output during the depend phase (bad)"
	if a:
		sys.exit(a)
