%define name spyce
%define version __VERSION__
%define release __RELEASE__

%define httpd_conf /etc/httpd/conf/httpd.conf
%define httpd_conf_beginline ### BEGIN SPYCE CONFIG MARKER
%define httpd_conf_endline ### END SPYCE CONFIG MARKER
%define html_dir /var/www/html

Summary:       SPYCE - Python Server Pages, Python-based HTML scripting engine
Name:          %{name}
Version:       %{version}
Release:       %{release}
Group:         System/Servers
Packager:      Rimon Barr <rimon AT acm DOT org>
URL:           http://spyce.sourceforge.net
License:       Refer to LICENCE.TXT
BuildArchitectures: noarch
BuildRoot:     %{_builddir}/%{name}-root
#BuildRequires: python >= 2.2
Requires:      python >= 2.2
Requires:      httpd >= 2.0
Source0:       %{name}-%{version}-%{release}.tgz

%description
SPYCE is a server-side engine that supports simple and efficient Python-based
dynamic HTML generation. Those who like Python and are familiar with JSP, or
PHP, or ASP, should have a look at this engine. It allows one to generate
dynamic HTML content just as easily, using Python for the dynamic parts. Its
modular design makes it very flexible and extensible. It can also be used as a
command-line utility for HTML pre-processing.

%prep
%setup -q

%build
make all

%install
rm -rf ${RPM_BUILD_ROOT}
make DESTDIR=${RPM_BUILD_ROOT} install

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
/usr/share/spyce

%post
ln -sf /usr/share/spyce/run_spyceCmd.py /usr/bin/spyce
ln -sf /usr/share/spyce/docs /usr/share/doc/spyce
echo -n "Adding Spyce config to httpd.conf..."
cp %httpd_conf %httpd_conf.spyce-install.bak
sed -e "/%httpd_conf_beginline/,/%httpd_conf_endline/d" \
  < %httpd_conf.spyce-install.bak > %httpd_conf
echo "%httpd_conf_beginline"                                 >> %httpd_conf
cat /usr/share/spyce/spyceApache.conf | sed -e "s+XXX+/usr/share/spyce+g"                             >> %httpd_conf
echo "%httpd_conf_endline"                                   >> %httpd_conf
echo " done."
/usr/sbin/apachectl graceful

%postun
if [ $1 == 0 ]; then 
  rm -f /usr/bin/spyce
  rm -f /usr/share/doc/spyce
  rm -f %html_dir/spyce
  echo -n "Removing Spyce config from httpd.conf..."
  cp %httpd_conf %httpd_conf.spyce-uninstall.bak
  sed -e "/%httpd_conf_beginline/,/%httpd_conf_endline/d" \
    < %httpd_conf.spyce-uninstall.bak > %httpd_conf
  echo " done."
  /usr/sbin/apachectl graceful
fi
