import subprocess
import inspect
import os
import sys


def add_arguments(cmd, *args):
	for arg in args[::-1]:
		cmd.insert(1, arg)


def execute_without_jarvis(args):
	"""
	Execute the original program by patching the PATH
	environment variable
	"""
	jarvis_env = os.environ.copy()
	dirs = jarvis_env['PATH'].split(':')
	script_path = os.path.dirname(sys.argv[0])
	dir_to_exclude = os.path.abspath(script_path)
	del dirs[dirs.index(dir_to_exclude)]
	jarvis_env['PATH'] = ':'.join(dirs)
	args[0] = os.path.basename(sys.argv[0])
	subprocess.call(args, env=jarvis_env)
	sys.exit(0)
