From: <nr...@us...> - 2008-08-29 20:41:43
|
Revision: 5270 http://jython.svn.sourceforge.net/jython/?rev=5270&view=rev Author: nriley Date: 2008-08-29 20:41:41 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Revert stubbed out bit from r5210. Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2008-08-29 19:58:06 UTC (rev 5269) +++ trunk/jython/src/org/python/util/jython.java 2008-08-29 20:41:41 UTC (rev 5270) @@ -212,7 +212,7 @@ } catch (java.io.FileNotFoundException e) { throw Py.IOError(e); } - if (false) {//(imp.load("os").__getattr__("isatty").__call__(Py.java2py(file.getFD())).__nonzero__()) { + if (imp.load("os").__getattr__("isatty").__call__(Py.java2py(file.getFD())).__nonzero__()) { opts.interactive = true; interp.interact(null, new PyFile(file)); System.exit(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-29 21:08:55
|
Revision: 5271 http://jython.svn.sourceforge.net/jython/?rev=5271&view=rev Author: pjenvey Date: 2008-08-29 21:08:52 +0000 (Fri, 29 Aug 2008) Log Message: ----------- PEP 338 (jython -m mod) support patch from Georgy Berdyshev Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2008-08-29 20:41:41 UTC (rev 5270) +++ trunk/jython/src/org/python/util/jython.java 2008-08-29 21:08:52 UTC (rev 5271) @@ -26,11 +26,12 @@ public class jython { private static final String COPYRIGHT = - "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information."; + "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information."; - private static final String usage = - // "usage: jython [option] ... [-c cmd | -m mod | file | -] [arg] ...\n" + - "usage: jython [option] ... [-c cmd | file | -] [arg] ...\n" + + static final String usageHeader = + "usage: jython [option] ... [-c cmd | -m mod | file | -] [arg] ...\n"; + + private static final String usage = usageHeader + "Options and arguments:\n" + //(and corresponding environment variables):\n" + "-c cmd : program passed in as string (terminates option list)\n" + //"-d : debug output from parser (also PYTHONDEBUG=x)\n" + @@ -120,7 +121,10 @@ System.err.println(InteractiveConsole.getDefaultBanner()); System.exit(0); } - System.err.println(usage); + if (!opts.runModule) { + System.err.println(usage); + } + int exitcode = opts.help ? 0 : -1; System.exit(exitcode); } @@ -147,14 +151,14 @@ } // Print banner and copyright information (or not) - if (opts.interactive && opts.notice) { + if (opts.interactive && opts.notice && !opts.runModule) { System.err.println(InteractiveConsole.getDefaultBanner()); } if (Options.importSite) { try { imp.load("site"); - if (opts.interactive && opts.notice) { + if (opts.interactive && opts.notice && !opts.runModule) { System.err.println(COPYRIGHT); } } catch (PyException pye) { @@ -253,6 +257,21 @@ Py.printException(t); } } + + if (opts.moduleName != null) { + // PEP 338 - Execute module as a script + try { + interp.exec("import runpy"); + interp.set("name", Py.newString(opts.moduleName)); + interp.exec("runpy.run_module(name, run_name='__main__', alter_sys=True)"); + interp.cleanup(); + System.exit(0); + } catch (Throwable t) { + Py.printException(t); + interp.cleanup(); + System.exit(0); + } + } } if (opts.fixInteractive || (opts.filename == null && opts.command == null)) { @@ -308,6 +327,7 @@ { public String filename; public boolean jar, interactive, notice; + public boolean runModule; public boolean fixInteractive; public boolean help, version; public String[] argv; @@ -316,11 +336,13 @@ public java.util.Vector warnoptions = new java.util.Vector(); public String encoding; public String division; + public String moduleName; public CommandLineOptions() { filename = null; jar = fixInteractive = false; interactive = notice = true; + runModule = false; properties = new java.util.Properties(); help = version = false; } @@ -412,6 +434,20 @@ else division = args[++index]; } + else if (arg.startsWith("-m")) { + runModule = true; + if ((index + 1) < args.length) { + moduleName = args[++index]; + } else { + System.err.println("Argument expected for the -m option"); + System.err.print(jython.usageHeader); + System.err.println("Try `jython -h' for more information."); + return false; + } + if (!fixInteractive) { + interactive = false; + } + } else { String opt = args[index]; if (opt.startsWith("--")) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-09-05 16:21:58
|
Revision: 5290 http://jython.svn.sourceforge.net/jython/?rev=5290&view=rev Author: zyasoft Date: 2008-09-05 16:21:55 +0000 (Fri, 05 Sep 2008) Log Message: ----------- PySystemState.warnoptions was not initialized before adding to it in the processing of the -W option. Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2008-09-05 03:36:04 UTC (rev 5289) +++ trunk/jython/src/org/python/util/jython.java 2008-09-05 16:21:55 UTC (rev 5290) @@ -6,6 +6,8 @@ import java.io.FileInputStream; import java.io.InputStream; import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -14,6 +16,7 @@ import org.python.core.PyCode; import org.python.core.PyException; import org.python.core.PyFile; +import org.python.core.PyList; import org.python.core.PyModule; import org.python.core.PyString; import org.python.core.PyStringMap; @@ -136,8 +139,8 @@ // Now create an interpreter InteractiveConsole interp = newInterpreter(); - for (int i = 0; i < opts.warnoptions.size(); i++) { - String wopt = (String) opts.warnoptions.elementAt(i); + PySystemState.warnoptions = new PyList(); + for (String wopt : opts.warnoptions) { PySystemState.warnoptions.append(new PyString(wopt)); } @@ -333,7 +336,7 @@ public String[] argv; public java.util.Properties properties; public String command; - public java.util.Vector warnoptions = new java.util.Vector(); + public List<String> warnoptions = new ArrayList<String>(); public String encoding; public String division; public String moduleName; @@ -403,7 +406,7 @@ break; } else if (arg.equals("-W")) { - warnoptions.addElement(args[++index]); + warnoptions.add(args[++index]); } else if (arg.equals("-C")) { encoding = args[++index]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-01-31 02:20:53
|
Revision: 6003 http://jython.svn.sourceforge.net/jython/?rev=6003&view=rev Author: pjenvey Date: 2009-01-31 02:20:48 +0000 (Sat, 31 Jan 2009) Log Message: ----------- make --version resemble CPython Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-01-29 20:51:21 UTC (rev 6002) +++ trunk/jython/src/org/python/util/jython.java 2009-01-31 02:20:48 UTC (rev 6003) @@ -11,6 +11,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import org.python.Version; import org.python.core.Options; import org.python.core.Py; import org.python.core.PyCode; @@ -119,8 +120,7 @@ CommandLineOptions opts = new CommandLineOptions(); if (!opts.parse(args)) { if (opts.version) { - PySystemState.determinePlatform(System.getProperties()); - System.err.println(InteractiveConsole.getDefaultBanner()); + System.err.println("Jython " + Version.PY_VERSION); System.exit(0); } if (!opts.runModule) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-03-31 23:30:59
|
Revision: 6141 http://jython.svn.sourceforge.net/jython/?rev=6141&view=rev Author: otmarhumbel Date: 2009-03-31 23:30:57 +0000 (Tue, 31 Mar 2009) Log Message: ----------- gracefully fall back into the old interactive console if jline classes are not on the classpath Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-03-31 19:41:07 UTC (rev 6140) +++ trunk/jython/src/org/python/util/jython.java 2009-03-31 23:30:57 UTC (rev 6141) @@ -312,7 +312,7 @@ String interpClass = PySystemState.registry.getProperty("python.console", "org.python.util.InteractiveConsole"); return (InteractiveConsole)Class.forName(interpClass).newInstance(); - } catch (Exception e) { + } catch (Throwable t) { return new InteractiveConsole(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-23 07:45:29
|
Revision: 6258 http://jython.svn.sourceforge.net/jython/?rev=6258&view=rev Author: pjenvey Date: 2009-04-23 07:45:20 +0000 (Thu, 23 Apr 2009) Log Message: ----------- omit the -h usage from an invalid -c argument (as -m does) consequently this fixes test_cmd_line blocking on Windows. subprocess w/ stderr=PIPE seems to have issues there Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-04-23 07:38:49 UTC (rev 6257) +++ trunk/jython/src/org/python/util/jython.java 2009-04-23 07:45:20 UTC (rev 6258) @@ -126,7 +126,7 @@ System.err.println("Jython " + Version.PY_VERSION); System.exit(0); } - if (!opts.runModule) { + if (!opts.runCommand && !opts.runModule) { System.err.println(usage); } @@ -339,7 +339,7 @@ { public String filename; public boolean jar, interactive, notice; - public boolean runModule; + public boolean runCommand, runModule; public boolean fixInteractive; public boolean help, version; public String[] argv; @@ -409,6 +409,7 @@ Options.importSite = false; } else if (arg.equals("-c")) { + runCommand = true; if (arg.length() > 2) { command = arg.substring(2); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-09 21:07:07
|
Revision: 6319 http://jython.svn.sourceforge.net/jython/?rev=6319&view=rev Author: pjenvey Date: 2009-05-09 21:06:49 +0000 (Sat, 09 May 2009) Log Message: ----------- coding standards Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-05-08 06:41:51 UTC (rev 6318) +++ trunk/jython/src/org/python/util/jython.java 2009-05-09 21:06:49 UTC (rev 6319) @@ -2,8 +2,9 @@ package org.python.util; import java.io.File; -import java.io.IOException; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.List; @@ -29,8 +30,7 @@ import org.python.modules._systemrestart; import org.python.modules.thread.thread; -public class jython -{ +public class jython { private static final String COPYRIGHT = "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information."; @@ -64,32 +64,32 @@ "- : program read from stdin (default; interactive mode if a tty)\n" + "arg ... : arguments passed to program in sys.argv[1:]\n" + "Other environment variables:\n" + - "JYTHONPATH: '" + java.io.File.pathSeparator + "'-separated list of directories prefixed to the default module\n" + + "JYTHONPATH: '" + File.pathSeparator + + "'-separated list of directories prefixed to the default module\n" + " search path. The result is sys.path."; public static boolean shouldRestart; public static void runJar(String filename) { - // TBD: this is kind of gross because a local called `zipfile' just - // magically shows up in the module's globals. Either `zipfile' - // should be called `__zipfile__' or (preferrably, IMO), __run__.py - // should be imported and a main() function extracted. This - // function should be called passing zipfile in as an argument. + // TBD: this is kind of gross because a local called `zipfile' just magically + // shows up in the module's globals. Either `zipfile' should be called + // `__zipfile__' or (preferrably, IMO), __run__.py should be imported and a main() + // function extracted. This function should be called passing zipfile in as an + // argument. // - // Probably have to keep this code around for backwards - // compatibility (?) + // Probably have to keep this code around for backwards compatibility (?) try { ZipFile zip = new ZipFile(filename); ZipEntry runit = zip.getEntry("__run__.py"); - if (runit == null) + if (runit == null) { throw Py.ValueError("jar file missing '__run__.py'"); + } PyStringMap locals = new PyStringMap(); - // Stripping the stuff before the last File.separator fixes Bug - // #931129 by keeping illegal characters out of the generated - // proxy class name + // Stripping the stuff before the last File.separator fixes Bug #931129 by + // keeping illegal characters out of the generated proxy class name int beginIndex; if ((beginIndex = filename.lastIndexOf(File.separator)) != -1) { filename = filename.substring(beginIndex + 1); @@ -151,7 +151,7 @@ opts.interactive = ((PyFile)Py.defaultSystemState.stdin).isatty(); if (!opts.interactive) { PySystemState systemState = Py.getSystemState(); - systemState.ps1 = systemState.ps2 = new PyString(); + systemState.ps1 = systemState.ps2 = Py.EmptyString; } } @@ -176,13 +176,13 @@ } if (opts.division != null) { - if ("old".equals(opts.division)) + if ("old".equals(opts.division)) { Options.divisionWarning = 0; - else if ("warn".equals(opts.division)) + } else if ("warn".equals(opts.division)) { Options.divisionWarning = 1; - else if ("warnall".equals(opts.division)) + } else if ("warnall".equals(opts.division)) { Options.divisionWarning = 2; - else if ("new".equals(opts.division)) { + } else if ("new".equals(opts.division)) { Options.Qnew = true; interp.cflags.setFlag(CodeFlag.CO_FUTURE_DIVISION); } @@ -204,8 +204,7 @@ runJar(opts.filename); } else if (opts.filename.equals("-")) { try { - interp.locals.__setitem__(new PyString("__file__"), - new PyString("<stdin>")); + interp.locals.__setitem__(new PyString("__file__"), new PyString("<stdin>")); interp.execfile(System.in, "<stdin>"); } catch (Throwable t) { Py.printException(t); @@ -217,8 +216,8 @@ FileInputStream file; try { - file = new java.io.FileInputStream(new RelativeFile(opts.filename)); - } catch (java.io.FileNotFoundException e) { + file = new FileInputStream(new RelativeFile(opts.filename)); + } catch (FileNotFoundException e) { throw Py.IOError(e); } if (FileUtil.isatty(file.getFD())) { @@ -228,9 +227,9 @@ } else { interp.execfile(file, opts.filename); } - } catch(Throwable t) { - if (t instanceof PyException && - ((PyException)t).match(_systemrestart.SystemRestart)) { + } catch (Throwable t) { + if (t instanceof PyException + && ((PyException)t).match(_systemrestart.SystemRestart)) { // Shutdown this instance... shouldRestart = true; shutdownInterpreter(); @@ -248,12 +247,11 @@ } } else { - // if there was no file name on the command line, then "" is - // the first element on sys.path. This is here because if - // there /was/ a filename on the c.l., and say the -i option - // was given, sys.path[0] will have gotten filled in with the - // dir of the argument filename. - Py.getSystemState().path.insert(0, new PyString("")); + // if there was no file name on the command line, then "" is the first element + // on sys.path. This is here because if there /was/ a filename on the c.l., + // and say the -i option was given, sys.path[0] will have gotten filled in + // with the dir of the argument filename. + Py.getSystemState().path.insert(0, Py.EmptyString); if (opts.command != null) { try { @@ -285,10 +283,11 @@ opts.encoding = PySystemState.registry.getProperty( "python.console.encoding", null); } - if(opts.encoding != null) { - if(!Charset.isSupported(opts.encoding)) { + if (opts.encoding != null) { + if (!Charset.isSupported(opts.encoding)) { System.err.println(opts.encoding - + " is not a supported encoding on this JVM, so it can't be used in python.console.encoding."); + + " is not a supported encoding on this JVM, so it can't " + + "be used in python.console.encoding."); System.exit(1); } interp.cflags.encoding = opts.encoding; @@ -311,8 +310,9 @@ */ private static InteractiveConsole newInterpreter() { try { - String interpClass = PySystemState.registry.getProperty("python.console", - "org.python.util.InteractiveConsole"); + String interpClass = + PySystemState.registry.getProperty("python.console", + "org.python.util.InteractiveConsole"); return (InteractiveConsole)Class.forName(interpClass).newInstance(); } catch (Throwable t) { return new InteractiveConsole(); @@ -335,8 +335,7 @@ } } -class CommandLineOptions -{ +class CommandLineOptions { public String filename; public boolean jar, interactive, notice; public boolean runCommand, runModule; @@ -363,57 +362,50 @@ properties.put(key, value); try { System.setProperty(key, value); + } catch (SecurityException e) { + // continue } - catch (SecurityException e) {} } public boolean parse(String[] args) { - int index=0; + int index = 0; + while (index < args.length && args[index].startsWith("-")) { String arg = args[index]; if (arg.equals("-h") || arg.equals("-?") || arg.equals("--help")) { help = true; return false; - } - else if (arg.equals("-V") || arg.equals("--version")) { + } else if (arg.equals("-V") || arg.equals("--version")) { version = true; return false; - } - else if (arg.equals("-")) { - if (!fixInteractive) + } else if (arg.equals("-")) { + if (!fixInteractive) { interactive = false; + } filename = "-"; - } - else if (arg.equals("-i")) { + } else if (arg.equals("-i")) { fixInteractive = true; interactive = true; - } - else if (arg.equals("-jar")) { + } else if (arg.equals("-jar")) { jar = true; - if (!fixInteractive) + if (!fixInteractive) { interactive = false; - } - else if (arg.equals("-u")) { + } + } else if (arg.equals("-u")) { Options.unbuffered = true; - } - else if (arg.equals("-v")) { + } else if (arg.equals("-v")) { Options.verbose++; - } - else if (arg.equals("-vv")) { + } else if (arg.equals("-vv")) { Options.verbose += 2; - } - else if (arg.equals("-vvv")) { + } else if (arg.equals("-vvv")) { Options.verbose +=3 ; - } - else if (arg.equals("-S")) { + } else if (arg.equals("-S")) { Options.importSite = false; - } - else if (arg.equals("-c")) { + } else if (arg.equals("-c")) { runCommand = true; if (arg.length() > 2) { command = arg.substring(2); - } - else if ((index + 1) < args.length) { + } else if ((index + 1) < args.length) { command = args[++index]; } else { System.err.println("Argument expected for the -c option"); @@ -426,19 +418,14 @@ } index++; break; - } - else if (arg.equals("-W")) { + } else if (arg.equals("-W")) { warnoptions.add(args[++index]); - } - else if (arg.equals("-C")) { + } else if (arg.equals("-C")) { encoding = args[++index]; - } - else if (arg.equals("-E")) { - // XXX: accept -E (ignore environment variables) to be - // compatiable with CPython. do nothing for now (we - // could ignore the registry) - } - else if (arg.startsWith("-D")) { + } else if (arg.equals("-E")) { + // XXX: accept -E (ignore environment variables) to be compatiable with + // CPython. do nothing for now (we could ignore the registry) + } else if (arg.startsWith("-D")) { String key = null; String value = null; int equals = arg.indexOf("="); @@ -446,25 +433,22 @@ String arg2 = args[++index]; key = arg.substring(2, arg.length()); value = arg2; - } - else { + } else { key = arg.substring(2, equals); - value = arg.substring(equals+1, arg.length()); + value = arg.substring(equals + 1, arg.length()); } setProperty(key, value); - } - else if (arg.startsWith("-Q")) { - if (arg.length() > 2) + } else if (arg.startsWith("-Q")) { + if (arg.length() > 2) { division = arg.substring(2); - else + } else { division = args[++index]; - } - else if (arg.startsWith("-m")) { + } + } else if (arg.startsWith("-m")) { runModule = true; if (arg.length() > 2) { moduleName = arg.substring(2); - } - else if ((index + 1) < args.length) { + } else if ((index + 1) < args.length) { moduleName = args[++index]; } else { System.err.println("Argument expected for the -m option"); @@ -477,20 +461,20 @@ } index++; - int n = args.length-index+1; + int n = args.length - index + 1; argv = new String[n]; argv[0] = moduleName; for (int i = 1; index < args.length; i++, index++) { argv[i] = args[index]; } return true; - } - else { + } else { String opt = args[index]; - if (opt.startsWith("--")) + if (opt.startsWith("--")) { opt = opt.substring(2); - else if (opt.startsWith("-")) + } else if (opt.startsWith("-")) { opt = opt.substring(1); + } System.err.println("Unknown option: " + opt); return false; } @@ -499,24 +483,26 @@ notice = interactive; if (filename == null && index < args.length && command == null) { filename = args[index++]; - if (!fixInteractive) + if (!fixInteractive) { interactive = false; + } notice = false; } - if (command != null) + if (command != null) { notice = false; + } - int n = args.length-index+1; + int n = args.length - index + 1; argv = new String[n]; - //new String[args.length-index+1]; - if (filename != null) + if (filename != null) { argv[0] = filename; - else if (command != null) + } else if (command != null) { argv[0] = "-c"; - else + } else { argv[0] = ""; + } - for(int i=1; i<n; i++, index++) { + for (int i = 1; i < n; i++, index++) { argv[i] = args[index]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-05-16 02:02:23
|
Revision: 6352 http://jython.svn.sourceforge.net/jython/?rev=6352&view=rev Author: pjenvey Date: 2009-05-16 01:58:51 +0000 (Sat, 16 May 2009) Log Message: ----------- refactor Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-05-16 01:14:07 UTC (rev 6351) +++ trunk/jython/src/org/python/util/jython.java 2009-05-16 01:58:51 UTC (rev 6352) @@ -317,18 +317,19 @@ * unexpected behavior with the std file streams. */ private static InteractiveConsole newInterpreter(boolean interactiveStdin) { - if (interactiveStdin) { - String interpClass = PySystemState.registry.getProperty("python.console", ""); - if (interpClass.length() > 0) { - try { - return (InteractiveConsole)Class.forName(interpClass).newInstance(); - } catch (Throwable t) { - // fall through - } + if (!interactiveStdin) { + return new InteractiveConsole(); + } + + String interpClass = PySystemState.registry.getProperty("python.console", ""); + if (interpClass.length() == 0) { + try { + return (InteractiveConsole)Class.forName(interpClass).newInstance(); + } catch (Throwable t) { + // fall through } - return new JLineConsole(); } - return new InteractiveConsole(); + return new JLineConsole(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2009-08-06 20:17:17
|
Revision: 6634 http://jython.svn.sourceforge.net/jython/?rev=6634&view=rev Author: leosoto Date: 2009-08-06 20:17:09 +0000 (Thu, 06 Aug 2009) Log Message: ----------- Handle exceptions when running a JAR file through -jar cmdline switch. Fixes http://bugs.jython.org/issue1405 Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-08-06 05:10:26 UTC (rev 6633) +++ trunk/jython/src/org/python/util/jython.java 2009-08-06 20:17:09 UTC (rev 6634) @@ -70,6 +70,18 @@ public static boolean shouldRestart; + /** + * Runs a JAR file, by executing the code found in the file __run__.py, + * which should be in the root of the JAR archive. + * + * Note that the __name__ is set to the base name of the JAR file and not + * to "__main__" (for historic reasons). + * + * This method do NOT handle exceptions. the caller SHOULD handle any + * (Py)Exceptions thrown by the code. + * + * @param filename The path to the filename to run. + */ public static void runJar(String filename) { // TBD: this is kind of gross because a local called `zipfile' just magically // shows up in the module's globals. Either `zipfile' should be called @@ -201,7 +213,12 @@ } Py.getSystemState().path.insert(0, new PyString(path)); if (opts.jar) { - runJar(opts.filename); + try { + runJar(opts.filename); + } catch (Throwable t) { + Py.printException(t); + System.exit(-1); + } } else if (opts.filename.equals("-")) { try { interp.locals.__setitem__(new PyString("__file__"), new PyString("<stdin>")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-10-19 03:02:57
|
Revision: 7161 http://jython.svn.sourceforge.net/jython/?rev=7161&view=rev Author: zyasoft Date: 2010-10-19 03:02:51 +0000 (Tue, 19 Oct 2010) Log Message: ----------- Fixed test for console interactivity. This allows ipython and similar readline using scripts to run without -i. Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2010-10-18 02:19:18 UTC (rev 7160) +++ trunk/jython/src/org/python/util/jython.java 2010-10-19 03:02:51 UTC (rev 7161) @@ -157,7 +157,7 @@ PySystemState systemState = Py.getSystemState(); // Decide if stdin is interactive - if (!opts.fixInteractive && opts.interactive) { + if (!opts.fixInteractive || opts.interactive) { opts.interactive = ((PyFile)Py.defaultSystemState.stdin).isatty(); if (!opts.interactive) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-12-24 23:17:13
|
Revision: 7177 http://jython.svn.sourceforge.net/jython/?rev=7177&view=rev Author: pjenvey Date: 2010-12-24 23:17:07 +0000 (Fri, 24 Dec 2010) Log Message: ----------- don't force System.exit on a successful main thread exit, so we don't stop non-daemon threads Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2010-12-24 02:36:59 UTC (rev 7176) +++ trunk/jython/src/org/python/util/jython.java 2010-12-24 23:17:07 UTC (rev 7177) @@ -160,7 +160,6 @@ if (!opts.fixInteractive || opts.interactive) { opts.interactive = ((PyFile)Py.defaultSystemState.stdin).isatty(); if (!opts.interactive) { - systemState.ps1 = systemState.ps2 = Py.EmptyString; } } @@ -243,7 +242,7 @@ if (PosixModule.getPOSIX().isatty(file.getFD())) { opts.interactive = true; interp.interact(null, new PyFile(file)); - System.exit(0); + return; } else { interp.execfile(file, opts.filename); } @@ -294,7 +293,7 @@ interp.set("name", Py.newString(opts.moduleName)); interp.exec("runpy.run_module(name, run_name='__main__', alter_sys=True)"); interp.cleanup(); - System.exit(0); + return; } catch (Throwable t) { Py.printException(t); interp.cleanup(); @@ -323,9 +322,6 @@ } } interp.cleanup(); - if (opts.fixInteractive || opts.interactive) { - System.exit(0); - } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |