File clustershell.spec of Package clustershell

# spec file for package clustershell
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2017 Stephane Thiell <>
# 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

%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
%{!?python2_sitelib: %global python2_sitelib %{python_sitelib}}
%{!?__python: %global __python python}
%{!?__python2: %global __python2 %{__python}}

%if 0%{?fedora} >= 22
%{!?python2_pkgversion: %global python2_pkgversion 2}
%global python2_pkgprefix python%{python2_pkgversion}
%global python2_pkgprefix python

%if 0%{?rhel}
%{!?python3_pkgversion: %global python3_pkgversion 34}
%{!?python3_pkgversion: %global python3_pkgversion 3}
%global python3_pkgprefix python%{python3_pkgversion}

# Undefined in SUSE
%{!?__python3: %global __python3 python3}
%{!?python3_shortver: %global python3_shortver %(%{__python3} -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')}

%global srcname ClusterShell

Name:           clustershell
Version:        1.8.1
Release:        0%{?dist}
Summary:        Python framework for efficient cluster administration
License:        LGPL-2.1-only
Group:          Productivity/Clustering/Computing
BuildArch:      noarch
Requires:       python2-%{name} = %{version}-%{release}
Requires:       vim
BuildRequires:  vim
Provides:       vim-clustershell = %{version}-%{release}
Obsoletes:      vim-clustershell < 1.7.81-4

ClusterShell is a set of tools and a Python library to execute commands
on cluster nodes in parallel depending on selected engine and worker
mechanisms. Advanced node sets and node groups handling methods are provided
to ease and improve the daily administration of large compute clusters or
server farms. Command line utilities like clush, clubak and nodeset (or
cluset) allow traditional shell scripts to take benefit of the features
offered by the library.

%package -n python2-%{name}
Summary:        ClusterShell module for Python 2
Group:          Productivity/Clustering/Computing
BuildRequires:  %{python2_pkgprefix}-devel
BuildRequires:  %{python2_pkgprefix}-setuptools
Requires:       %{python2_pkgprefix}-setuptools
%if 0%{?suse_version}
Requires:       %{python2_pkgprefix}-PyYAML
Requires:       PyYAML
%{?python_provide:%python_provide python2-%{name}}

%description -n python2-%{name}
ClusterShell Python 2 module and related command line tools.

%package -n %{python3_pkgprefix}-%{name}
Summary:        ClusterShell module for Python 3
Group:          Productivity/Clustering/Computing
BuildRequires:  %{python3_pkgprefix}-devel
BuildRequires:  %{python3_pkgprefix}-setuptools
Requires:       %{python3_pkgprefix}-PyYAML
Requires:       %{python3_pkgprefix}-setuptools
%{?python_provide:%python_provide %{python3_pkgprefix}-%{srcname}}

%description -n %{python3_pkgprefix}-%{name}
ClusterShell Python 3 module and related command line tools.

%setup -q -n %{srcname}-%{version}

%{__python3} build
%{__python2} build

%{__python3} install -O1 --skip-build --root %{buildroot}

pushd %{buildroot}%{_bindir}
for i in clubak cluset clush nodeset; do
  mv $i $i-%{python3_shortver}

%{__python2} install -O1 --skip-build --root %{buildroot}

# move config dir away from default setuptools /usr prefix (if rpm-building as user)
[ -d %{buildroot}/usr/etc ] && mv %{buildroot}/usr/etc %{buildroot}/%{_sysconfdir}

%if 0%{?rhel} && 0%{?rhel} <= 6
# old versions of rpm (el5 and el6) requires that a file/link exists in buildroot
# even when ghosted, but it is not installed at the end...
ln -s conf/groups.d/local.cfg %{buildroot}/%{_sysconfdir}/clustershell/groups

# man pages
install -d %{buildroot}/%{_mandir}/{man1,man5}
install -p -m 0644 doc/man/man1/clubak.1 %{buildroot}/%{_mandir}/man1/
install -p -m 0644 doc/man/man1/cluset.1 %{buildroot}/%{_mandir}/man1/
install -p -m 0644 doc/man/man1/clush.1 %{buildroot}/%{_mandir}/man1/
install -p -m 0644 doc/man/man1/nodeset.1 %{buildroot}/%{_mandir}/man1/
install -p -m 0644 doc/man/man5/clush.conf.5 %{buildroot}/%{_mandir}/man5/
install -p -m 0644 doc/man/man5/groups.conf.5 %{buildroot}/%{_mandir}/man5/

# vim addons
%if 0%{?suse_version}
%define vimdatadir %{_datadir}/vim/site
%define vimdatadir %{_datadir}/vim/vimfiles

install -d %{buildroot}/%{vimdatadir}/{ftdetect,syntax}
install -p -m 0644 doc/extras/vim/ftdetect/clustershell.vim %{buildroot}/%{vimdatadir}/ftdetect/
install -p -m 0644 doc/extras/vim/syntax/clushconf.vim %{buildroot}/%{vimdatadir}/syntax/
install -p -m 0644 doc/extras/vim/syntax/groupsconf.vim %{buildroot}/%{vimdatadir}/syntax/

%if 0%{?rhel}
rm -rf %{buildroot}

%files -n python2-%{name}
%if 0%{?rhel}

%files -n %{python3_pkgprefix}-%{name}
%if 0%{?rhel}

%if 0%{?rhel}
%doc ChangeLog COPYING.LGPLv2.1
%doc doc/examples
%doc doc/sphinx
%dir %{_sysconfdir}/clustershell
%dir %{_sysconfdir}/clustershell/groups.d
%dir %{_sysconfdir}/clustershell/groups.conf.d
%config(noreplace) %{_sysconfdir}/clustershell/clush.conf
%config(noreplace) %{_sysconfdir}/clustershell/groups.conf
%ghost %{_sysconfdir}/clustershell/groups
%config(noreplace) %{_sysconfdir}/clustershell/groups.d/local.cfg
%doc %{_sysconfdir}/clustershell/groups.conf.d/README
%doc %{_sysconfdir}/clustershell/groups.conf.d/*.conf.example
%doc %{_sysconfdir}/clustershell/groups.d/README
%doc %{_sysconfdir}/clustershell/groups.d/*.yaml.example
%doc %{_sysconfdir}/clustershell/topology.conf.example