#!/bin/sh

ln -s /usr/bin/wps.py /usr/lib/cgi-bin/wps.py
#chmod 777 /usr/lib/python2.5/site-packages/pywps/Templates/1_0_0
#chmod 777 /usr/lib/python2.5/site-packages/pywps/Templates/1_0_0/inc

/usr/bin/env python << EOF
# compile templates
# compiling before installing is necessary, because the apache
# webserver has not the permission to create new files in the 
# python site-packages directory

import os
from htmltmpl import TemplateManager, TemplateProcessor
from distutils import sysconfig

baseDir =  os.path.join(sysconfig.get_python_lib(),
                        os.environ["DPKG_MAINTSCRIPT_PACKAGE"],'Templates')
versionDirs = ['1_0_0']

template_files = ['GetCapabilities', 'DescribeProcess','Execute']

for version in versionDirs:
    for template_file in template_files:
        print 'Compiling template '+template_file
        template_file = os.path.join(baseDir,version,
                                template_file + '.tmpl')
        template = TemplateManager().prepare(template_file)
        tproc = TemplateProcessor()
        compiled_document = tproc.process(template)
EOF

