| 1 | # Copyright 1999-2008 Gentoo Foundation |
1 | # Copyright 1999-2008 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.38 2008/05/29 20:01:55 hawking Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.41 2008/05/30 09:58:28 hawking Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: python.eclass |
5 | # @ECLASS: python.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # python@gentoo.org |
7 | # python@gentoo.org |
| 8 | # |
8 | # |
| … | |
… | |
| 135 | python_mod_compile() { |
135 | python_mod_compile() { |
| 136 | local f myroot |
136 | local f myroot |
| 137 | |
137 | |
| 138 | # Check if phase is pkg_postinst() |
138 | # Check if phase is pkg_postinst() |
| 139 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
139 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
| 140 | die "${FUNCNAME} should only be run in pkg_postinst()" |
140 | die "${FUNCNAME} should only be run in pkg_postinst()" |
| 141 | |
141 | |
| 142 | # allow compiling for older python versions |
142 | # allow compiling for older python versions |
| 143 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
143 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
| 144 | PYVER=${PYTHON_OVERRIDE_PYVER} |
144 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| 145 | else |
145 | else |
| … | |
… | |
| 171 | # |
171 | # |
| 172 | # If supplied with arguments, it will recompile all modules recursively |
172 | # If supplied with arguments, it will recompile all modules recursively |
| 173 | # in the supplied directory |
173 | # in the supplied directory |
| 174 | # This function should only be run in pkg_postinst() |
174 | # This function should only be run in pkg_postinst() |
| 175 | # |
175 | # |
|
|
176 | # Options passed to this function are passed to compileall.py |
|
|
177 | # |
| 176 | # Example: |
178 | # Example: |
| 177 | # python_mod_optimize /usr/share/codegen |
179 | # python_mod_optimize /usr/share/codegen |
| 178 | python_mod_optimize() { |
180 | python_mod_optimize() { |
| 179 | local mydirs myfiles myroot path |
181 | local mydirs myfiles myroot myopts |
| 180 | |
182 | |
| 181 | # Check if phase is pkg_postinst() |
183 | # Check if phase is pkg_postinst() |
| 182 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
184 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
| 183 | die "${FUNCNAME} should only be run in pkg_postinst()" |
185 | die "${FUNCNAME} should only be run in pkg_postinst()" |
| 184 | |
186 | |
| 185 | # strip trailing slash |
187 | # strip trailing slash |
| 186 | myroot="${ROOT%/}" |
188 | myroot="${ROOT%/}" |
| 187 | |
189 | |
| 188 | # respect ROOT |
190 | # respect ROOT and options passed to compileall.py |
| 189 | for path in $@; do |
191 | while [ $# -gt 0 ]; do |
|
|
192 | case $1 in |
|
|
193 | -l|-f|-q) |
|
|
194 | myopts="${myopts} $1" |
|
|
195 | ;; |
|
|
196 | -d|-x) |
|
|
197 | myopts="${myopts} $1 $2" |
|
|
198 | shift |
|
|
199 | ;; |
|
|
200 | -*) |
|
|
201 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
202 | ;; |
|
|
203 | *) |
| 190 | [ ! -e "${myroot}/${path}" ] && ewarn "${myroot}/${path} doesn't exist!" |
204 | [ ! -e "${myroot}/${1}" ] && ewarn "${myroot}/${1} doesn't exist!" |
| 191 | [ -d "${myroot}/${path#/}" ] && mydirs="${mydirs} ${myroot}/${path#/}" |
205 | [ -d "${myroot}/${1#/}" ] && mydirs="${mydirs} ${myroot}/${1#/}" |
| 192 | # Files are passed to python_mod_compile which is ROOT-aware |
206 | # Files are passed to python_mod_compile which is ROOT-aware |
| 193 | [ -f "${myroot}/${path}" ] && myfiles="${myfiles} ${path}" |
207 | [ -f "${myroot}/${1}" ] && myfiles="${myfiles} ${1}" |
|
|
208 | ;; |
|
|
209 | esac |
|
|
210 | shift |
| 194 | done |
211 | done |
| 195 | |
212 | |
| 196 | # allow compiling for older python versions |
213 | # allow compiling for older python versions |
| 197 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
214 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
| 198 | PYVER=${PYTHON_OVERRIDE_PYVER} |
215 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| 199 | else |
216 | else |
| 200 | python_version |
217 | python_version |
| 201 | fi |
218 | fi |
| 202 | |
219 | |
| 203 | # set opts |
220 | # set additional opts |
| 204 | if [ "${PYVER}" = "2.2" ]; then |
221 | myopts="${myopts} -q" |
| 205 | compileopts="" |
|
|
| 206 | else |
|
|
| 207 | compileopts="-q" |
|
|
| 208 | fi |
|
|
| 209 | |
222 | |
| 210 | ebegin "Byte compiling python modules for python-${PYVER} .." |
223 | ebegin "Byte compiling python modules for python-${PYVER} .." |
| 211 | if [ -n "${mydirs}" ]; then |
224 | if [ -n "${mydirs}" ]; then |
| 212 | python${PYVER} \ |
225 | python${PYVER} \ |
| 213 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
226 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 214 | ${compileopts} ${mydirs} |
227 | ${myopts} ${mydirs} |
| 215 | python${PYVER} -O \ |
228 | python${PYVER} -O \ |
| 216 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
229 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 217 | ${compileopts} ${mydirs} |
230 | ${myopts} ${mydirs} |
| 218 | fi |
231 | fi |
| 219 | |
232 | |
| 220 | if [ -n "${myfiles}" ]; then |
233 | if [ -n "${myfiles}" ]; then |
| 221 | python_mod_compile ${myfiles} |
234 | python_mod_compile ${myfiles} |
| 222 | fi |
235 | fi |
| … | |
… | |
| 238 | python_mod_cleanup() { |
251 | python_mod_cleanup() { |
| 239 | local SEARCH_PATH myroot |
252 | local SEARCH_PATH myroot |
| 240 | |
253 | |
| 241 | # Check if phase is pkg_postrm() |
254 | # Check if phase is pkg_postrm() |
| 242 | [[ ${EBUILD_PHASE} != postrm ]] &&\ |
255 | [[ ${EBUILD_PHASE} != postrm ]] &&\ |
| 243 | die "${FUNCNAME} should only be run in pkg_postrm()" |
256 | die "${FUNCNAME} should only be run in pkg_postrm()" |
| 244 | |
257 | |
| 245 | # strip trailing slash |
258 | # strip trailing slash |
| 246 | myroot="${ROOT%/}" |
259 | myroot="${ROOT%/}" |
| 247 | |
260 | |
| 248 | if [ $# -gt 0 ]; then |
261 | if [ $# -gt 0 ]; then |