File calibre.spec of Package calibre

#
# spec file for package calibre
#
# 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/
#


Summary:        EBook Management Application
License:        GPL-3.0
Group:          Productivity/Other
Name:           calibre
Version:        2.62.0
Release:        0
Url:            http://calibre-ebook.com
Source0:        http://download.calibre-ebook.com/%{version}/calibre-%{version}.tar.xz
Source2:        %{name}.desktop
Patch2:         calibre-setup.install.py.diff
# PATCH-FIX-OPENSUSE: disabling Autoupdate Searcher
Patch3:         calibre-no-update.diff
# PATCH-FIX-TO-UPSTREAM: use reproducible list order
Patch4:         reproducible.patch
# PATCH-FIX-UPSTREAM calibre-appdata-add-name-summary.patch badshah400@gmail.com -- Add summary and name fields to appdata
Patch5:         calibre-appdata-add-name-summary.patch
BuildRequires:  fdupes
BuildRequires:  help2man
BuildRequires:  hicolor-icon-theme
BuildRequires:  update-desktop-files

# A note on BuildRequires and Requires:
#
# Requires should always be a subset of BuildRequires. If there are packages
# that are only Required
# * there is no way to check whether these packages are available in the given
#   repositories unless you install the package (the build environment only
#   contains packages from the given repositories and the project
# * the project's repository might become inconsistent, because Required
#   packages do not block a build. So a package might get published, although
#   a Required package does not build
# For those reasons put Requires also in the BuildRequires list below
BuildRequires:  chmlib-devel >= 0.40
BuildRequires:  dbus-1-python >= 1.2.0
BuildRequires:  libQt5Core-private-headers-devel >= 5.3.2
BuildRequires:  libQt5Gui-private-headers-devel >= 5.3.2
BuildRequires:  libQt5PlatformSupport-private-headers-devel >= 5.3.2
BuildRequires:  libicu-devel >= 4.4
BuildRequires:  libmtp-devel
BuildRequires:  libopenssl-devel
BuildRequires:  libpodofo-devel >= 0.8.2
BuildRequires:  libpoppler-devel >= 0.20.2
BuildRequires:  libwmf-devel >= 0.2.8
BuildRequires:  poppler-tools
BuildRequires:  python-Pillow
BuildRequires:  python-apsw
BuildRequires:  python-beautifulsoup >= 3.0.5
BuildRequires:  python-cherrypy
BuildRequires:  python-cssselect >= 0.7.1
BuildRequires:  python-cssutils >= 0.9.9
BuildRequires:  python-dateutil >= 1.4.1
BuildRequires:  python-devel >= 2.7.9
BuildRequires:  python-dnspython >= 1.6.0
BuildRequires:  python-genshi
BuildRequires:  python-lxml >= 3.2.1
BuildRequires:  python-mechanize >= 0.1.11
BuildRequires:  python-netifaces
BuildRequires:  python-odfpy
BuildRequires:  python-pypdf
BuildRequires:  python-qt5-devel >= 5.3.1
BuildRequires:  python-setuptools
BuildRequires:  sqlite3-devel
BuildRequires:  xdg-utils >= 1.0.2
# calibre no longer depends on ImageMagick
# but keept BuildREquires to convert icon to several sizes
BuildRequires:  pkgconfig(ImageMagick) >= 6.5.9

Requires:       chmlib >= 0.40
Requires:       dbus-1-python
Requires:       libicu >= 4.4
Requires:       libmtp9
Requires:       libwmf >= 0.2.8
Requires:       optipng >= 0.7.5
Requires:       podofo >= 0.8.2
Requires:       poppler-tools
Requires:       python >= 2.7.9
%if 0%{?suse_version} > 1320 
Requires:       python-Pygments >= 2.0.1
%endif
Requires:       python-Pillow
Requires:       python-apsw
Requires:       python-beautifulsoup >= 3.0.5
Requires:       python-cherrypy
Requires:       python-cssselect >= 0.7.1
Requires:       python-cssutils >= 0.9.9
Requires:       python-dateutil >= 1.4.1
Requires:       python-dnspython >= 1.6.0
Requires:       python-genshi
Requires:       python-lxml >= 3.2.1
Requires:       python-mechanize >= 0.1.11
Requires:       python-netifaces
Requires:       python-odfpy
Requires:       python-pypdf
Requires:       python-qt5 >= 5.3.1
Requires:       python-setuptools
Requires:       sqlite3
Requires:       xdg-utils >= 1.0.2
%requires_eq    libQt5Core5
%requires_eq    libQt5Gui5

BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%{py_requires}
# http://lists.opensuse.org/opensuse-packaging/2009-08/msg00110.html

%description
Calibre is an ebook library manager. It can view, convert and catalog
ebooks in most of the major ebook formats. It can also talk to a few
ebook reader devices. It can go out to the internet and fetch
metadata for your books. It can download newspapers and convert them
into ebooks for convenient reading. It is cross platform, running on
Linux, Windows and OS X.

%prep
%setup -q
%patch2 -p1
%patch3 -p1 -b .no-update
%patch4 -p1
%patch5 -p1 

# dos2unix newline conversion
sed -i 's/\r//' src/calibre/web/feeds/recipes/*

# remove shebangs
sed -i -e '/^#!\//, 1d' src/calibre/*/*/*/*/*.py
sed -i -e '/^#!\//, 1d' src/calibre/*/*/*/*.py
sed -i -e '/^#!\//, 1d' src/calibre/*/*/*.py
sed -i -e '/^#![ ]*\//, 1d' src/calibre/*/*.py
sed -i -e '/^#!\//, 1d' src/calibre/*.py
sed -i -e '/^#!\//, 1d' src/templite/*.py
sed -i -e '/^#!\//, 1d' src/tinycss/*.py
sed -i -e '/^#!\//, 1d' src/tinycss/*/*.py
sed -i -e '/^#!\//, 1d' resources/default_tweaks.py
sed -i -e '/^#!\//, 1d' resources/catalog/section_list_templates.py

# remove the executable flag from files
find src/calibre -name "*.py" -type f  | xargs chmod -x
chmod -x recipes/*

# remove bundled beautifulsoup
rm -f src/calibre/ebooks/BeautifulSoup.py
find "." -type f -name \*.py -exec \
    sed -e 's/calibre.ebooks.BeautifulSoup/BeautifulSoup/' -i {} +

cp -v %{SOURCE2}  .

%build
LANG="en_US.UTF8" \
CFLAGS="%{optflags}" \
CXXFLAGS="%{optflags}" \
OVERRIDE_CFLAGS="%{optflags}" \
python setup.py build

%install
python setup.py install \
   --prefix=%{_prefix} \
   --root=%{buildroot}%{_prefix} \
   --staging-bindir=%{buildroot}%{_bindir} \
   --staging-libdir=%{buildroot}%{_libdir} \
   --staging-sharedir=%{buildroot}%{_datadir} \
   --staging-mandir=%{buildroot}%{_mandir} \
   --libdir=%{_libdir}

# GENERATE AND INSTALL HIRES ICONS INTO HICOLOR DIR (PRESENT ICON LOOKS BLURRED ON HiDPI)
for i in 24 32 48 64 128 256 512
do
  mkdir -p %{buildroot}%{_datadir}/icons/hicolor/${i}x${i}/apps
  convert -strip icons/calibre.png \
          -resize ${i}x${i} %{buildroot}%{_datadir}/icons/hicolor/${i}x${i}/apps/%{name}.png
done

%suse_update_desktop_file -i -n calibre Office Viewer

%fdupes %{buildroot}

# packages aren't allowed to register mimetypes like this
rm -f %{buildroot}%{_datadir}/applications/defaults.list

# these are provided as separate packages
rm -rf %{buildroot}%{_libdir}/%{name}/{odf,cherrypy,pyPdf,encutils,cssutils}
rm -rf %{buildroot}%{_libdir}/%{name}/cal/utils/genshi
rm -rf %{buildroot}%{_libdir}/%{name}/cal/trac
# Also the Liberation fonts are provided as separate package
rm -rf %{buildroot}%{_datadir}/%{name}/fonts/liberation

# add shebangs
sed -i -e '1i#!/usr/bin/python' %{buildroot}%{_libdir}/%{name}/chardet/*.py

# appdata file references calibre-gui.desktop, and .appdata.xml file should necessarily have matching name with .desktop file in order for the app to show up in Software Centres
mv %{buildroot}%{_datadir}/applications/calibre.desktop %{buildroot}%{_datadir}/applications/calibre-gui.desktop

# Remove all appdata.xml files but the main one, we do not install the corresponding .desktop files
rm %{buildroot}%{_datadir}/appdata/calibre-ebook-{edit,viewer}.appdata.xml

%post
%desktop_database_post
%icon_theme_cache_post

%postun
%desktop_database_postun
%icon_theme_cache_postun

%files
# -f %%{name}.lang  -f iso639.lang
%defattr(-,root,root)
%{_bindir}/*
%exclude %{_bindir}/calibre-uninstall
%{_datadir}/applications/%{name}-gui.desktop
%dir %{_datadir}/icons/hicolor/512x512
%dir %{_datadir}/icons/hicolor/512x512/apps
%{_datadir}/icons/hicolor/*/apps/*.png
%{_datadir}/%{name}/
%{_libdir}/%{name}/
%dir %{_datadir}/appdata
%{_datadir}/appdata/%{name}-gui.appdata.xml
%{_datadir}/bash-completion/completions/%{name}
/usr/lib/python2.7/site-packages/init_calibre.py

%changelog
openSUSE Build Service is sponsored by