%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
%define gittag #GITTAG#

Name:           willie
Version:        #VERSION#
Release:        0.#BUILD#%{gittag}%{?dist}
Summary:        Simple, lightweight and easy-to-use IRC Utility bot

License:        EFL 2.0
URL:            http://willie.dftba.net/
Source0:        %{name}-%{version}.tar

BuildArch:      noarch
BuildRequires:  python2-devel
BuildRequires:  python-sphinx
BuildRequires:  dos2unix
BuildRequires: systemd

Requires:       pytz
Requires:       python-lxml
Requires:       python-feedparser
Requires:       python-enchant
Requires:       pyOpenSSL
Requires:       python-praw
Requires:       python-backports-ssl_match_hostname

%description
Willie is a simple, lightweight, open source, easy-to-use IRC Utility bot.
It is designed to be easy to use, run and extend.

%prep
%setup -q

%build
%{__python} setup.py build
dos2unix CREDITS
cd docs/
make singlehtml
mv build/singlehtml build/api-docs
rm build/api-docs/.buildinfo


%install
%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT

mkdir -p %{buildroot}%{_prefix}/lib/tmpfiles.d
install -m 0644 contrib/%{name}.conf %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf
mkdir -p %{buildroot}/run
install -d -m 0755 %{buildroot}/run/%{name}/
mkdir -p %{buildroot}%{_sysconfdir}
install -m 0644 contrib/%{name}.cfg %{buildroot}%{_sysconfdir}/%{name}.cfg
mkdir -p %{buildroot}%{_unitdir}
install -m 0644 contrib/%{name}.service %{buildroot}%{_unitdir}/%{name}.service
mkdir -p %{buildroot}/var/log/%{name}
mkdir -p %{buildroot}/var/lib/%{name}

%files
%doc README.rst COPYING CREDITS NEWS docs/build/api-docs
%config(noreplace) %{_sysconfdir}/%{name}.cfg
%{python_sitelib}/*
%{_bindir}/willie
%dir %attr(-,%{name}, %{name})/run/%{name}/
%{_prefix}/lib/tmpfiles.d/%{name}.conf
%{_unitdir}/%{name}.service
%dir %attr(-,%{name}, %{name})/var/lib/%{name}/
%dir %attr(-,%{name}, %{name})/var/log/%{name}/


%pre
getent group %{name} >/dev/null || groupadd -r %{name}
getent passwd %{name} >/dev/null || \
useradd -r -g %{name} -d /var/lib/%{name} -s /sbin/nologin \
        -c "willie ircbot account " %{name}
exit 0

%post
%systemd_post willie.service

%preun
%systemd_preun willie.service

%postun
%systemd_postun willie.service

%changelog
* #LONGDATE# Elad Alfassa <elad@fedoraproject.org> #VERSION#0.#BUILD##GITTAG#
- Update from git
