app-text/calibre: Drop dev-python/dnspython in favour of the virtual
[gentoo.git] / app-text / calibre / calibre-2.33.0.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6 inherit eutils fdo-mime bash-completion-r1 multilib toolchain-funcs
7
8 DESCRIPTION="Ebook management application"
9 HOMEPAGE="http://calibre-ebook.com/"
10 SRC_URI="http://download.calibre-ebook.com/${PV}/${P}.tar.xz"
11
12 LICENSE="
13         GPL-3+
14         GPL-3
15         GPL-2+
16         GPL-2
17         GPL-1+
18         LGPL-3+
19         LGPL-2.1+
20         LGPL-2.1
21         BSD
22         MIT
23         Old-MIT
24         Apache-2.0
25         public-domain
26         || ( Artistic GPL-1+ )
27         CC-BY-3.0
28         OFL-1.1
29         PSF-2
30         unRAR
31 "
32 KEYWORDS="~amd64 ~arm ~x86"
33 SLOT="0"
34 IUSE="+udisks"
35
36 COMMON_DEPEND="
37         >=app-text/podofo-0.8.2:=
38         >=app-text/poppler-0.26.5[qt5]
39         >=dev-lang/python-2.7.9:2.7[sqlite,ssl]
40         >=dev-libs/chmlib-0.40:=
41         dev-libs/glib:2
42         >=dev-libs/icu-4.4:=
43         >=dev-python/apsw-3.7.17[python_targets_python2_7(-)]
44         >=dev-python/beautifulsoup-3.0.5:python-2[python_targets_python2_7(-)]
45         >=dev-python/dnspython-1.6.0:0[python_targets_python2_7(-)]
46         >=dev-python/cssselect-0.7.1[python_targets_python2_7(-)]
47         >=dev-python/cssutils-0.9.9[python_targets_python2_7(-)]
48         >=dev-python/dbus-python-1.2.0[python_targets_python2_7(-)]
49         >=dev-python/lxml-3.2.1[python_targets_python2_7(-)]
50         >=dev-python/mechanize-0.1.11[python_targets_python2_7(-)]
51         dev-python/netifaces[python_targets_python2_7(-)]
52         dev-python/psutil[python_targets_python2_7(-)]
53         >=dev-python/pygments-2.0.1[python_targets_python2_7(-)]
54         >=dev-python/python-dateutil-1.4.1[python_targets_python2_7(-)]
55         >=dev-python/PyQt5-5.3.1[gui,svg,webkit,widgets,network,printsupport,python_targets_python2_7(-)]
56         dev-qt/qtcore:5
57         dev-qt/qtgui:5
58         dev-qt/qtwidgets:5
59         media-fonts/liberation-fonts
60         >=media-gfx/imagemagick-6.5.9[jpeg,png]
61         media-libs/fontconfig
62         >=media-libs/freetype-2:=
63         >=media-libs/libmtp-1.1.5:=
64         >=media-libs/libwmf-0.2.8
65         sys-libs/zlib
66         virtual/libusb:1=
67         virtual/python-imaging[python_targets_python2_7(-)]
68         x11-libs/libX11
69         x11-libs/libXext
70         x11-libs/libXrender
71         >=x11-misc/xdg-utils-1.0.2-r2
72         udisks? ( virtual/libudev )"
73 RDEPEND="${COMMON_DEPEND}
74         udisks? ( || ( sys-fs/udisks:2 sys-fs/udisks:0 ) )"
75 DEPEND="${COMMON_DEPEND}
76         >=dev-python/setuptools-0.6_rc5
77         >=virtual/podofo-build-0.8.2"
78
79 src_prepare() {
80         # Fix outdated version constant.
81         #sed -e "s#\\(^numeric_version =\\).*#\\1 (${PV//./, })#" \
82         #       -i src/calibre/constants.py || \
83         #       die "sed failed to patch constants.py"
84
85         # Avoid sandbox violation in /usr/share/gnome/apps when linux.py
86         # calls xdg-* (bug #258938).
87         sed -e "s|'xdg-desktop-menu', 'install'|\\0, '--mode', 'user'|" \
88                 -e "s|check_call(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
89                 -e "s|\\(CurrentDir(tdir)\\), \\\\\$|\\1:|" \
90                 -e "s|PreserveMIMEDefaults():||" \
91                 -e "s|xdg-icon-resource install|\\0 --mode user|" \
92                 -e "s|cc(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
93                 -e "s|'xdg-mime', 'install'|\\0, '--mode', 'user'|" \
94                 -i src/calibre/linux.py || die "sed failed to patch linux.py"
95
96         # Disable unnecessary privilege dropping for bug #287067.
97         sed -e "s:if os.geteuid() == 0:if False and os.geteuid() == 0:" \
98                 -i setup/install.py || die "sed failed to patch install.py"
99
100         sed -e "/^            self\\.check_call(qmc + \\[.*\\.pro'\\])$/a\
101 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ self.check_call(['sed', \
102 '-e', 's|^CFLAGS .*|\\\\\\\\0 ${CFLAGS}|', \
103 '-e', 's|^CXXFLAGS .*|\\\\\\\\0 ${CXXFLAGS}|', \
104 '-e', 's|^LFLAGS .*|\\\\\\\\0 ${LDFLAGS}|', \
105 '-i', 'Makefile'])" \
106                 -i setup/extensions.py || die "sed failed to patch extensions.py"
107
108         # use system beautifulsoup, instead of bundled
109         rm -f "${S}"/src/calibre/ebooks/BeautifulSoup.py \
110                 || die "could not remove bundled beautifulsoup"
111         find "${S}" -type f -name \*.py -exec \
112                 sed -e 's/calibre.ebooks.BeautifulSoup/BeautifulSoup/' -i {} + \
113                 || die "could not sed bundled beautifulsoup out of the source tree"
114
115         # avoid failure of xdg tools to recognize vendor prefix
116         sed -e "s|xdg-icon-resource install|xdg-icon-resource install --novendor|" \
117                 -e "s|'xdg-mime', 'install'|'xdg-mime', 'install', '--novendor'|" \
118                 -e "s|'xdg-desktop-menu', 'install'|'xdg-desktop-menu', 'install', '--novendor'|" \
119                 -i "${S}"/src/calibre/linux.py || die 'sed failed'
120
121         # no_updates: do not annoy user with "new version is availible all the time
122         # disable_plugins: walking sec-hole, wait for upstream to use GHNS interface
123         epatch \
124                 "${FILESDIR}/${PN}-2.9.0-no_updates_dialog.patch" \
125                 "${FILESDIR}/${PN}-disable_plugins.patch"
126 }
127
128 src_install() {
129         # Bypass kbuildsycoca and update-mime-database in order to
130         # avoid sandbox violations if xdg-mime tries to call them.
131         cat - > "${T}/kbuildsycoca" <<-EOF
132         #!${BASH}
133         echo $0 : $@
134         exit 0
135         EOF
136
137         cp "${T}"/{kbuildsycoca,update-mime-database}
138         chmod +x "${T}"/{kbuildsycoca,update-mime-database}
139
140         export QMAKE="${EPREFIX}/usr/$(get_libdir)/qt5/bin/qmake"
141
142         # Unset DISPLAY in order to prevent xdg-mime from triggering a sandbox
143         # violation with kbuildsycoca as in bug #287067, comment #13.
144         export -n DISPLAY
145
146         # Bug #352625 - Some LANGUAGE values can trigger the following ValueError:
147         #   File "/usr/lib/python2.6/locale.py", line 486, in getdefaultlocale
148         #    return _parse_localename(localename)
149         #  File "/usr/lib/python2.6/locale.py", line 418, in _parse_localename
150         #    raise ValueError, 'unknown locale: %s' % localename
151         #ValueError: unknown locale: 46
152         export -n LANGUAGE
153
154         # Bug #295672 - Avoid sandbox violation in ~/.config by forcing
155         # variables to point to our fake temporary $HOME.
156         export HOME="${T}/fake_homedir"
157         export XDG_CONFIG_HOME="${HOME}/.config"
158         export XDG_DATA_HOME="${HOME}/.local/share"
159         export CALIBRE_CONFIG_DIRECTORY="${XDG_CONFIG_HOME}/calibre"
160         mkdir -p "${XDG_DATA_HOME}" "${CALIBRE_CONFIG_DIRECTORY}"
161
162         tc-export CC CXX
163         # Bug #334243 - respect LDFLAGS when building extensions
164         export OVERRIDE_CFLAGS="$CFLAGS" OVERRIDE_LDFLAGS="$LDFLAGS"
165         local libdir=$(get_libdir)
166         [[ -n $libdir ]] || die "get_libdir returned an empty string"
167
168         # Bug #472690 - Avoid sandbox violation for /dev/dri/card0.
169         local x
170         for x in /dev/dri/card[0-9] ; do
171                 [[ -e ${x} ]] && addpredict ${x}
172         done
173
174         dodir "/usr/$(get_libdir)/python2.7/site-packages" # for init_calibre.py
175         PATH=${T}:${PATH} PYTHONPATH=${S}/src${PYTHONPATH:+:}${PYTHONPATH} \
176         "${EPREFIX}"/usr/bin/python2.7 setup.py install \
177                 --root="${D}" \
178                 --prefix="${EPREFIX}/usr" \
179                 --libdir="${EPREFIX}/usr/${libdir}" \
180                 --staging-root="${ED}usr" \
181                 --staging-libdir="${ED}usr/${libdir}" || die
182
183         grep -rlZ "${ED}" "${ED}" | xargs -0 sed -e "s:${D}:/:g" -i ||
184                 die "failed to fix harcoded \$D in paths"
185
186         # The menu entries end up here due to '--mode user' being added to
187         # xdg-* options in src_prepare.
188         dodir /usr/share/mime/packages
189         chmod -fR a+rX,u+w,g-w,o-w "${HOME}"/.local
190         mv "${HOME}"/.local/share/mime/packages/* "${ED}"usr/share/mime/packages/ ||
191                 die "failed to register mime types"
192         dodir /usr/share/icons
193         mv "${HOME}"/.local/share/icons/* "${ED}"usr/share/icons/ ||
194                 die "failed to install icon files"
195
196         domenu "${HOME}"/.local/share/applications/*.desktop ||
197                 die "failed to install .desktop menu files"
198
199         find "${ED}"usr/share -type d -empty -delete
200
201         cd "${ED}"/usr/share/calibre/fonts/liberation || die
202         local x
203         for x in * ; do
204                 [[ -f ${EROOT}usr/share/fonts/liberation-fonts/${x} ]] || continue
205                 ln -sf "../../../fonts/liberation-fonts/${x}" "${x}" || die
206         done
207
208         einfo "Converting python shebangs"
209         while read -r -d $'\0' ; do
210                 local shebang=$(head -n1 "$REPLY")
211                 if [[ ${shebang} == "#!"*python* ]] ; then
212                         sed -i -e "1s:.*:#!${EPREFIX}/usr/bin/python2.7:" "$REPLY" || \
213                                 die "sed failed"
214                 fi
215         done < <(find "${ED}" -type f -print0)
216
217         einfo "Compiling python modules"
218         "${EPREFIX}"/usr/bin/python2.7 -m compileall -q -f \
219                 -d "${EPREFIX}"/usr/lib/calibre "${ED}"usr/lib/calibre || die
220
221         newinitd "${FILESDIR}"/calibre-server.init calibre-server
222         newconfd "${FILESDIR}"/calibre-server.conf calibre-server
223 }
224
225 pkg_postinst() {
226         fdo-mime_desktop_database_update
227         fdo-mime_mime_database_update
228 }