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