Salome HOME
4f4c5a36c09dbaf99a21ff59d666836a476e807f
[modules/yacs.git] / src / wrappergen / src / HXX2SALOME_GENERIC_CLASS_NAME_SRC / adm_local / unix / py-compile
1 #!/bin/sh
2 # py-compile - Compile a Python program
3
4 scriptversion=2004-01-12.23
5
6 # Copyright (C) 2000-2021  CEA/DEN, EDF R&D
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24
25 # This program is free software; you can redistribute it and/or modify
26 # it under the terms of the GNU General Public License as published by
27 # the Free Software Foundation; either version 2, or (at your option)
28 # any later version.
29
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 # GNU General Public License for more details.
34
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
38 # 02111-1307, USA.
39
40 # As a special exception to the GNU General Public License, if you
41 # distribute this file as part of a program that contains a
42 # configuration script generated by Autoconf, you may include it under
43 # the same distribution terms that you use for the rest of that program.
44
45 # This file is maintained in Automake, please report
46 # bugs to <bug-automake@gnu.org> or send patches to
47 # <automake-patches@gnu.org>.
48
49 if [ -z "$PYTHON" ]; then
50   PYTHON=python
51 fi
52
53 basedir=
54
55 case "$1" in
56   --basedir)
57     basedir=$2
58     if test -z "$basedir"; then
59       echo "$0: Missing argument to --basedir." 1>&2
60       exit 1
61     fi
62     shift 2
63     ;;
64   -h|--h*)
65     cat <<\EOF
66 Usage: py-compile [--help] [--version] [--basedir DIR] FILES..."
67
68 Byte compile some python scripts FILES.  This should be performed
69 after they have been moved to the final installation location
70
71 Report bugs to <bug-automake@gnu.org>.
72 EOF
73     exit 0
74     ;;
75   -v|--v*)
76     echo "py-compile $scriptversion"
77     exit 0
78     ;;
79 esac
80
81 if [ $# = 0 ]; then
82     echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
83     exit 1
84 fi
85
86 # if basedir was given, then it should be prepended to filenames before
87 # byte compilation.
88 if [ -z "$basedir" ]; then
89     trans="path = file"
90 else
91     trans="path = os.path.join('$basedir', file)"
92 fi
93
94 $PYTHON -c "
95 import sys, os, string, py_compile
96
97 files = '''$*'''
98 print('Byte-compiling python modules...')
99 for file in string.split(files):
100     $trans
101     if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
102         continue
103     print(file, end='')
104     sys.stdout.flush()
105     py_compile.compile(path)
106 print" || exit $?
107
108 # this will fail for python < 1.5, but that doesn't matter ...
109 $PYTHON -O -c "
110 import sys, os, string, py_compile
111
112 files = '''$*'''
113 print('Byte-compiling python modules (optimized versions) ...')
114 for file in string.split(files):
115     $trans
116     if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
117         continue
118     print(file, end='')
119     sys.stdout.flush()
120     py_compile.compile(path)
121 print" 2>/dev/null || :
122
123 # Local Variables:
124 # mode: shell-script
125 # sh-indentation: 2
126 # eval: (add-hook 'write-file-hooks 'time-stamp)
127 # time-stamp-start: "scriptversion="
128 # time-stamp-format: "%:y-%02m-%02d.%02H"
129 # time-stamp-end: "$"
130 # End: