Erik Grinaker is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againRevelation / py-compile
- commit
- e92f2103325c
- parent
- e7337e848a4c
- branch
- default
- tags
- revelation-0.4.7
set release date
1 |
a207757f8451
|
#!/bin/sh |
2 |
d3dc5af086e8
|
# py-compile - Compile a Python program |
3 |
a207757f8451
|
|
4 |
d3dc5af086e8
|
scriptversion=2005-05-14.22 |
5 |
d3dc5af086e8
|
|
6 |
d3dc5af086e8
|
# Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. |
7 |
a207757f8451
|
|
8 |
a207757f8451
|
# This program is free software; you can redistribute it and/or modify |
9 |
a207757f8451
|
# it under the terms of the GNU General Public License as published by |
10 |
a207757f8451
|
# the Free Software Foundation; either version 2, or (at your option) |
11 |
a207757f8451
|
# any later version. |
12 |
a207757f8451
|
|
13 |
a207757f8451
|
# This program is distributed in the hope that it will be useful, |
14 |
a207757f8451
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
a207757f8451
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
a207757f8451
|
# GNU General Public License for more details. |
17 |
a207757f8451
|
|
18 |
a207757f8451
|
# You should have received a copy of the GNU General Public License |
19 |
a207757f8451
|
# along with this program; if not, write to the Free Software |
20 |
d3dc5af086e8
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 |
d3dc5af086e8
|
# 02110-1301, USA. |
22 |
a207757f8451
|
|
23 |
a207757f8451
|
# As a special exception to the GNU General Public License, if you |
24 |
a207757f8451
|
# distribute this file as part of a program that contains a |
25 |
a207757f8451
|
# configuration script generated by Autoconf, you may include it under |
26 |
a207757f8451
|
# the same distribution terms that you use for the rest of that program. |
27 |
a207757f8451
|
|
28 |
d3dc5af086e8
|
# This file is maintained in Automake, please report |
29 |
d3dc5af086e8
|
# bugs to <bug-automake@gnu.org> or send patches to |
30 |
d3dc5af086e8
|
# <automake-patches@gnu.org>. |
31 |
a207757f8451
|
|
32 |
a207757f8451
|
if [ -z "$PYTHON" ]; then |
33 |
a207757f8451
|
PYTHON=python |
34 |
a207757f8451
|
fi |
35 |
a207757f8451
|
|
36 |
a207757f8451
|
basedir= |
37 |
d3dc5af086e8
|
destdir= |
38 |
d3dc5af086e8
|
files= |
39 |
d3dc5af086e8
|
while test $# -ne 0; do |
40 |
d3dc5af086e8
|
case "$1" in |
41 |
d3dc5af086e8
|
--basedir) |
42 |
d3dc5af086e8
|
basedir=$2 |
43 |
d3dc5af086e8
|
if test -z "$basedir"; then |
44 |
d3dc5af086e8
|
echo "$0: Missing argument to --basedir." 1>&2 |
45 |
d3dc5af086e8
|
exit 1 |
46 |
d3dc5af086e8
|
fi |
47 |
d3dc5af086e8
|
shift |
48 |
d3dc5af086e8
|
;; |
49 |
d3dc5af086e8
|
--destdir) |
50 |
d3dc5af086e8
|
destdir=$2 |
51 |
d3dc5af086e8
|
if test -z "$destdir"; then |
52 |
d3dc5af086e8
|
echo "$0: Missing argument to --destdir." 1>&2 |
53 |
d3dc5af086e8
|
exit 1 |
54 |
d3dc5af086e8
|
fi |
55 |
d3dc5af086e8
|
shift |
56 |
d3dc5af086e8
|
;; |
57 |
d3dc5af086e8
|
-h|--h*) |
58 |
d3dc5af086e8
|
cat <<\EOF |
59 |
d3dc5af086e8
|
Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..." |
60 |
a207757f8451
|
|
61 |
d3dc5af086e8
|
Byte compile some python scripts FILES. Use --destdir to specify any |
62 |
d3dc5af086e8
|
leading directory path to the FILES that you don't want to include in the |
63 |
d3dc5af086e8
|
byte compiled file. Specify --basedir for any additional path information you |
64 |
d3dc5af086e8
|
do want to be shown in the byte compiled file. |
65 |
a207757f8451
|
|
66 |
d3dc5af086e8
|
Example: |
67 |
d3dc5af086e8
|
py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py |
68 |
d3dc5af086e8
|
|
69 |
d3dc5af086e8
|
Report bugs to <bug-automake@gnu.org>. |
70 |
d3dc5af086e8
|
EOF |
71 |
d3dc5af086e8
|
exit $? |
72 |
d3dc5af086e8
|
;; |
73 |
d3dc5af086e8
|
-v|--v*) |
74 |
d3dc5af086e8
|
echo "py-compile $scriptversion" |
75 |
d3dc5af086e8
|
exit $? |
76 |
d3dc5af086e8
|
;; |
77 |
d3dc5af086e8
|
*) |
78 |
d3dc5af086e8
|
files="$files $1" |
79 |
d3dc5af086e8
|
;; |
80 |
d3dc5af086e8
|
esac |
81 |
d3dc5af086e8
|
shift |
82 |
d3dc5af086e8
|
done |
83 |
d3dc5af086e8
|
|
84 |
d3dc5af086e8
|
if test -z "$files"; then |
85 |
d3dc5af086e8
|
echo "$0: No files given. Try \`$0 --help' for more information." 1>&2 |
86 |
a207757f8451
|
exit 1 |
87 |
a207757f8451
|
fi |
88 |
a207757f8451
|
|
89 |
a207757f8451
|
# if basedir was given, then it should be prepended to filenames before |
90 |
a207757f8451
|
# byte compilation. |
91 |
a207757f8451
|
if [ -z "$basedir" ]; then |
92 |
d3dc5af086e8
|
pathtrans="path = file" |
93 |
a207757f8451
|
else |
94 |
d3dc5af086e8
|
pathtrans="path = os.path.join('$basedir', file)" |
95 |
d3dc5af086e8
|
fi |
96 |
d3dc5af086e8
|
|
97 |
d3dc5af086e8
|
# if destdir was given, then it needs to be prepended to the filename to |
98 |
d3dc5af086e8
|
# byte compile but not go into the compiled file. |
99 |
d3dc5af086e8
|
if [ -z "$destdir" ]; then |
100 |
d3dc5af086e8
|
filetrans="filepath = path" |
101 |
d3dc5af086e8
|
else |
102 |
d3dc5af086e8
|
filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)" |
103 |
a207757f8451
|
fi |
104 |
a207757f8451
|
|
105 |
a207757f8451
|
$PYTHON -c " |
106 |
a207757f8451
|
import sys, os, string, py_compile |
107 |
a207757f8451
|
|
108 |
d3dc5af086e8
|
files = '''$files''' |
109 |
d3dc5af086e8
|
|
110 |
a207757f8451
|
print 'Byte-compiling python modules...' |
111 |
a207757f8451
|
for file in string.split(files): |
112 |
d3dc5af086e8
|
$pathtrans |
113 |
d3dc5af086e8
|
$filetrans |
114 |
d3dc5af086e8
|
if not os.path.exists(filepath) or not (len(filepath) >= 3 |
115 |
d3dc5af086e8
|
and filepath[-3:] == '.py'): |
116 |
a207757f8451
|
continue |
117 |
a207757f8451
|
print file, |
118 |
a207757f8451
|
sys.stdout.flush() |
119 |
d3dc5af086e8
|
py_compile.compile(filepath, filepath + 'c', path) |
120 |
a207757f8451
|
print" || exit $? |
121 |
a207757f8451
|
|
122 |
a207757f8451
|
# this will fail for python < 1.5, but that doesn't matter ... |
123 |
a207757f8451
|
$PYTHON -O -c " |
124 |
a207757f8451
|
import sys, os, string, py_compile |
125 |
a207757f8451
|
|
126 |
d3dc5af086e8
|
files = '''$files''' |
127 |
a207757f8451
|
print 'Byte-compiling python modules (optimized versions) ...' |
128 |
a207757f8451
|
for file in string.split(files): |
129 |
d3dc5af086e8
|
$pathtrans |
130 |
d3dc5af086e8
|
$filetrans |
131 |
d3dc5af086e8
|
if not os.path.exists(filepath) or not (len(filepath) >= 3 |
132 |
d3dc5af086e8
|
and filepath[-3:] == '.py'): |
133 |
a207757f8451
|
continue |
134 |
a207757f8451
|
print file, |
135 |
a207757f8451
|
sys.stdout.flush() |
136 |
d3dc5af086e8
|
py_compile.compile(filepath, filepath + 'o', path) |
137 |
a207757f8451
|
print" 2>/dev/null || : |
138 |
a207757f8451
|
|
139 |
d3dc5af086e8
|
# Local Variables: |
140 |
d3dc5af086e8
|
# mode: shell-script |
141 |
d3dc5af086e8
|
# sh-indentation: 2 |
142 |
d3dc5af086e8
|
# eval: (add-hook 'write-file-hooks 'time-stamp) |
143 |
d3dc5af086e8
|
# time-stamp-start: "scriptversion=" |
144 |
d3dc5af086e8
|
# time-stamp-format: "%:y-%02m-%02d.%02H" |
145 |
d3dc5af086e8
|
# time-stamp-end: "$" |
146 |
d3dc5af086e8
|
# End: |