source: trunk/essentials/sys-devel/automake-1.7/lib/py-compile

Last change on this file was 3120, checked in by bird, 18 years ago

automake 1.7.9

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