File python3-mutagen.spec of Package python3-mutagen

#
# spec file for package python3-mutagen
#
# Copyright (c) 2016 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/
#


Name:           python3-mutagen
Version:        1.36.1
Release:        0
Summary:        Python module to Handle Audio Metadata
License:        GPL-2.0
Group:          Development/Libraries/Python
Url:            https://pypi.python.org/pypi/mutagen
Source:         https://files.pythonhosted.org/packages/source/m/mutagen/mutagen-%{version}.tar.gz
# PATCH-FIX-OPENSUSE fix-tests-tools-names.diff -- Undo the alternate-names of the tools when importing the modules so tests build successfully.
Patch0:         fix-tests-tools-names.diff
# PATCH-FIX-UPSTREAM fix-tests-on-BE.diff -- Fix tests in big endian systems
Patch1:         0001-id3-always-use-little-endian-order-for-utf-16-with-BOM.patch
BuildRequires:  python3-devel
BuildRequires:  python3-pytest
BuildRequires:  python3-setuptools
Requires(post):	update-alternatives
Requires(postun): update-alternatives
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch

%description
Mutagen is a Python module to handle audio metadata. It supports FLAC,
M4A, MP3, Ogg FLAC, Ogg Speex, Ogg Theora, Ogg Vorbis, True Audio, and
WavPack audio files. All versions of ID3v2 are supported, and all
standard ID3v2.4 frames are parsed. It can read Xing headers to
accurately calculate the bitrate and length of MP3s. ID3 and APEv2 tags
can be edited regardless of their audio format. It can also manipulate
Ogg streams on an individual packet/page level.

%prep
%setup -q -n mutagen-%{version}
%patch0 -p1
%patch1 -p1
# remove shebangs from library files
find mutagen/ -name "*.py" -exec sed -i -e '/^#!\s\?\/usr\/bin\/\(env\s\)\?python$/d' {} ';'

export LANG=en_US.UTF-8
for i in mid3cp mid3iconv mid3v2 moggsplit mutagen-inspect mutagen-pony; do
    j=`echo $i|tr '-' '_'`
    sed -i "s/\"${i}\"/\"${i}-%{py3_ver}\"/g" setup.py
    sed -i "s/u\"${i}\"/u\"${i}-%{py3_ver}\"/g" tests/test_tools_${j}.py
    mv tools/${i} tools/${i}-%{py3_ver}
    mv man/${i}.1 man/${i}-%{py3_ver}.1
done

%build
python3 setup.py build

%install
python3 setup.py install --root=%{buildroot} --prefix="%{_prefix}"

# Prepare for update-alternatives usage
mkdir -p %{buildroot}%{_sysconfdir}/alternatives
for p in mid3cp mid3iconv mid3v2 moggsplit mutagen-inspect mutagen-pony; do    
    ln -s -f %{_sysconfdir}/alternatives/$p %{buildroot}%{_bindir}/$p
    ln -s -f %{_sysconfdir}/alternatives/$p.1.gz %{buildroot}%{_mandir}/man1/${p}.1.gz
    # create a dummy target for /etc/alternatives/$p and /etc/alternatives/$p.1.gz
    touch %{buildroot}%{_sysconfdir}/alternatives/$p
    touch %{buildroot}%{_sysconfdir}/alternatives/$p.1.gz
done

%post
"%_sbindir/update-alternatives" \
   --install %{_bindir}/mid3cp mid3cp %{_bindir}/mid3cp-%{py3_ver} 30 \
   --slave %{_bindir}/mid3iconv mid3iconv %{_bindir}/mid3iconv-%{py3_ver} \
   --slave %{_bindir}/mid3v2 mid3v2 %{_bindir}/mid3v2-%{py3_ver} \
   --slave %{_bindir}/moggsplit moggsplit %{_bindir}/moggsplit-%{py3_ver} \
   --slave %{_bindir}/mutagen-inspect mutagen-inspect %{_bindir}/mutagen-inspect-%{py3_ver} \
   --slave %{_bindir}/mutagen-pony mutagen-pony %{_bindir}/mutagen-pony-%{py3_ver} \
   --slave %{_mandir}/man1/mid3cp.1.gz mid3cp.1.gz %{_mandir}/man1/mid3cp-%{py3_ver}.1.gz \
   --slave %{_mandir}/man1/mid3iconv.1.gz mid3iconv.1.gz %{_mandir}/man1/mid3iconv-%{py3_ver}.1.gz \
   --slave %{_mandir}/man1/mid3v2.1.gz mid3v2.1.gz %{_mandir}/man1/mid3v2-%{py3_ver}.1.gz \
   --slave %{_mandir}/man1/moggsplit.1.gz moggsplit.1.gz %{_mandir}/man1/moggsplit-%{py3_ver}.1.gz \
   --slave %{_mandir}/man1/mutagen-inspect.1.gz mutagen-inspect.1.gz %{_mandir}/man1/mutagen-inspect-%{py3_ver}.1.gz \
   --slave %{_mandir}/man1/mutagen-pony.1.gz mutagen-pony.1.gz %{_mandir}/man1/mutagen-pony-%{py3_ver}.1.gz

%postun
if [ $1 -eq 0 ] ; then
    "%_sbindir/update-alternatives" --remove mid3cp %{_bindir}/mid3cp-%{py3_ver}
fi

%check
export LANG=en_US.UTF-8
export PATH="$PATH:%{buildroot}%{_bindir}"
export PYTHONPATH="$PYTHONPATH:%{buildroot}%{python3_sitelib}"
python3 setup.py test

%files
%defattr(-, root, root, 0755)
%doc COPYING NEWS README.rst
%{_bindir}/mid3cp
%{_bindir}/mid3iconv
%{_bindir}/mid3v2
%{_bindir}/moggsplit
%{_bindir}/mutagen-inspect
%{_bindir}/mutagen-pony
%{_bindir}/mid3cp-%{py3_ver}
%{_bindir}/mid3iconv-%{py3_ver}
%{_bindir}/mid3v2-%{py3_ver}
%{_bindir}/moggsplit-%{py3_ver}
%{_bindir}/mutagen-inspect-%{py3_ver}
%{_bindir}/mutagen-pony-%{py3_ver}
%ghost %{_sysconfdir}/alternatives/mid3cp
%ghost %{_sysconfdir}/alternatives/mid3iconv
%ghost %{_sysconfdir}/alternatives/mid3v2
%ghost %{_sysconfdir}/alternatives/moggsplit
%ghost %{_sysconfdir}/alternatives/mutagen-inspect
%ghost %{_sysconfdir}/alternatives/mutagen-pony
%{_mandir}/man1/mid3cp.1.gz
%{_mandir}/man1/mid3iconv.1.gz
%{_mandir}/man1/mid3v2.1.gz
%{_mandir}/man1/moggsplit.1.gz
%{_mandir}/man1/mutagen-inspect.1.gz
%{_mandir}/man1/mutagen-pony.1.gz
%{_mandir}/man1/mid3cp-%{py3_ver}.1.gz
%{_mandir}/man1/mid3iconv-%{py3_ver}.1.gz
%{_mandir}/man1/mid3v2-%{py3_ver}.1.gz
%{_mandir}/man1/moggsplit-%{py3_ver}.1.gz
%{_mandir}/man1/mutagen-inspect-%{py3_ver}.1.gz
%{_mandir}/man1/mutagen-pony-%{py3_ver}.1.gz
%ghost %{_sysconfdir}/alternatives/mid3cp.1.gz
%ghost %{_sysconfdir}/alternatives/mid3iconv.1.gz
%ghost %{_sysconfdir}/alternatives/mid3v2.1.gz
%ghost %{_sysconfdir}/alternatives/moggsplit.1.gz
%ghost %{_sysconfdir}/alternatives/mutagen-inspect.1.gz
%ghost %{_sysconfdir}/alternatives/mutagen-pony.1.gz
%{python3_sitelib}/mutagen
%{python3_sitelib}/mutagen-%{version}-py*.egg-info

%changelog