File: python-epydoc.postinst

package info (click to toggle)
epydoc 2.1-8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,364 kB
  • ctags: 2,878
  • sloc: python: 9,010; makefile: 85; sh: 73
file content (67 lines) | stat: -rw-r--r-- 2,551 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

# The idea here is to install the epydoc modules in /usr/lib/site-python, so
# they'll be accessible to all Python interpreters.  The code below was
# originally based on the postinst for the linda package, but I've now mangled
# it beyond recognition.
#
# Ugh.  This is turning out to be rather nasty.  Hopefully I have now dealt
# with many of the special cases that users have been reporting.
#
# I originally wanted to compile the packages with the default Python
# interpreter.  However, since I depend on various specific versioned python
# packages, this won't work.  Users who don't have the default python package
# installed get postinst failures.  Instead of using just the default, I look
# for the "best" Python on the machine (starting with the default), and use
# that to compile the modules.
#
# This is not a perfect solution.  However, the "best" Python out of my list is
# likely the default, so at least in the general case, users won't have to deal
# with the inefficiency of recompiling the modules every time they run
# Epydoc.  I'm open to suggestions as to a better way to do this, given the
# way the Epydoc dependencies are layed out.
#
# I also need to be able to deal with users who have Python alternatives set
# up.  In other words, /usr/bin/python might point to /etc/alternatives/python
# and from there to some other strange path.  Just because I was able to find
# an interpreter does not mean I have any idea where to find the compileall.py
# script.  So, instead of using compileall.py, I just import the underlying
# compileall.compile_dir() function and run it myself with the interpreter I've
# found.

set -e

DIR='/usr/lib/site-python/epydoc'
SCRIPT="import sys; from compileall import compile_dir as c; r=c(dir='${DIR}', force=1, quiet=1); sys.exit(not r)"

# Note: 2.3 and 2.4 are out-of-order because 2.3 is still the default
for i in python python2.3 python2.4 python2.2 python2.1
do
   if [ -x "/usr/bin/${i}" ];
   then
      PYTHON=`readlink -f /usr/bin/${i}`  # canonical path even if it's not a link
      break
   fi
done

if [ -z ${PYTHON} ];
then
   exit 3
fi

case "$1" in
   configure|abort-upgrade|abort-remove|abort-deconfigure|upgrade)
      if [ "$DEBIAN_FRONTEND" != "noninteractive" ]; then
         echo "Compiling python modules in ${DIR} ..."
      fi
      ${PYTHON} -c "${SCRIPT}"

      if [ "$DEBIAN_FRONTEND" != "noninteractive" ]; then
         echo "Compiling optimized python modules in ${DIR} ..."
      fi
      ${PYTHON} -O -c "${SCRIPT}"
   ;;
esac

#DEBHELPER#