File python-carbon.spec of Package python-carbon

#
# spec file for package python-carbon
#
# 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:           python-carbon
Version:        1.1.7
Release:        0
Summary:        Backend data caching and persistence daemon for Graphite
License:        Apache-2.0
Group:          Development/Languages/Python
URL:            http://graphite-project.github.com
Source:         https://files.pythonhosted.org/packages/source/c/carbon/carbon-%{version}.tar.gz
Source1:        carbon-cache.service
Source2:        carbon-relay.service
Source3:        carbon-aggregator.service
Source4:        carbon-tmpfiles.conf
Source99:       %{name}-rpmlintrc
Patch0:         %{name}-path.patch
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module setuptools}
BuildRequires:  python-rpm-macros
BuildRequires:  systemd
Requires:       python3-service_identity
Requires:       python3-Twisted >= 8.0
Requires:       python-whisper >= %{version}
Requires(pre):  shadow
BuildArch:      noarch
%{?systemd_requires}

%description
Twisted daemon that listens for time-series data and writes this data
out to whisper databases, relays the data or aggregates the data.
Carbon is a data collection and storage agent.

%prep
%setup -q -n carbon-%{version}
%patch0 -p1

%build
%python_build


%install
# rpmlintrc
sed -i 's|\/usr\/bin\/env python|\/usr\/bin\/python|g' lib/carbon/amqp_listener.py
sed -i 's|\/usr\/bin\/env python|\/usr\/bin\/python|g' lib/carbon/amqp_publisher.py

# setup
%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/storage
mkdir -p %{buildroot}%{_tmpfilesdir}
mkdir -p %{buildroot}%{_localstatedir}/lib/graphite

# Install example configuration files
mkdir -p %{buildroot}%{_sysconfdir}/graphite
mv %{buildroot}%{_localstatedir}/lib/graphite/conf/*.example %{buildroot}%{_sysconfdir}/graphite
#
for file in %{buildroot}%{_sysconfdir}/graphite/*.example; do
bn=$(basename $file .example)
cp $file %{buildroot}%{_sysconfdir}/graphite/$bn
done
# Create symlinks
pushd %{buildroot}%{_localstatedir}/lib/graphite/conf
for file in %{buildroot}%{_sysconfdir}/graphite/*.example; do
bn=$(basename $file .example)
ln -s %{_sysconfdir}/graphite/$bn
done
popd

# rights
chmod +x %{buildroot}%{python_sitelib}/carbon/amqp_publisher.py
chmod +x %{buildroot}%{python_sitelib}/carbon/amqp_listener.py

# move examples
mkdir -p %{buildroot}%{_defaultdocdir}/%{name}
mv %{buildroot}%{_localstatedir}/lib/graphite/examples %{buildroot}%{_defaultdocdir}/%{name}

# install systemd
install -Dp -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/carbon-cache.service
install -Dp -m 0644 %{SOURCE2} %{buildroot}%{_unitdir}/carbon-relay.service
install -Dp -m 0644 %{SOURCE3} %{buildroot}%{_unitdir}/carbon-aggregator.service
mkdir -p %{buildroot}%{_sbindir}
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rccarbon-cache
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rccarbon-relay
ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rccarbon-aggregator

# Install tmpfile
install -Dm 0644 %{SOURCE4} %{buildroot}%{_tmpfilesdir}/graphite.conf


%pre
%service_add_pre carbon-cache.service
%service_add_pre carbon-relay.service
%service_add_pre carbon-aggregator.service

%post
%service_add_post carbon-cache.service
%service_add_post carbon-relay.service
%service_add_post carbon-aggregator.service
%tmpfiles_create %{_tmpfilesdir}/graphite.conf

%preun
%service_del_preun carbon-cache.service
%service_del_preun carbon-relay.service
%service_del_preun carbon-aggregator.service

%postun
%service_del_postun carbon-cache.service
%service_del_postun carbon-relay.service
%service_del_postun carbon-aggregator.service

%files
%license LICENSE
%doc README.md
%dir %{_docdir}/python-carbon
%{_docdir}/python-carbon/examples
%dir %{_sysconfdir}/graphite
%{_sysconfdir}/graphite/*example
%config(noreplace) %{_sysconfdir}/graphite/aggregation-rules.conf
%config(noreplace) %{_sysconfdir}/graphite/blacklist.conf
%config(noreplace) %{_sysconfdir}/graphite/carbon.amqp.conf
%config(noreplace) %{_sysconfdir}/graphite/carbon.conf
%config(noreplace) %{_sysconfdir}/graphite/relay-rules.conf
%config(noreplace) %{_sysconfdir}/graphite/rewrite-rules.conf
%config(noreplace) %{_sysconfdir}/graphite/storage-aggregation.conf
%config(noreplace) %{_sysconfdir}/graphite/storage-schemas.conf
%config(noreplace) %{_sysconfdir}/graphite/whitelist.conf
%dir %{python_sitelib}/carbon
%dir %{python_sitelib}/twisted
%dir %{python_sitelib}/twisted/plugins
%{python_sitelib}/carbon/*
%{python_sitelib}/carbon/aggregator/*
%{python_sitelib}/carbon-%{version}-py%{python_version}.egg-info
%{python_sitelib}/twisted/plugins/*
%pycache_only %{python_sitelib}/carbon/__pycache__/*.pyc
%pycache_only %{python_sitelib}/carbon/aggregator/__pycache__/*.pyc
%pycache_only %{python_sitelib}/twisted/plugins/__pycache__/*.pyc

%{_unitdir}/carbon-*.service
%{_sbindir}/rccarbon-*
%{_prefix}/lib/graphite
%{_tmpfilesdir}/graphite.conf
%ghost %dir %{_rundir}/graphite
%defattr(-,wwwrun,www,-)
%dir %{_localstatedir}/log/graphite
%dir %{_localstatedir}/log/graphite/storage
%dir %{_localstatedir}/lib/graphite
%{_localstatedir}/lib/graphite

%changelog
openSUSE Build Service is sponsored by