File graphite-web.spec of Package graphite-web

#
# spec file for package graphite-web
#
# Copyright (c) 2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
Name:           graphite-web
Version:        1.1.7
Release:        0
Summary:        Enterprise scalable realtime graphing
License:        Apache-2.0
Group:          Development/Languages/Python
URL:            http://graphite-project.github.com
Source:         https://github.com/graphite-project/graphite-web/archive/%{version}.tar.gz
Source99:       %{name}-rpmlintrc
Source100:      README.SUSE
Patch0:         %{name}-path.patch
Patch1:         %{name}-fix_invalide_theme.patch
BuildArch:      noarch
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module setuptools}
BuildRequires:  %{python_module django >= 1.8}
BuildRequires:  %{python_module nose}
BuildRequires:  python-rpm-macros
BuildRequires:  apache2
Requires:       apache2
%if %{?suse_version} > 1500
Requires:       apache2-mod_wsgi
%else
Requires:       apache2-mod_wsgi-python3
%endif
Requires:       python-carbon >= %{version}
Requires:       python-whisper >= %{version}
Requires:       python3-cairo
Requires:       python3-cairocffi
# Requires:       python3-ceres <- optional for whisper, but does not exists in suse
Requires:       python3-django >= 1.8
Requires:       python3-django-tagging >= 0.4.6
Requires:       python3-pyparsing
Requires:       python3-pytz
Requires:       python3-scandir
Requires:       python3-simplejson
Requires:       python3-six
Requires:       python3-urllib3
Requires:       timezone
Recommends:     python3-ldap
Recommends:     python3-python-memcached
Recommends:     python3-rrdtool

%description
Graphite consists of a storage backend and a web-based visualization frontend.
Client applications send streams of numeric time-series data to the Graphite
backend (called carbon), where it gets stored in fixed-size database files
similar in design to RRD. The web frontend provides user interfaces
for visualizing this data in graphs as well as a simple URL-based API for
direct graph generation.

Graphite's design is focused on providing simple interfaces (both to users and
applications), real-time visualization, high-availability, and enterprise
scalability.

%prep
%setup -q
%patch0 -p1
%patch1 -p1
install -m644 %{SOURCE100} .
# rpmlintrc
sed -i 's|\/usr\/bin\/env python|\/usr\/bin\/python|g' check-dependencies.py
chmod +x examples/example-client.py

%build
%python_build

%install
%python_exec setup.py install --root=%{buildroot} --install-scripts=%{_prefix}/lib/graphite --install-lib=%{python_sitelib} --install-data=%{_localstatedir}/lib/graphite

# Create directories
mkdir -p %{buildroot}%{_localstatedir}/log/graphite/webapp
mkdir -p %{buildroot}%{_localstatedir}/lib/graphite/static
# for wsgi
mkdir -p %{buildroot}/srv/www/run

# empty files for graphite with correct rights
touch %{buildroot}%{_localstatedir}/log/graphite/exception.log
touch %{buildroot}%{_localstatedir}/log/graphite/info.log

# install missing manage.py, check-dependencies.py
install webapp/manage.py %{buildroot}%{_prefix}/lib/graphite/manage.py
install webapp/manage.py %{buildroot}%{_prefix}/lib/graphite/check-dependencies.py
sed -i 's|\/usr\/bin\/env python|\/usr\/bin\/python|' %{buildroot}%{_prefix}/lib/graphite/manage.py
sed -i 's|\/usr\/bin\/env python|\/usr\/bin\/python|' %{buildroot}%{_prefix}/lib/graphite/check-dependencies.py

# Install some default configurations and wsgi
mkdir -p %{buildroot}%{_sysconfdir}/graphite
mv %{buildroot}%{_localstatedir}/lib/graphite/conf/*.example %{buildroot}%{_sysconfdir}/graphite
mv %{buildroot}%{python_sitelib}/graphite/*.example %{buildroot}%{_sysconfdir}/graphite
#
for file in %{buildroot}%{_sysconfdir}/graphite/*.example; do
bn=$(basename $file .example)
cp $file %{buildroot}%{_sysconfdir}/graphite/$bn
done

# apache.conf
mkdir -p %{buildroot}%{_sysconfdir}/apache2/vhosts.d
cp -r examples/example-graphite-vhost.conf %{buildroot}%{_sysconfdir}/apache2/vhosts.d/graphite-web.conf
sed -i 's|@DJANGO_ROOT@|%{python_sitelib}\/django|g' %{buildroot}%{_sysconfdir}/apache2/vhosts.d/graphite-web.conf
sed -i 's|modules\/mod_wsgi.so|%{_libdir}\/apache2\/mod_wsgi.so|' %{buildroot}%{_sysconfdir}/apache2/vhosts.d/graphite-web.conf

# Create local_settings symlink
pushd %{buildroot}%{python_sitelib}/graphite
ln -s %{_sysconfdir}/graphite/local_settings.py
popd
pushd %{buildroot}%{_localstatedir}/lib/graphite/conf
ln -s %{_sysconfdir}/graphite/dashboard.conf
ln -s %{_sysconfdir}/graphite/graphTemplates.conf
ln -s %{_sysconfdir}/graphite/graphite.wsgi
popd

# Configure django /media/ location
sed -i 's|\/opt|\/var\/lib|' %{buildroot}%{_sysconfdir}/graphite/graphite.wsgi
sed -i 's|\/opt|\/var\/lib|' %{buildroot}%{_sysconfdir}/graphite/local_settings.py
sed -i 's|\/opt|\/var\/lib|' %{buildroot}%{_prefix}/lib/graphite/build-index.sh
# TODO: If you use prefix in wsgi. You must also adjusted graphite-web.conf
#sed -i 's|#URL_PEFIX|URL_PREIX|g' %%{buildroot}%%{_sysconfdir}/graphite/local_settings.py

chmod -x %{buildroot}%{_sysconfdir}/graphite/graphite.wsgi
chmod -x %{buildroot}%{_sysconfdir}/graphite/graphite.wsgi.example


%post
if [ $1 -eq 1 ]; then
   # random secret key
   K=$(dd if=/dev/urandom count=1 bs=64 2>/dev/null | base64 -w 0)
   sed -i 's|^#SECRET_KEY.*$|SECRET_KEY = "'$K'"|' %{_sysconfdir}/graphite/local_settings.py
   # initialize database
%if 0%{?suse_version} >= 1500
   django-admin migrate --pythonpath='%{_localstatedir}/lib/graphite/webapp' \
                        --settings=graphite.settings \
                        --run-syncdb \
                        --noinput
%else
   django-admin syncdb --pythonpath='%{_localstatedir}/lib/graphite/webapp' \
                       --settings=graphite.settings \
                       --noinput
%endif
   chown wwwrun:www %{_localstatedir}/lib/graphite/storage/graphite.db
fi

%check
nosetests

%files
%license LICENSE
%doc README.md README.SUSE check-dependencies.py docs

#%%{python_sitelib}/graphite*

%dir %{python_sitelib}/graphite
%{python_sitelib}/graphite/*
%{python_sitelib}/graphite_web-%{version}-py%{python_version}.egg-info
%pycache_only %{python_sitelib}/graphite/__pycache__/*.pyc



%dir %{_sysconfdir}/graphite
%config(noreplace) %{_sysconfdir}/apache2/vhosts.d/graphite-web.conf
%config(noreplace) %{_sysconfdir}/graphite/local_settings.py
%config(noreplace) %{_sysconfdir}/graphite/dashboard.conf
%config(noreplace) %{_sysconfdir}/graphite/graphTemplates.conf
%attr(-,wwwrun,www) %config(noreplace) %{_sysconfdir}/graphite/graphite.wsgi
%config(noreplace) %{_sysconfdir}/graphite/dashboard.conf
%attr(-,wwwrun,www) %dir /srv/www/run
%attr(-,wwwrun,www) %dir %{_localstatedir}/log/graphite
%attr(-,wwwrun,www) %dir %{_localstatedir}/log/graphite/webapp
%attr(-,wwwrun,www) %dir %{_localstatedir}/lib/graphite
%attr(-,wwwrun,www) %{_sysconfdir}/graphite/*.example
%attr(-,wwwrun,www) %{_sysconfdir}/graphite/*.conf
%attr(-,wwwrun,www) %{_localstatedir}/log/graphite/exception.log
%attr(-,wwwrun,www) %{_localstatedir}/log/graphite/info.log
%attr(-,wwwrun,www) %{_localstatedir}/lib/graphite
%{_prefix}/lib/graphite

%changelog