File python-dmidecode.spec of Package python-dmidecode

#
# spec file for package python-dmidecode
#
# Copyright (c) 2017 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 http://bugs.opensuse.org/
#


%global base_name dmidecode

%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
%{!?python_ver: %global python_ver %(%{__python} -c "import sys ; print sys.version[:3]")}

%if 0%{?fedora} || 0%{?suse_version} > 1320
%global build_py3   1
%global default_py3 1
%endif

%define pythonX %{?default_py3: python3}%{!?default_py3: python2}

Summary:        Python module to access DMI data
License:        GPL-2.0
Group:          System Environment/Libraries

Name:           python-dmidecode
Version:        3.12.2
Release:        0
Url:            https://github.com/nima/python-dmidecode
Source0:        http://src.autonomy.net.au/python-dmidecode/%{name}-%{version}.tar.gz
Patch0:         huge-memory.diff
Patch1:         gcc7-inline.patch
Patch2:         detect-lib-with-py3.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Requires:       %{pythonX}-%{base_name} = %{version}-%{release}


%description
python-dmidecode is a python extension module that uses the code-base
of the 'dmidecode' utility, and presents the data as python data
structures or as XML data using libxml2.


%package -n python2-%{base_name}
Summary: Python 3 module to access DMI data
Requires:       %{name} = %{version}-%{release}
Requires:       libxml2-python
BuildRequires:  libxml2-devel
BuildRequires:  libxml2-python
BuildRequires:  python-devel

%description -n python2-%{base_name}
python2-dmidecode is a Python extension module that uses the
code-base of the 'dmidecode' utility, and presents the data
as python data structures or as XML data using libxml2.

%if 0%{?build_py3}
%package -n python3-%{base_name}
Summary: Python 3 module to access DMI data
Requires:       %{name} = %{version}-%{release}
Requires:       python3-libxml2-python
BuildRequires:  python3-devel
BuildRequires:  python3-libxml2-python

%description -n python3-%{base_name}
python3-dmidecode is a Python 3 extension module that uses the
code-base of the 'dmidecode' utility, and presents the data
as Python 3 data structures or as XML data using libxml2.
%endif

%prep
%setup -qc
%patch0 -p0
%patch1 -p0
%patch2 -p0
mv %{name}-%{version} python2
%if 0%{?build_py3}
cp -a python{2,3}

pushd python3
sed -i 's/python2/python3/g' Makefile unit-tests/Makefile
popd
%endif

%build
pushd python2
export LDFLAGS="-Wl,-rpath=%{python_sitearch}"
make build
popd

%if 0%{?build_py3}
pushd python3
export LDFLAGS="-Wl,-rpath=%{python3_sitearch}"
make build
popd
%endif

%install
pushd python2
%{__python2} src/setup.py install --root %{buildroot} --prefix=%{_prefix}
popd

%if 0%{?build_py3}
pushd python3
%{__python3} src/setup.py install --root %{buildroot} --prefix=%{_prefix}
popd
%endif

%check
pushd python2/unit-tests
make
popd
%if 0%{?build_py3}
pushd python3/unit-tests
make
popd
%endif

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%doc python2/README python2/doc/README.upstream python2/doc/LICENSE python2/doc/AUTHORS python2/doc/AUTHORS.upstream
%{_datadir}/python-dmidecode/

%files -n python2-%{base_name}
%defattr(-,root,root,-)
%{python_sitearch}/dmidecodemod.so
%{python_sitearch}/dmidecode.py
%{python_sitearch}/dmidecode.py[co]
%if "%{python_ver}" >= "2.5"
%{python_sitearch}/*.egg-info
%endif

%if 0%{?build_py3}
%files -n python3-%{base_name}
%defattr(-,root,root,-)
%{python3_sitearch}/dmidecodemod.cpython-%{python3_version_nodots}m-*.so
%{python3_sitearch}/__pycache__/dmidecode.cpython-%{python3_version_nodots}*.py[co]
%{python3_sitearch}/dmidecode.py
%{python3_sitearch}/*.egg-info
%endif

%changelog
openSUSE Build Service is sponsored by