1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 PYTHON_COMPAT=( python2_7 )
8 PYTHON_REQ_USE="sqlite,ssl"
10 inherit eutils fdo-mime bash-completion-r1 multilib toolchain-funcs python-single-r1
12 DESCRIPTION="Ebook management application"
13 HOMEPAGE="http://calibre-ebook.com/"
14 SRC_URI="http://download.calibre-ebook.com/${PV}/${P}.tar.xz"
30 || ( Artistic GPL-1+ )
36 KEYWORDS="~amd64 ~arm ~x86"
40 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
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:=
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}]
64 media-fonts/liberation-fonts
65 >=media-gfx/imagemagick-6.5.9[jpeg,png]
67 >=media-libs/freetype-2:=
68 >=media-libs/libmtp-1.1.5:=
69 >=media-libs/libwmf-0.2.8
72 virtual/python-dnspython[${PYTHON_USEDEP}]
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
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"
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"
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"
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"
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"
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'
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
131 "${FILESDIR}/${PN}-2.9.0-no_updates_dialog.patch" \
132 "${FILESDIR}/${PN}-disable_plugins.patch"
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
144 cp "${T}"/{kbuildsycoca,update-mime-database} || die
145 chmod +x "${T}"/{kbuildsycoca,update-mime-database} || die
147 export QMAKE="${EPREFIX}/usr/$(get_libdir)/qt5/bin/qmake"
149 # Unset DISPLAY in order to prevent xdg-mime from triggering a sandbox
150 # violation with kbuildsycoca as in bug #287067, comment #13.
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
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
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"
175 # Bug #472690 - Avoid sandbox violation for /dev/dri/card0.
177 for x in /dev/dri/card[0-9] ; do
178 [[ -e ${x} ]] && addpredict ${x}
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 \
186 --prefix="${EPREFIX}/usr" \
187 --libdir="${EPREFIX}/usr/${libdir}" \
188 --staging-root="${ED}usr" \
189 --staging-libdir="${ED}usr/${libdir}" || die
191 grep -rlZ "${ED}" "${ED}" | xargs -0 sed -e "s:${D}:/:g" -i ||
192 die "failed to fix harcoded \$D in paths"
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"
204 domenu "${HOME}"/.local/share/applications/*.desktop ||
205 die "failed to install .desktop menu files"
207 find "${ED}"usr/share -type d -empty -delete
209 cd "${ED}"/usr/share/calibre/fonts/liberation || die
212 [[ -f ${EPREFIX}usr/share/fonts/liberation-fonts/${x} ]] || continue
213 ln -sf "../../../fonts/liberation-fonts/${x}" "${x}" || die
216 einfo "Converting python shebangs"
217 python_fix_shebang "${ED}"
219 einfo "Compiling python modules"
220 python_optimize "${ED}"usr/lib/calibre
222 newinitd "${FILESDIR}"/calibre-server.init calibre-server
223 newconfd "${FILESDIR}"/calibre-server.conf calibre-server
225 bashcomp_alias calibre \
232 fetch-ebook-metadata \
242 fdo-mime_desktop_database_update
243 fdo-mime_mime_database_update
247 fdo-mime_desktop_database_update
248 fdo-mime_mime_database_update