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