#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Command to build the documentation"""
__docformat__ = "restructuredtext"

import os
import sys


#{ Initialization

def prepare_project_package():
	"""Assure we are able to import the root package. If this is not the case, 
	resort to manually including the required code to set everything up"""
	ospd = os.path.dirname
	mrvpath = os.path.join(ospd(ospd(os.path.realpath(os.path.abspath(__file__)))), 'bin', 'mrv')
	globals()['__name__'] = "prevent execution of main"
	globals()['__file__'] = mrvpath
	
	try:
		execfile(mrvpath, globals())
	except Exception, e:
		raise EnvironmentError("Could not execute mrv at %r with error %s" % (mrvpath, e))
	# END exception handling
	
	prepare_project_syspath()


def makedoc_main(args):
	"""Parse args, initialize a builder, and run it"""
	prepare_project_package()
	import base
	base.DocGenerator.makedoc(args)

#} END initialization


# run the script 
if __name__ == "__main__":
	makedoc_main(sys.argv[1:])
