Home

Jython Shell Script Verbosity @ 2009-08-08 18:24:39
Filed under: Code  Tech  Python  Jython 
Frank made me want to send something back today so I added script debugging to the jython shell script ... Now I should go eat something.

[steve@powerhouse shell]$ ./jython
./jython:  contains neither jython-dev.jar nor jython.jar.
Try running this script from the 'bin' directory of an installed Jython or
setting $JYTHON_HOME.
[steve@powerhouse shell]$ ./jython --verbose
+ JYTHON_SHELL_DEBUG=true
+ cygwin=false
+ case "`uname`" in
++ uname
+ PRG=./jython
+ '[' -h ./jython ']'
+ '[' -z '' ']'
+ JAVA_CMD=(java)
+ '[' -z '' ']'
+ '[' ./jython = ./jython ']'
++ pwd
+ JYTHON_HOME_1=/home/steve/Tech/jython/jython/src/shell
+ '[' -f /home/steve/Tech/jython/jython/src/shell/jython.jar -o -f \
 /home/steve/Tech/jython/jython/src/shell/jython-dev.jar ']'
++ dirname /home/steve/Tech/jython/jython/src/shell
+ JYTHON_HOME=/home/steve/Tech/jython/jython/src
+ '[' '!' -f /home/steve/Tech/jython/jython/src/jython.jar -a '!' \
-f /home/steve/Tech/jython/jython/src/jython-dev.jar ']'
+ JYTHON_HOME=
+ '[' -z '' ']'
+ JYTHON_OPTS=
+ CP_DELIMITER=:
+ CP=/jython-dev.jar
+ '[' -f /jython-dev.jar ']'
+ '[' '!' -f /jython.jar ']'
+ echo './jython:  contains neither jython-dev.jar nor jython.jar.'
./jython:  contains neither jython-dev.jar nor jython.jar.
+ echo 'Try running this script from the '\''bin'\'' directory of an installed Jython or '
Try running this script from the 'bin' directory of an installed Jython or
+ echo 'setting $JYTHON_HOME.'
setting $JYTHON_HOME.
+ exit 1
[steve@powerhouse shell]$


Here is the actual patch if you are interested ....

diff --git a/jython/src/shell/jython b/jython/src/shell/jython
index ff8df4a..41f145b 100755
--- a/jython/src/shell/jython
+++ b/jython/src/shell/jython
@@ -12,9 +12,25 @@
 #
 # -----------------------------------------------------------------------------

-cygwin=false
+# ----- Allow for script debug mode -------------------------------------------
+# Someone may want to know what this script is doing :-) ... allow --verbose/-v
+# Note that this is done way before other options so the user can see the
+# results from the start.
+JYTHON_SHELL_DEBUG=false
+function toggle_debug {
+    ARGS=$1
+    if [[ "$ARGS" =~ "--verbose" ]]; then
+        if [ $JYTHON_SHELL_DEBUG == false ]; then
+            set -x && JYTHON_SHELL_DEBUG=true
+        else
+            set +x && JYTHON_SHELL_DEBUG=false
+        fi
+    fi
+}
+toggle_debug $@

 # ----- Identify OS we are running under --------------------------------------
+cygwin=false
 case "`uname`" in
   CYGWIN*) cygwin=true;;
   Darwin) darwin=true;;
@@ -267,6 +283,7 @@ elif [ -n "$help_requested" ] ; then
   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 "--verbose: shows all information on this shell script as it executes" >&2
   echo "--       : pass remaining arguments through to Jython" >&2
   echo "Jython launcher environment variables:" >&2
   echo "JAVA_HOME  : Java installation directory" >&2
@@ -277,5 +294,6 @@ fi
 if $cygwin; then
   stty icanon echo > /dev/null 2>&1
 fi
-
+# Turn off script debug just incase
+toggle_debug $@
 exit $JYTHON_STATUS

 digg it   seed it   del.icio.us   ma.gnolia
Tags:         Log in to post comments.


 
A Django joint.
© 2007-2009 Steve 'Ashcrow' Milner | Studio7designs | Arbutus Photography