~ubuntu-branches/ubuntu/hardy/gedit/hardy-proposed

« back to all changes in this revision

Viewing changes to py-compile

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-07-11 14:06:41 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20060711140641-9ale6eu5anm0iftf
Tags: upstream-2.15.4
ImportĀ upstreamĀ versionĀ 2.15.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
# py-compile - Compile a Python program
3
3
 
4
 
scriptversion=2004-01-12.23
 
4
scriptversion=2005-05-14.22
5
5
 
6
 
# Copyright (C) 2000, 2001, 2003, 2004  Free Software Foundation, Inc.
 
6
# Copyright (C) 2000, 2001, 2003, 2004, 2005  Free Software Foundation, Inc.
7
7
 
8
8
# This program is free software; you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
# You should have received a copy of the GNU General Public License
19
19
# along with this program; if not, write to the Free Software
20
 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
 
# 02111-1307, USA.
 
20
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
21
# 02110-1301, USA.
22
22
 
23
23
# As a special exception to the GNU General Public License, if you
24
24
# distribute this file as part of a program that contains a
34
34
fi
35
35
 
36
36
basedir=
37
 
 
38
 
case "$1" in
39
 
  --basedir)
40
 
    basedir=$2
41
 
    if test -z "$basedir"; then
42
 
      echo "$0: Missing argument to --basedir." 1>&2
43
 
      exit 1
44
 
    fi
45
 
    shift 2
46
 
    ;;
47
 
  -h|--h*)
48
 
    cat <<\EOF
49
 
Usage: py-compile [--help] [--version] [--basedir DIR] FILES..."
50
 
 
51
 
Byte compile some python scripts FILES.  This should be performed
52
 
after they have been moved to the final installation location
 
37
destdir=
 
38
files=
 
39
while test $# -ne 0; do
 
40
  case "$1" in
 
41
    --basedir)
 
42
      basedir=$2
 
43
      if test -z "$basedir"; then
 
44
        echo "$0: Missing argument to --basedir." 1>&2
 
45
        exit 1
 
46
      fi
 
47
      shift
 
48
      ;;
 
49
    --destdir)
 
50
      destdir=$2
 
51
      if test -z "$destdir"; then
 
52
        echo "$0: Missing argument to --destdir." 1>&2
 
53
        exit 1
 
54
      fi
 
55
      shift
 
56
      ;;
 
57
    -h|--h*)
 
58
      cat <<\EOF
 
59
Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
 
60
 
 
61
Byte compile some python scripts FILES.  Use --destdir to specify any
 
62
leading directory path to the FILES that you don't want to include in the
 
63
byte compiled file.  Specify --basedir for any additional path information you
 
64
do want to be shown in the byte compiled file.
 
65
 
 
66
Example:
 
67
  py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
53
68
 
54
69
Report bugs to <bug-automake@gnu.org>.
55
70
EOF
56
 
    exit 0
57
 
    ;;
58
 
  -v|--v*)
59
 
    echo "py-compile $scriptversion"
60
 
    exit 0
61
 
    ;;
62
 
esac
 
71
      exit $?
 
72
      ;;
 
73
    -v|--v*)
 
74
      echo "py-compile $scriptversion"
 
75
      exit $?
 
76
      ;;
 
77
    *)
 
78
      files="$files $1"
 
79
      ;;
 
80
  esac
 
81
  shift
 
82
done
63
83
 
64
 
if [ $# = 0 ]; then
 
84
if test -z "$files"; then
65
85
    echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
66
86
    exit 1
67
87
fi
69
89
# if basedir was given, then it should be prepended to filenames before
70
90
# byte compilation.
71
91
if [ -z "$basedir" ]; then
72
 
    trans="path = file"
73
 
else
74
 
    trans="path = os.path.join('$basedir', file)"
 
92
    pathtrans="path = file"
 
93
else
 
94
    pathtrans="path = os.path.join('$basedir', file)"
 
95
fi
 
96
 
 
97
# if destdir was given, then it needs to be prepended to the filename to
 
98
# byte compile but not go into the compiled file.
 
99
if [ -z "$destdir" ]; then
 
100
    filetrans="filepath = path"
 
101
else
 
102
    filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
75
103
fi
76
104
 
77
105
$PYTHON -c "
78
106
import sys, os, string, py_compile
79
107
 
80
 
files = '''$*'''
 
108
files = '''$files'''
 
109
 
81
110
print 'Byte-compiling python modules...'
82
111
for file in string.split(files):
83
 
    $trans
84
 
    if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
 
112
    $pathtrans
 
113
    $filetrans
 
114
    if not os.path.exists(filepath) or not (len(filepath) >= 3
 
115
                                            and filepath[-3:] == '.py'):
85
116
        continue
86
117
    print file,
87
118
    sys.stdout.flush()
88
 
    py_compile.compile(path)
 
119
    py_compile.compile(filepath, filepath + 'c', path)
89
120
print" || exit $?
90
121
 
91
122
# this will fail for python < 1.5, but that doesn't matter ...
92
123
$PYTHON -O -c "
93
124
import sys, os, string, py_compile
94
125
 
95
 
files = '''$*'''
 
126
files = '''$files'''
96
127
print 'Byte-compiling python modules (optimized versions) ...'
97
128
for file in string.split(files):
98
 
    $trans
99
 
    if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
 
129
    $pathtrans
 
130
    $filetrans
 
131
    if not os.path.exists(filepath) or not (len(filepath) >= 3
 
132
                                            and filepath[-3:] == '.py'):
100
133
        continue
101
134
    print file,
102
135
    sys.stdout.flush()
103
 
    py_compile.compile(path)
 
136
    py_compile.compile(filepath, filepath + 'o', path)
104
137
print" 2>/dev/null || :
105
138
 
106
139
# Local Variables: