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
- c649040647c5
- parent
- deb6e8bed5dc
- branch
- default
- tags
- revelation-0.4.2
bumped version number to 0.4.2
1 |
a207757f8451
|
#!/bin/sh |
2 |
a207757f8451
|
|
3 |
a207757f8451
|
# py-compile - Compile a Python program |
4 |
a207757f8451
|
# Copyright 2000, 2001 Free Software Foundation, Inc. |
5 |
a207757f8451
|
|
6 |
a207757f8451
|
# This program is free software; you can redistribute it and/or modify |
7 |
a207757f8451
|
# it under the terms of the GNU General Public License as published by |
8 |
a207757f8451
|
# the Free Software Foundation; either version 2, or (at your option) |
9 |
a207757f8451
|
# any later version. |
10 |
a207757f8451
|
|
11 |
a207757f8451
|
# This program is distributed in the hope that it will be useful, |
12 |
a207757f8451
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
a207757f8451
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
a207757f8451
|
# GNU General Public License for more details. |
15 |
a207757f8451
|
|
16 |
a207757f8451
|
# You should have received a copy of the GNU General Public License |
17 |
a207757f8451
|
# along with this program; if not, write to the Free Software |
18 |
a207757f8451
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
19 |
a207757f8451
|
# 02111-1307, USA. |
20 |
a207757f8451
|
|
21 |
a207757f8451
|
# As a special exception to the GNU General Public License, if you |
22 |
a207757f8451
|
# distribute this file as part of a program that contains a |
23 |
a207757f8451
|
# configuration script generated by Autoconf, you may include it under |
24 |
a207757f8451
|
# the same distribution terms that you use for the rest of that program. |
25 |
a207757f8451
|
|
26 |
a207757f8451
|
# called as "py-compile [--basedir DIR] PY_FILES ... |
27 |
a207757f8451
|
|
28 |
a207757f8451
|
if [ -z "$PYTHON" ]; then |
29 |
a207757f8451
|
PYTHON=python |
30 |
a207757f8451
|
fi |
31 |
a207757f8451
|
|
32 |
a207757f8451
|
basedir= |
33 |
a207757f8451
|
|
34 |
a207757f8451
|
case "$1" in |
35 |
a207757f8451
|
--basedir) |
36 |
a207757f8451
|
basedir=$2 |
37 |
a207757f8451
|
shift 2 |
38 |
a207757f8451
|
;; |
39 |
a207757f8451
|
--help) |
40 |
a207757f8451
|
echo "Usage: py-compile [--basedir DIR] PY_FILES ..." |
41 |
a207757f8451
|
echo "Byte compile some python scripts. This should be performed" |
42 |
a207757f8451
|
echo "after they have been moved to the final installation location" |
43 |
a207757f8451
|
exit 0 |
44 |
a207757f8451
|
;; |
45 |
a207757f8451
|
--version) |
46 |
a207757f8451
|
echo "py-compile version 0.0" |
47 |
a207757f8451
|
exit 0 |
48 |
a207757f8451
|
;; |
49 |
a207757f8451
|
esac |
50 |
a207757f8451
|
|
51 |
a207757f8451
|
if [ $# = 0 ]; then |
52 |
a207757f8451
|
echo "No files given to $0" 1>&2 |
53 |
a207757f8451
|
exit 1 |
54 |
a207757f8451
|
fi |
55 |
a207757f8451
|
|
56 |
a207757f8451
|
# if basedir was given, then it should be prepended to filenames before |
57 |
a207757f8451
|
# byte compilation. |
58 |
a207757f8451
|
if [ -z "$basedir" ]; then |
59 |
a207757f8451
|
trans="path = file" |
60 |
a207757f8451
|
else |
61 |
a207757f8451
|
trans="path = os.path.join('$basedir', file)" |
62 |
a207757f8451
|
fi |
63 |
a207757f8451
|
|
64 |
a207757f8451
|
$PYTHON -c " |
65 |
a207757f8451
|
import sys, os, string, py_compile |
66 |
a207757f8451
|
|
67 |
a207757f8451
|
files = '''$*''' |
68 |
a207757f8451
|
print 'Byte-compiling python modules...' |
69 |
a207757f8451
|
for file in string.split(files): |
70 |
a207757f8451
|
$trans |
71 |
a207757f8451
|
if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'): |
72 |
a207757f8451
|
continue |
73 |
a207757f8451
|
print file, |
74 |
a207757f8451
|
sys.stdout.flush() |
75 |
a207757f8451
|
py_compile.compile(path) |
76 |
a207757f8451
|
print" || exit $? |
77 |
a207757f8451
|
|
78 |
a207757f8451
|
# this will fail for python < 1.5, but that doesn't matter ... |
79 |
a207757f8451
|
$PYTHON -O -c " |
80 |
a207757f8451
|
import sys, os, string, py_compile |
81 |
a207757f8451
|
|
82 |
a207757f8451
|
files = '''$*''' |
83 |
a207757f8451
|
print 'Byte-compiling python modules (optimized versions) ...' |
84 |
a207757f8451
|
for file in string.split(files): |
85 |
a207757f8451
|
$trans |
86 |
a207757f8451
|
if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'): |
87 |
a207757f8451
|
continue |
88 |
a207757f8451
|
print file, |
89 |
a207757f8451
|
sys.stdout.flush() |
90 |
a207757f8451
|
py_compile.compile(path) |
91 |
a207757f8451
|
print" 2>/dev/null || : |
92 |
a207757f8451
|