#!/usr/bin/python

"""
lbugz: execute bugz from the git repository.

This script is primarily used to test bugz. It is a wrapper which adds
the package directory to the system path and executes bin/bugz from the
git repository passing along any arguments supplied to it.

This is based on a patch from Mike Frysinger <vapier@gentoo.org>.
"""

import os
import subprocess
import sys
 
args = sys.argv

path = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
# path = os.path.normpath(os.path.join(path, '.'))
print path

pkg = os.path.join(path, 'bugz')
script = os.path.join(path, 'bin/bugz')
if os.path.exists(pkg) and os.path.exists(script):

	if 'PYTHONPATH' in os.environ.keys():
		os.environ['PYTHONPATH'] = path + ':' + os.environ['PYTHONPATH']
	else:
		os.environ['PYTHONPATH'] = path + ':'

	args[0] = script
	subprocess.call(args)
