]>
Commit | Line | Data |
---|---|---|
6566e5f2 MT |
1 | #!/bin/sh |
2 | ||
e9e430d4 MT |
3 | python_interpreter="python" |
4 | paths="" | |
5 | ||
6 | while [ $# -gt 0 ]; do | |
7 | case "${1}" in | |
8 | --python=*) | |
9 | python_interpreter=${1#--python=} | |
10 | ;; | |
11 | *) | |
12 | paths="${paths} ${1}" | |
13 | ;; | |
14 | esac | |
15 | shift | |
16 | done | |
6566e5f2 | 17 | |
e9e430d4 MT |
18 | if [ -z "${paths}" ]; then |
19 | echo >&2 "No path specified!" | |
20 | exit 1 | |
6566e5f2 MT |
21 | fi |
22 | ||
e9e430d4 MT |
23 | if [ "${python_interpreter:0:1}" != "/" ]; then |
24 | python_interpreter=$(which ${python_interpreter} 2>/dev/null) | |
25 | fi | |
6566e5f2 | 26 | |
e9e430d4 MT |
27 | if [ ! -x "${python_interpreter}" ]; then |
28 | echo >&2 "Python interpreter is not executable: ${python_interpreter}" | |
29 | exit 1 | |
6566e5f2 MT |
30 | fi |
31 | ||
e9e430d4 MT |
32 | tempfile=$(mktemp) |
33 | trap "rm -f ${tempfile}" EXIT | |
34 | ||
35 | cat > ${tempfile} <<EOF | |
61918bfa | 36 | import os |
e9e430d4 MT |
37 | import py_compile |
38 | import sys | |
39 | ||
40 | for file in sys.argv[1:]: | |
61918bfa MT |
41 | if not os.path.exists(file): |
42 | continue | |
43 | ||
e9e430d4 MT |
44 | py_compile.compile(file, doraise=0) |
45 | EOF | |
46 | ||
61918bfa | 47 | filelist=$(find ${paths} -type f -a -name "*.py" 2>/dev/null) |
e9e430d4 MT |
48 | |
49 | # Compile with optimization. | |
50 | ${python_interpreter} -O ${tempfile} ${filelist} | |
51 | ||
52 | # Compile without optimization. | |
53 | ${python_interpreter} ${tempfile} ${filelist} | |
54 | ||
55 | # Hardlink identical files. | |
61918bfa | 56 | for pyc in $(find ${paths} -type f -a -name "*.pyc" 2>/dev/null); do |
e9e430d4 MT |
57 | pyo="${pyc/.pyc/.pyo}" |
58 | ||
59 | if cmp -s "${pyc}" "${pyo}"; then | |
60 | ln -f "${pyc}" "${pyo}" | |
61 | fi | |
62 | done |