%global pybasever %(%{__python3} -c "import sys; print(sys.version[:3])")
%global date 20200423
%global commit 5732515

Name:          pdfbooklet
Version:       3.1.3a
Release:       0.%{date}.git%{commit}%{?dist}.1sunshine
License:       GPLv3+, CeCILL
Group:         Applications/Publishing
Summary:       A simple application for creating booklets and other layouts from PDF files
URL:           https://sourceforge.net/projects/pdfbooklet
# Source0:       http://downloads.sourceforge.net/%%{name}/%%{name}-%%{version}.tar.gz
# git source created with:
# git clone https://github.com/Averell7/PdfBooklet/ pdfbooklet-$version-$commit; cd pdfbooklet-$version-$commit; git checkout $commit; cd -; tar cJvvp --exclude .git -f pdfbooklet-$version-$commit.tar.xz pdfbooklet-$version-$commit
Source0:       %{name}-%{version}-%{commit}.tar.xz
Patch0:        %{name}-%{version}-docpath.patch
Patch1:        %{name}-%{version}-version.patch
Patch2:        %{name}-%{version}-translations.patch
BuildRequires: python3-setuptools python3-devel
Requires:      python3 pygobject3 python3-gobject python3-cairo
BuildArch:     noarch

%description
A simple application for creating booklets and other layouts from PDF files

%prep
%setup -q -n %{name}-%{version}-%{commit}
%patch0 -p1 -b.docpath
%patch1 -p1 -b.version
%patch2 -p1 -b.translations
echo 'MimeType=application/pdf;' >> %{name}/data/%{name}.desktop
# fix python hashbang
for file in bin/pdfbooklet pdfbooklet/pdfshuffler_iconview3.py pdfbooklet/files_chooser.py; do
    sed -i -e 's|/usr/bin/python|/usr/bin/python3|' "$file"
done
# rename to avoid single quote (patch0 follows this new name)
cp -p "documentation/Pdf-Booklet_User's_Guide.pdf" "documentation/Pdf-Booklet_Users_Guide.pdf"

%build
%{__python3} setup.py build

%install
%{__python3} setup.py install --prefix=%{_prefix} --root=%{buildroot} --optimize=2 --record=INSTALLED_FILES

# don't package .po files
find %{buildroot}%{_datadir}/locale/ -name "*.po*" -delete -print

%find_lang %{name}
%find_lang pdfshuffler

%files -f %{name}.lang -f pdfshuffler.lang
%doc documentation/Manuel_de_Pdf-Booklet.pdf
%doc documentation/Note_for_Linux_users_3.0.6.html
%doc documentation/Pdf-Booklet_Users_Guide.pdf
%{_bindir}/%{name}
%{python3_sitelib}/%{name}*.egg-info
%{python3_sitelib}/%{name}
%{_datadir}/applications/%{name}.desktop
%{_datadir}/%{name}
%{_datadir}/pixmaps/%{name}.png

%changelog
* Thu May 14 2020 Moritz Barsnick <moritz+rpm@barsnick.net> 3.1.3a-0.20200423-git5732515.1sunshine
- update to latest git snapshot
- package all translations using %%find_lang

* Tue Dec 3 2019 Moritz Barsnick <moritz+rpm@barsnick.net> 3.1.3a-0.20191104-git842f593.1sunshine
- update to 3.1.3a

* Tue May 07 2019 Moritz Barsnick <moritz+rpm@barsnick.net> 3.1.0-0.20190507-gitb7d3eca.2sunshine
- fix license
- add a patch to fix the path and the filename of the documentation
- add a patch to display the correct version string
- add a patch to install all translations, and package them all

* Tue May 07 2019 Moritz Barsnick <moritz+rpm@barsnick.net> 3.1.0-0.20190507-gitb7d3eca.1sunshine
- update to 3.1.0
- drop my config file patch, it's upstream

* Sat Nov 03 2018 Moritz Barsnick <moritz+rpm@barsnick.net> 3.0.6-0.4sunshine
- add a patch for the configuration file to be in a proper location

* Fri Nov 02 2018 Moritz Barsnick <moritz+rpm@barsnick.net> 3.0.6-0.3sunshine
- BR python3-devel

* Fri Nov 02 2018 Moritz Barsnick <moritz+rpm@barsnick.net> 3.0.6-0.2sunshine
- fix Requires

* Fri Nov 02 2018 Moritz Barsnick <moritz+rpm@barsnick.net> 3.0.6-0.1sunshine
- update to 3.0.6
- improve packaging

* Sat Feb 22 2014 Muhammad Shaban <Mr.Muhammad@linuxac.org> - 2.2.2-1
- initial build