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