Jumbo patch:
[platform/upstream/automake.git] / lib / py-compile
1 #!/bin/sh
2 # called as "py-compile [--basedir DIR] PY_FILES ...
3
4 if [ -z "$PYTHON" ]; then
5   PYTHON=python
6 fi
7
8 basedir=
9
10 case "$1" in
11     --basedir)
12         basedir=$2
13         shift 2
14         ;;
15     --help)
16         echo "Usage: py-compile [--basedir DIR] PY_FILES ..."
17         echo "Byte compile some python scripts.  This should be performed"
18         echo "after they have been moved to the final installation location"
19         exit 0
20         ;;
21     --version)
22         echo "py-compile version 0.0"
23         exit 0
24         ;;
25 esac
26
27 if [ $# = 0 ]; then
28     echo "No files given to $0" 1>&2
29     exit 1
30 fi
31
32 # if basedir was given, then it should be prepended to filenames before
33 # byte compilation.
34 if [ -z "$basedir" ]; then
35     trans="path = file"
36 else
37     trans="path = os.path.join('$basedir', file)"
38 fi
39
40 $PYTHON -c "
41 import sys, os, string, py_compile
42
43 files = '''$*'''
44 print 'Byte-compiling python modules...'
45 for file in string.split(files):
46     $trans
47     if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
48         continue
49     print file,
50     sys.stdout.flush()
51     py_compile.compile(path)
52 print" || exit $?
53
54 # this will fail for python < 1.5, but that doesn't matter ...
55 $PYTHON -O -c "
56 import sys, os, string, py_compile
57
58 files = '''$*'''
59 print 'Byte-compiling python modules (optimised versions) ...'
60 for file in string.split(files):
61     $trans
62     if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
63         continue
64     print file,
65     sys.stdout.flush()
66     py_compile.compile(path)
67 print" 2>/dev/null || :
68