#! /usr/bin/python
# -*- mode: python encoding: UTF-8 -*-

'''
run:
$ waf configure
$ waf
$ waf --view

or just:
$ waf --view
'''

VERSION = '0.0.1'
APPNAME = 'the_docs'

top = '.'

import os

def options(opt):
	opt.add_option('--view', action='store_true', default=False, help='View the document')

def configure(conf):
	conf.load('tex')
	cwd = os.getcwd()
	cc = cwd + '/beamermindist/'

	conf.find_program(['okular', 'kpdf', 'xpdf', 'gnome-open'], var='VIEW', mandatory=False)

	lst = []
	for x in "themes/color themes/font themes/inner themes/outer themes/theme art".split():
		lst.append(cc+x)
	u = ":".join(lst)
	conf.env.LATEX = "; export TEXINPUTS=%s:$TEXINPUTS; export GS_OPTIONS=\"-sPAPERSIZE=a4\"; %s" % (u, conf.env.LATEX)

def build(bld) :
	bld(features='tex', type='pdflatex', source='main.tex')

	def view(ctx):
		ctx.exec_command(ctx.env.VIEW + ['build/main.pdf'])

	if bld.env.VIEW and bld.options.view:
		bld.add_post_fun(view)

