Salome HOME
Windows compatibility.
[modules/yacs.git] / py-compile
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
28 if [ -z "$PYTHON" ]; then
29   PYTHON=python
30 fi
31
32 basedir=
33
34 case "$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         ;;
49 esac
50
51 if [ $# = 0 ]; then
52     echo "No files given to $0" 1>&2
53     exit 1
54 fi
55
56 # if basedir was given, then it should be prepended to filenames before
57 # byte compilation.
58 if [ -z "$basedir" ]; then
59     trans="path = file"
60 else
61     trans="path = os.path.join('$basedir', file)"
62 fi
63
64 $PYTHON -c "
65 import sys, os, string, py_compile
66
67 files = '''$*'''
68 print 'Byte-compiling python modules...'
69 for 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)
76 print" || exit $?
77
78 # this will fail for python < 1.5, but that doesn't matter ...
79 $PYTHON -O -c "
80 import sys, os, string, py_compile
81
82 files = '''$*'''
83 print 'Byte-compiling python modules (optimised versions) ...'
84 for 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)
91 print" 2>/dev/null || :
92