File osc.spec of Package osc

#
# spec file for package osc
#
# Copyright (c) 2020 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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/
#


%if 0%{?fedora} >= 29 || 0%{?rhel} >= 8 || 0%{?suse_version} >= 1500 || 0%{?mageia} >= 8
%bcond_without python3
%else
%bcond_with    python3
%endif

%if %{with python3}
%{!?__python3: %define __python3 /usr/bin/python3}
%define __python %{__python3}
%define python_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
%define use_python python3
%else
%{!?__python: %define __python /usr/bin/python}
%{!?python_sitelib: %define python_sitelib %(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%define use_python python
%endif

%define chardet_pkg %{use_python}-chardet
%define keyring_pkg %{use_python}-keyring
%define progressbar_pkg %{use_python}-progressbar
%define setuptools_pkg %{use_python}-setuptools

%if 0%{?suse_version}
%define m2crypto_pkg %{use_python}-M2Crypto
%else
%define m2crypto_pkg %{use_python}-m2crypto
%endif

%if 0%{?fedora} || 0%{?rhel} >= 8 || 0%{?suse_version} >= 1500 || 0%{?mageia} || 0%{?debian} || 0%{?ubuntu}
%define rpmpython_pkg %{use_python}-rpm
%else
%define rpmpython_pkg rpm-%{use_python}
%endif

%define version_unconverted 0.167.2
%define osc_plugin_dir %{_prefix}/lib/osc-plugins
%define macros_file macros.osc

Name:           osc
Version:        0.167.2
Release:        0
Summary:        Open Build Service Commander
License:        GPL-2.0-or-later
%if "%{_vendor}" == "debbuild"
# For debian control metadata
Packager:       Marco Strigl <marco.strigl@suse.com>
Group:          devel
%else
Group:          Development/Tools/Other
%endif
URL:            https://github.com/openSUSE/osc
Source:         %{name}-%{version}.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?debian} || 0%{?ubuntu}
BuildRequires:  %{use_python}-dev
%else
BuildRequires:  %{use_python}-devel
%endif
BuildRequires:  %{setuptools_pkg}
BuildRequires:  diffstat
BuildRequires:  %{rpmpython_pkg}
Requires:       %{rpmpython_pkg}

%if 0%{?fedora} || 0%{?rhel} >= 6 || 0%{?suse_version} >= 1120 || 0%{?mageia} || 0%{?debian} || 0%{?ubuntu}
BuildArch:      noarch
%endif

%if 0%{?fedora} || 0%{?rhel} >= 8 || 0%{?suse_version} || 0%{?mageia} || 0%{?debian} || 0%{?ubuntu}
Recommends:     %{progressbar_pkg}
# needed for storing credentials in kwallet/gnome-keyring
Recommends:     %{keyring_pkg}
%endif

# Adapt for SUSE's unusual packaging of Python
%if 0%{?suse_version}
Requires:       %{use_python}
BuildRequires:  %{use_python}-xml
Requires:       %{use_python}-xml
%if !%{with python3} && 0%{?suse_version} < 1020
BuildRequires:  python-elementtree
Requires:       python-elementtree
%endif
%endif

%if 0%{?suse_version} > 1000
Recommends:     diffstat
Recommends:     build
Recommends:     sudo
Recommends:     powerpc32
Recommends:     ca-certificates
# These packages are needed for "osc add $URL"
Recommends:     obs-service-recompress
Recommends:     obs-service-set_version
Recommends:     obs-service-tar_scm
Recommends:     obs-service-obs_scm
Recommends:     obs-service-verify_file
Recommends:     obs-service-download_files
Recommends:     obs-service-format_spec_file
Recommends:     obs-service-source_validator
Recommends:     xdg-utils
# for osc >= 0.167.0 the newest build version is needed.
# Otherwise osc chroot might not work correctly.
Conflicts:      build < 20200106
%endif

%if 0%{?rhel} && 0%{?rhel} < 6
BuildRequires:  python-elementtree
Requires:       python-elementtree
%endif

%if 0%{?fedora} || 0%{?suse_version} >= 1500 || 0%{?mageia}
BuildRequires:  %{chardet_pkg}
Requires:       %{chardet_pkg}
%endif

%if 0%{?fedora} >= 29 || 0%{?rhel} >= 8 || 0%{?suse_version} || 0%{?mageia} || 0%{?debian} || 0%{?ubuntu}
BuildRequires:  %{m2crypto_pkg} > 0.19
Requires:       %{m2crypto_pkg} > 0.19
%else
BuildRequires:  m2crypto > 0.19
Requires:       m2crypto > 0.19
%endif

Provides:       %{use_python}-osc

%description
Commandline client for the Open Build Service.

See http://en.opensuse.org/openSUSE:OSC , as well as
http://en.opensuse.org/openSUSE:Build_Service_Tutorial for a general
introduction.

%prep
%setup -q

%build
CFLAGS="%{optflags}" %{__python} setup.py build

cat << eom > %{macros_file}
%%osc_plugin_dir %{osc_plugin_dir}
eom
echo >> %{macros_file}

%install
%{__python} setup.py install --prefix=%{_prefix} --root=%{buildroot}
perl -p -i -e 's{#!.*python}{#!%{_bindir}/%{use_python}}' osc-wrapper.py
ln -s osc-wrapper.py %{buildroot}/%{_bindir}/osc
mkdir -p %{buildroot}%{osc_plugin_dir}
mkdir -p %{buildroot}%{_localstatedir}/lib/osc-plugins
install -Dm0644 dist/complete.csh %{buildroot}%{_sysconfdir}/profile.d/osc.csh
%if 0%{?suse_version}
install -Dm0644 dist/complete.sh %{buildroot}%{_sysconfdir}/bash_completion.d/osc.sh
%else
install -Dm0644 dist/complete.sh %{buildroot}%{_sysconfdir}/profile.d/osc.sh
%endif
%if 0%{?suse_version} > 1110
install -Dm0755 dist/osc.complete %{buildroot}%{_prefix}/lib/osc/complete
%else
install -Dm0755 dist/osc.complete %{buildroot}%{_libdir}/osc/complete
%endif

install -m644 %{macros_file} -D %{buildroot}%{_sysconfdir}/rpm/%{macros_file}

%if 0%{?suse_version} >= 1500
%check
cd tests
%{use_python} suite.py
%endif

%if (0%{?rhel} && 0%{?rhel} < 6) || (0%{?suse_version} && 0%{?suse_version} < 1200)
%clean
rm -rf %{buildroot}
%endif

%files
%defattr(-,root,root,-)
%if 0%{?fedora} || 0%{?rhel} >= 7 || 0%{?suse_version} >= 1500 || 0%{?mageia}
%license COPYING
%doc AUTHORS README TODO NEWS
%else
%doc AUTHORS README TODO NEWS COPYING
%endif
%{_bindir}/osc*
%{python_sitelib}/*
%config %{_sysconfdir}/profile.d/osc.csh
%if 0%{?suse_version}
%config %{_sysconfdir}/bash_completion.d/osc.sh
%else
%config %{_sysconfdir}/profile.d/osc.sh
%endif
%config %{_sysconfdir}/rpm/%{macros_file}
%dir %{_localstatedir}/lib/osc-plugins
%{_mandir}/man1/osc.*
%if 0%{?suse_version} > 1110
%{_prefix}/lib/osc
%else
%{_libdir}/osc
%endif
%dir %{osc_plugin_dir}

%changelog
openSUSE Build Service is sponsored by