%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}

Name:           calibre
Version:        0.8.50
Release:        1%{?_dist_release}
Summary:        E-book converter and library management
Group:          Applications/Multimedia
License:        GPLv3
URL:            http://calibre-ebook.com/

# SourceURL: http://downloads.sourceforge.net/%{name}/%{name}-%{version}.tar.gz

# Upstream packages some unfree fonts which we cannot redistribute.
# While we're at it, also delete the liberation fonts which we already have.
#
# Download the upstream tarball and invoke this script while in the tarball's
# directory:
# ./generate-tarball.sh %{version}
Source0:        %{name}-%{version}-nofonts.tar.xz
Source1:        generate-tarball.sh
Source2:	calibre-mount-helper
Patch0:         %{name}-manpages.patch
Patch1:         %{name}-no-update.patch
Patch2:		calibre-0.8.21-poppler.patch
Patch10:	calibre-0.8.41-python27.patch
BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root

BuildRequires:	python >= 2.7.1
BuildRequires:	python-devel >= 2.7.1
BuildRequires:	ImageMagick-devel >= 6.5.9
BuildRequires:	python-setuptools
BuildRequires:	qt4-devel >= 4.7.0
BuildRequires:  PyQt4-devel >= 4.8.2
BuildRequires:	poppler-qt4-devel >= 0.12
BuildRequires:	podofo-devel >= 0.8.2
BuildRequires:	desktop-file-utils
BuildRequires:	python-mechanize >= 0.1.1
BuildRequires:	python-lxml >= 2.2.1
BuildRequires:	python-cssutils >= 0.9.6
BuildRequires:	python-dateutil >= 1.4.1
BuildRequires:	python-imaging >= 1.1.6
BuildRequires:	xdg-utils >= 1.0.2
BuildRequires:	python-BeautifulSoup >= 3.0.5
BuildRequires:	xz
BuildRequires:	unzip
BuildRequires:	libwmf-devel >= 0.2.8
BuildRequires:	chmlib-devel >= 0.40
BuildRequires:  python-cssutils > 0.9.6
BuildRequires:  sqlite3-devel
BuildRequires:	libicu-devel >= 4.4

Requires:	PyQt4
Requires:	pyPdf
Requires:	python-cherrypy
Requires:	python-cssutils
Requires:	ImageMagick
Requires:	python-odf
Requires:	python-django-tagging
Requires:	python-lxml
Requires:	python-imaging
Requires:	python-mechanize
Requires:	python-dateutil
Requires:	python-genshi
Requires:	python-BeautifulSoup

## vine
Requires:	TrueType-liberation

%description
Calibre is meant to be a complete e-library solution. It includes library
management, format conversion, news feeds to ebook conversion as well as
e-book reader sync features.

Calibre is primarily a ebook cataloging program. It manages your ebook
collection for you. It is designed around the concept of the logical book,
i.e. a single entry in the database that may correspond to ebooks in several
formats. It also supports conversion to and from a dozen different ebook
formats.

Supported input formats are: MOBI, LIT, PRC, EPUB, CHM, ODT, HTML, CBR, CBZ,
RTF, TXT, PDF and LRS.

%prep
%setup -q -n %{name}

# don't append calibre1 to the name of the manpages. No need to compress either
# upstream won't fix: http://bugs.calibre-ebook.com/ticket/3770#comment:7
%patch0 -p1 -b .manpages

# don't check for new upstream version (that's what packagers do)
%patch1 -p1 -b .no-update

# modify poppler checks
%patch2 -p1 -b .poppler

# use python2.7
%patch10 -p1 -b .vine

# 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/templite/*.py
%{__sed} -i -e '/^#!\//, 1d' resources/default_tweaks.py
%{__sed} -i -e '/^#!\//, 1d' resources/catalog/section_list_templates.py

%{__chmod} -x src/calibre/*/*/*/*.py
%{__chmod} -x src/calibre/*/*/*.py
%{__chmod} -x src/calibre/*/*.py
%{__chmod} -x src/calibre/*.py

%build
OVERRIDE_CFLAGS="%{optflags}" QMAKE=%{_libdir}/qt4/bin/qmake python setup.py build

%install
%__rm -rf %{buildroot}

%__mkdir -p %{buildroot}%{_datadir}

# create directories for xdg-utils
%__mkdir_p %{buildroot}%{_datadir}/icons
%__mkdir_p %{buildroot}%{_datadir}/icons/hicolor
%__mkdir_p %{buildroot}%{_datadir}/packages
%__mkdir_p %{buildroot}%{_datadir}/mime
%__mkdir_p %{buildroot}%{_datadir}/mime/packages
%__mkdir_p %{buildroot}%{_datadir}/applications
%__mkdir_p %{buildroot}%{_datadir}/desktop-directories

# create directory for calibre environment module
# the install script assumes it's there.
%__mkdir_p %{buildroot}%{python_sitelib}

XDG_DATA_DIRS="%{buildroot}%{_datadir}" \
XDG_UTILS_INSTALL_MODE="system" \
LIBPATH="%{_libdir}" \
python setup.py install --root=%{buildroot}%{_prefix} \
			--prefix=%{_prefix} \
			--libdir=%{_libdir} \
			--staging-libdir=%{buildroot}%{_libdir}

# remove shebang from init_calibre.py here because
# it just got spawned by the install script
%{__sed} -i -e '/^#!\//, 1d' %{buildroot}%{python_sitelib}/init_calibre.py

# icons
%__mkdir_p %{buildroot}%{_datadir}/pixmaps/
%__cp -p resources/images/library.png \
	%{buildroot}%{_datadir}/pixmaps/%{name}-gui.png
%__cp -p resources/images/viewer.png \
	%{buildroot}%{_datadir}/pixmaps/calibre-viewer.png

# every file is empty here
find %{buildroot}%{_datadir}/mime -maxdepth 1 -type f|xargs %__rm -f 

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

desktop-file-validate \
    %{buildroot}%{_datadir}/applications/calibre-ebook-viewer.desktop
desktop-file-validate \
    %{buildroot}%{_datadir}/applications/calibre-gui.desktop
desktop-file-validate \
    %{buildroot}%{_datadir}/applications/calibre-lrfviewer.desktop


%__mv %{buildroot}%{_datadir}/mime/packages/calibre-mimetypes \
    %{buildroot}%{_datadir}/mime/packages/calibre-mimetypes.xml

# mimetype icon for lrf
%__rm -rf %{buildroot}%{_datadir}/icons/hicolor/128x128
%__mkdir_p %{buildroot}%{_datadir}/icons/hicolor/scalable
%__mkdir_p %{buildroot}%{_datadir}/icons/hicolor/scalable/mimetypes
%__mkdir_p %{buildroot}%{_datadir}/icons/hicolor/scalable/apps
%__cp -p resources/images/mimetypes/lrf.png \
    %{buildroot}%{_datadir}/icons/hicolor/scalable/mimetypes/application-x-sony-bbeb.png
%__cp -p resources/images/viewer.png \
    %{buildroot}%{_datadir}/icons/hicolor/scalable/apps/calibre-viewer.png

# don't put bash completions in /usr/etc
%__mv %{buildroot}%{_prefix}%{_sysconfdir} %{buildroot}

# 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

# link to system fonts after we have deleted (see Source0) the non-free ones
# http://bugs.calibre-ebook.com/ticket/3832
%__mkdir_p %{buildroot}%{_datadir}/%{name}/fonts/prs500/
%__ln_s %{_datadir}/fonts/TrueType-liberation/LiberationSans-Regular.ttf \
	%{buildroot}%{_datadir}/%{name}/fonts/prs500/tt0003m_.ttf
%__ln_s %{_datadir}/fonts/TrueType-liberation/LiberationSerif-Regular.ttf \
	%{buildroot}%{_datadir}/%{name}/fonts/prs500/tt0011m_.ttf
%__ln_s %{_datadir}/fonts/TrueType-liberation/LiberationMono-Regular.ttf \
	%{buildroot}%{_datadir}/%{name}/fonts/prs500/tt0419m_.ttf

# http://bugs.calibre-ebook.com/ticket/3770#comment:7
# man pages
%__mv %{buildroot}%{_datadir}/%{name}/man %{buildroot}%{_mandir}

# delete locales, calibre stores them in a zip file now
rm -rf %{buildroot}%{_datadir}/%{name}/localization/locales/

%{__rm} -f %{buildroot}%{_bindir}/%{name}-uninstall

%__install -m 755 %{SOURCE2} %{buildroot}%{_bindir}/calibre-mount-helper

%clean
%{__rm} -rf %{buildroot}

%post
update-desktop-database &> /dev/null ||:
update-mime-database %{_datadir}/mime &> /dev/null || :
touch --no-create %{_datadir}/icons/hicolor || :
if [ -x %{_bindir}/gtk-update-icon-cache ] ; then
    %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
fi

%postun
update-desktop-database &> /dev/null ||:
update-mime-database %{_datadir}/mime &> /dev/null || :
touch --no-create %{_datadir}/icons/hicolor || :
if [ -x %{_bindir}/gtk-update-icon-cache ] ; then
    %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
fi

%files
%defattr(-,root,root,-)
%doc COPYRIGHT LICENSE Changelog.yaml
%{_bindir}/calibre
%{_bindir}/calibre-complete
%{_bindir}/calibre-customize
%{_bindir}/calibre-debug
%{_bindir}/calibre-parallel
%{_bindir}/calibre-server
%{_bindir}/calibre-smtp
%{_bindir}/calibre-mount-helper
%{_bindir}/calibredb
%{_bindir}/ebook-convert
%{_bindir}/ebook-device
%{_bindir}/ebook-meta
%{_bindir}/ebook-viewer
%{_bindir}/epub-fix
%{_bindir}/fetch-ebook-metadata
%{_bindir}/lrf2lrs
%{_bindir}/lrfviewer
%{_bindir}/lrs2lrf
%{_bindir}/markdown-calibre
%{_bindir}/pdfmanipulate
%{_bindir}/web2disk
%config(noreplace) %{_sysconfdir}/bash_completion.d/
%{_libdir}/%{name}
%{_datadir}/%{name}
%{_datadir}/pixmaps/*
%{_datadir}/applications/*.desktop
%{_datadir}/mime/packages/*
%{_datadir}/icons/hicolor/scalable/mimetypes/*
%{_datadir}/icons/hicolor/scalable/apps/*
%{python_sitelib}/init_calibre.py*
%{_mandir}/man1/*

%changelog
* Tue May  8 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.8.50-1
- new upstream release
- BuildRequires: qt4-devel >= 4.8.0
- BuildRequires: PyQt4-devel >= 4.9.1

* Fri Mar 23 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.8.44-1
- new upstream release

* Sun Mar 11 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.8.41-1
- new upstream release

* Sun Mar 11 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.7.50-2
- rebuild with ImageMagick-6.7.5.10

* Sun Mar 20 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.50-1
- new upstream release

* Sat Feb 19 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.46-1
- new upstream release

* Thu Feb 10 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.44-1
- new upstream release

* Fri Feb 04 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.42-1
- new upstream release

* Fri Jan 21 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.40-1
- new upstream release

* Mon Dec 27 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.35-1
- new upstream release

* Sun Dec 19 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.34-1
- new upstream release

* Mon Dec 13 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.33-1
- new upstream release
- added BuildRequires: libicu-devel

* Sat Dec 11 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.32-1
- new upstream release

* Fri Nov 05 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.26-1
- new upstream release

* Sun Oct 31 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.25-1
- new upstream release

  * Tue Oct 19 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.24-1
  - Update to 0.7.24

  * Sat Oct 09 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.23-1
  - Update to 0.7.23
  - Fix up mount helper with our own local script. 
  - Change files to list binaries so missing ones can more easily be noted. 

  * Mon Oct 04 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.22-1
  - Update to 0.7.22

  * Fri Oct 01 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.21-1
  - Update to 0.7.21

  * Wed Sep 29 2010 jkeating - 0.7.20-2
  - Rebuilt for gcc bug 634757

  * Fri Sep 24 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.20-1
  - Update to 0.7.20

  * Wed Sep 15 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.18-3
  - Rebuild for new ImageMagick

* Wed Sep 29 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.18-1
- new upstream release
- Fix svg/png changes. 

  * Mon Sep 13 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.18-2
  - Fix svg/png changes. 

  * Sun Sep 12 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.18-1
  - Update to 0.7.18
  - Require > 0.9.6 cssutils

  * Fri Sep 03 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.17-1
  - Update to 0.7.17

  * Fri Aug 27 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.16-1
  - Update to 0.7.16

* Mon Aug 23 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 0.7.15-1
- initial build based on Fedora development

* Sat Aug 21 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.15-1
- Update to 0.7.15

* Thu Aug 19 2010 Rex Dieter <rdieter@fedoraproject.org> - 0.7.14-2
- rebuild (poppler)

* Fri Aug 13 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.14-1
- Update to 0.7.14

* Fri Aug 06 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.13-1
- Update to 0.7.13

* Mon Aug 02 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.12-1
- Update to 0.7.12

* Fri Jul 30 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.11-1
- Update to 0.7.11

* Fri Jul 30 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.10-2
- Rebuilt for python2.7

* Fri Jul 23 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.10-1
- Update to 0.7.10

* Sat Jul 17 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.9-1
- Update to 0.7.9

* Sun Jul 11 2010 Michal Nowak <mnowak@redhat.com> - 0.7.8-1
- Update to 0.7.8
- build tar.xz instead of tar.bz2

* Fri Jul 02 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.7-1
- Update to 0.7.7

* Wed Jun 30 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.6-1
- Update to 0.7.6 

* Fri Jun 25 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.5-1
- Update to 0.7.5

* Sun Jun 20 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.4-1
- Update to 0.7.4

* Tue Jun 08 2010 Dan Horák <dan@danny.cz> - 0.7.1-2
- rebuilt with podofo 0.8.1

* Mon Jun 07 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.1-1
- Update to 0.7.1
- Added versioned dep on python-cssutils to make sure at least 0.9.6 is installed.

* Fri Jun 04 2010 Kevin Fenzi <kevin@tummy.com> - 0.7.0-1
- Update to 0.7.0

* Fri May 28 2010 Kevin Fenzi <kevin@tummy.com> - 0.6.55-1
- Update to 0.6.55

* Fri May 21 2010 Kevin Fenzi <kevin@tummy.com> - 0.6.54-1
- Update to 0.6.54

* Fri May 21 2010 Kevin Fenzi <kevin@tummy.com> - 0.6.53-1
- Update to 0.6.53

* Wed May  5 2010 Marcela Maslanova <mmaslano@redhat.com> - 0.6.47-2
- Rebuild against new poppler

* Sat Apr 10 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.47-1
- new upstream release 0.6.47
- new chmlib requirement
- create directory for calibre's environment module
- use bzip2 instead of gzip when preparing tarball in generate-tarball.sh
- remove cssutils patches (we now have python-cssutils 0.9.6 in Fedora)

* Fri Feb 26 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.42-1
- new upstream release 0.6.42
- remove shebang from default_tweaks.py

* Mon Feb  1 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.37-1
- new upstream release 0.6.37

* Fri Jan 29 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.36-1
- new upstream release 0.6.36
- fixed a cssprofiles issue with loading the profiles

* Tue Jan 26 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.35-3
- added -cssprofiles patch to cvs 

* Tue Jan 26 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.35-2
- remove python-cssutils 0.9.6 dependency

* Mon Jan 25 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.35-1
- new upstream release
- fedora includes cssutils >= 0.9.6 now; removed the cssprofiles patch
- removed -executables patch, upstream fixed it: http://bugs.calibre-ebook.com/ticket/4437

* Wed Jan  6 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.32-2
- fix for package tagged without adding new patch to cvs

* Wed Jan  6 2010 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.32-1
- new upstream release 0.6.32
- project website has changed
- added python-BeautifulSoup BuildRequire
- new patch to fix full buildpath in binary files

* Sun Dec  6 2009 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.26-1
- New upstream version
- Regenerated no-update patch because of code relocation

* Wed Dec  2 2009 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.25-1
- New upstream release

* Wed Nov 18 2009 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.24-1
- New upstream release: http://calibre.kovidgoyal.net/wiki/Changelog#Version0.6.2416Nov2009

* Mon Nov 16 2009 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.23-1
- new upstream release: http://calibre.kovidgoyal.net/wiki/Changelog#Version0.6.2313Nov2009
- patch to stop checking for new upstream version

* Sat Nov  7 2009 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.21-1
- new upstream version: http://calibre.kovidgoyal.net/wiki/Changelog#Version0.6.2106Nov2009
- added python-BeautifulSoup requirement

* Wed Nov  4 2009 Ionuț Arțăriși <mapleoin@fedoraproject.org> - 0.6.20-1
- new upstream version:
http://calibre.kovidgoyal.net/wiki/Changelog#Version0.6.2030Oct2009
- upstream now ships correct .desktop files
- fixed missing dependency: PyQt4
- fixed calibre-gui icon

* Thu Oct 22 2009 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.19-3
- removed unfree fonts from source package

* Thu Oct 22 2009 Ionuț C. Arțăriși <mapleoin@fedoraproject.org> - 0.6.19-2
- readability enhancements
- added python-genshi requires
- removed libwmf require since ImageMagick provides libwmf-lite as a
  dependency and that's what we actually need

* Wed Oct 21 2009 Ionuț Arțăriși <mapleoin@fedoraproject.org> - 0.6.19-1
- new upstream version:
  http://calibre.kovidgoyal.net/wiki/Changelog#Version0.6.1920Oct2009
- delete fonts, calibre can find the system fonts
- specify libdir as an install option, so calibre will link properly
  even on 64bit

* Mon Oct 19 2009 Ionuț Arțăriși <mapleoin@fedoraproject.org> - 0.6.18-1
- updated requires list
- new upstream release
- can override CFLAGS now
- removed trac and genshi duplicates
- use xdg env variables to do desktop integration in the buildroot
- added xdg-utils buildrequire
- install udev rules in /usr/lib even on 64bit and don't own the whole dir
- removed wrongly used Version field from .desktop files

* Mon Oct 12 2009 Ionuț Arțăriși <mapleoin@fedoraproject.org> - 0.6.17-2
- mimick what calibre's desktop-integration script does (mimetypes, icons etc.)
- removed unneeded INSTALL file
- marked bash completion file as config(noreplace) and take ownership of the dir

* Sat Oct 10 2009 Ionuț Arțăriși <mapleoin@fedoraproject.org> - 0.6.17-1
- new upstream release: http://calibre.kovidgoyal.net/wiki/Changelog#Version0.6.1709Oct2009
- the install process changed significantly
- locales were added

* Thu Sep 10 2009 Ionuț Arțăriși <mapleoin@lavabit.com> - 0.6.11-1
- new upstream release: http://calibre.kovidgoyal.net/wiki/Changelog#Version0.6.1104Sep2009
- minor path fixes
- rearranged files section

* Fri Aug 28 2009 Ionuț Arțăriși <mapleoin@fedoraproject.org> 0.6.10-1
- handle desktop files
- don't compress manpages and don't list them as duplicates
- added lrfviewer icon

* Tue Aug 25 2009 Ionuț Arțăriși <mapleoin@fedoraproject.org> 0.6.8-1
- Initial RPM release
