-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjython
executable file
·295 lines (262 loc) · 8.07 KB
/
jython
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env bash
# This file was generated by the Jython installer
# Created on Tue Oct 08 19:38:32 EDT 2013 by kfuruya
JAVA_HOME="/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home"
JYTHON_HOME_FALLBACK="/Users/kfuruya/jython2.5.2"
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# jython.sh - start script for Jython (adapted from jruby.sh)
#
# Environment variables (optional)
#
# JAVA_HOME Java installation directory
#
# JYTHON_HOME Jython installation directory
#
# JYTHON_OPTS Default Jython command line arguments
#
# -----------------------------------------------------------------------------
cygwin=false
# ----- Identify OS we are running under --------------------------------------
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin) darwin=true;;
esac
# ----- Verify and set required environment variables -------------------------
## resolve links - $0 may be a link to home
PRG=$0
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '.*/.*' > /dev/null; then
if expr "$link" : '/' > /dev/null; then
PRG="$link"
else
PRG="`dirname ${PRG}`/${link}"
fi
else
PRG="`dirname $PRG`/$link"
fi
done
if [ -z "$JAVA_HOME" ] ; then
JAVA_CMD=(java)
else
if $cygwin; then
JAVA_HOME=`cygpath -u "$JAVA_HOME"`
fi
JAVA_CMD=("$JAVA_HOME/bin/java")
fi
# try to dynamically determine jython home
# (this script typically resides in jython home, or in the /bin subdirectory)
if [ -z "$JYTHON_HOME" ] ; then
if [ "$PRG" = "./jython" ] ; then
# current dir is the script dir
JYTHON_HOME_1=`pwd`
else
# current dir is not the script dir
JYTHON_HOME_1=`dirname "$PRG"`
fi
if [ -f "$JYTHON_HOME_1"/jython.jar -o -f "$JYTHON_HOME_1"/jython-dev.jar ] ; then
JYTHON_HOME="$JYTHON_HOME_1"
else
JYTHON_HOME=`dirname "$JYTHON_HOME_1"`
fi
if [ ! -f "$JYTHON_HOME"/jython.jar -a ! -f "$JYTHON_HOME"/jython-dev.jar ] ; then
JYTHON_HOME="$JYTHON_HOME_FALLBACK"
fi
fi
if [ -z "$JYTHON_OPTS" ] ; then
JYTHON_OPTS=""
fi
CP_DELIMITER=":"
CP=$JYTHON_HOME/jython-dev.jar
if [ -f "$CP" ] ; then
# add necessary jars for command-line execution
for j in "$JYTHON_HOME"/javalib/*.jar; do
if [ "$CP" ]; then
CP="$CP$CP_DELIMITER$j"
else
CP="$j"
fi
done
elif [ ! -f "$JYTHON_HOME"/jython.jar ] ; then
echo "$0: $JYTHON_HOME contains neither jython-dev.jar nor jython.jar." >&2
echo "Try running this script from the 'bin' directory of an installed Jython or " >&2
echo 'setting $JYTHON_HOME.' >&2
exit 1
else
CP=$JYTHON_HOME/jython.jar
fi
if $cygwin; then
# switch delimiter only after building a Unix style $CP
CP_DELIMITER=";"
CP=`cygpath -p -w "$CP"`
PRG=`cygpath -w "$PRG"`
fi
# ----- Execute the requested command -----------------------------------------
if [ -z "$JAVA_MEM" ] ; then
JAVA_MEM=-Xmx512m
fi
if [ -z "$JAVA_STACK" ]; then
# 32 bit Java 6 needs the stack increased to at least 512k for
# test_cpickle to pass, but we don't want to shrink 64 bit Java's
# default of 1024k
JAVA_STACK=-Xss1024k
fi
JAVA_ENCODING=""
# Split out any -J argument for passing to the JVM.
# Scanning for args is aborted by '--'.
while [ $# -gt 0 ] ; do
case "$1" in
# Stuff after '-J' in this argument goes to JVM
-J*)
val=${1:2}
if [ "${val:0:4}" = "-Xmx" ]; then
JAVA_MEM=$val
elif [ "${val:0:4}" = "-Xss" ]; then
JAVA_STACK=$val
elif [ "${val}" = "" ]; then
$JAVA_CMD -help
echo "(Prepend -J in front of these options when using 'jython' command)"
exit
elif [ "${val}" = "-X" ]; then
$JAVA_CMD -X
echo "(Prepend -J in front of these options when using 'jython' command)"
exit
elif [ "${val}" = "-classpath" ]; then
CP="$CP$CP_DELIMITER$2"
shift
elif [ "${val}" = "-cp" ]; then
CP="$CP$CP_DELIMITER$2"
shift
else
if [ "${val:0:16}" = "-Dfile.encoding=" ]; then
JAVA_ENCODING=$val
fi
java_args=("${java_args[@]}" "${1:2}")
fi
;;
# Match switches that take an argument
-c|-C|-m|-jar|-Q|-W)
if [ $# = 1 ]; then
python_args=("${python_args[@]}" "$1")
else
python_args=("${python_args[@]}" "$1" "$2")
shift
fi;
;;
# Match -Dprop=val type args
-D*)
python_args=("${python_args[@]}" "$1")
;;
# Print the command, don't execute it
--print)
print_requested=true
;;
# Run with the instrumented profiler: http://jiprof.sourceforge.net/
--profile)
rm -f profile.txt # XXX do this?
profile_requested=true
agent_path="$JYTHON_HOME/javalib/profile.jar"
props_path="$JYTHON_HOME/javalib/profile.properties"
if $cygwin; then
agent_path=`cygpath -w "$agent_path"`
props_path=`cygpath -w "$props_path"`
fi
java_args=("${java_args[@]}" -javaagent:"$agent_path"
-Dprofile.properties="$props_path")
;;
# Put Jython on the boot classpath (disables the verifier)
--boot)
boot_requested=true
;;
# Run under JDB
--jdb)
if [ -z "$JAVA_HOME" ] ; then
JAVA_CMD=(jdb)
else
if $cygwin; then
JAVA_HOME=`cygpath -u "$JAVA_HOME"`
fi
JAVA_CMD=("$JAVA_HOME/bin/jdb")
fi
;;
-h|--help)
help_requested=true
python_args=("${python_args[@]}" "$1")
;;
# Abort processing on a double dash
--)
break
;;
# Other opts go to Jython
-*)
python_args=("${python_args[@]}" "$1")
;;
# Abort processing on first non-opt arg
*)
break
;;
esac
shift
done
# Force file.encoding to UTF-8 when on Mac, since Apple JDK defaults to MacRoman (JRUBY-3576)
if [[ $darwin && -z "$JAVA_ENCODING" ]]; then
java_args=("${java_args[@]}" "-Dfile.encoding=UTF-8")
fi
# Append the rest of the arguments
python_args=("${python_args[@]}" "$@")
# Put the python_args back into the position arguments $1, $2 etc
set -- "${python_args[@]}"
JAVA_OPTS="$JAVA_OPTS $JAVA_MEM $JAVA_STACK"
if $cygwin; then
JAVA_HOME=`cygpath --mixed "$JAVA_HOME"`
JYTHON_HOME=`cygpath --mixed "$JYTHON_HOME"`
if [[ ( "${1:0:1}" = "/" ) && ( ( -f "$1" ) || ( -d "$1" )) ]]; then
win_arg=`cygpath -w "$1"`
shift
win_args=("$win_arg" "$@")
set -- "${win_args[@]}"
fi
# fix JLine to use UnixTerminal
stty -icanon min 1 -echo > /dev/null 2>&1
if [ $? = 0 ]; then
JAVA_OPTS="$JAVA_OPTS -Djline.terminal=jline.UnixTerminal"
fi
fi
if [ -n "$profile_requested" -o -z "$boot_requested" ] ; then
[ -n "$profile_requested" ] && echo "Running with instrumented profiler"
java_args=("${java_args[@]}" -classpath "$CP$CP_DELIMITER$CLASSPATH")
else
if [ -z "$help_requested" -a -z "$print_requested" ] ; then
JAVA_CMD=(exec "${JAVA_CMD[@]}")
fi
java_args=("${java_args[@]}" -Xbootclasspath/a:"$CP")
[ -n "$CLASSPATH" ] && java_args=("${java_args[@]}" -classpath "$CLASSPATH")
fi
if [ -n "$print_requested" ] ; then
JAVA_CMD=(echo $JAVA_CMD)
fi
"${JAVA_CMD[@]}" $JAVA_OPTS "${java_args[@]}" -Dpython.home="$JYTHON_HOME" \
-Dpython.executable="$PRG" org.python.util.jython $JYTHON_OPTS "$@"
JYTHON_STATUS=$?
if [ -n "$profile_requested" ] ; then
echo "Profiling results:"
cat profile.txt
elif [ -n "$help_requested" ] ; then
echo "Jython launcher options:" >&2
echo "-Jarg : pass argument through to Java VM (e.g. -J-Xmx512m)" >&2
echo "--jdb : run under JDB" >&2
echo "--print : print the Java command instead of executing it" >&2
echo "--profile: run with the Java Interactive Profiler (http://jiprof.sf.net)" >&2
echo "--boot : put jython on the boot classpath (disables the bytecode verifier)" >&2
echo "-- : pass remaining arguments through to Jython" >&2
echo "Jython launcher environment variables:" >&2
echo "JAVA_HOME : Java installation directory" >&2
echo "JYTHON_HOME: Jython installation directory" >&2
echo "JYTHON_OPTS: default command line arguments" >&2
fi
if $cygwin; then
stty icanon echo > /dev/null 2>&1
fi
exit $JYTHON_STATUS