// Setup the basic python system state from these options
PySystemState.initialize(PySystemState.getBaseProperties(), opts.properties, opts.argv);
PyList warnoptions = new PyList();
for (String wopt : opts.warnoptions) {
warnoptions.append(new PyString(wopt));
}
Py.getSystemState().setWarnoptions(warnoptions);
PySystemState systemState = Py.getSystemState();
// Decide if stdin is interactive
if (!opts.fixInteractive || opts.interactive) {
opts.interactive = ((PyFile)Py.defaultSystemState.stdin).isatty();
if (!opts.interactive) {
systemState.ps1 = systemState.ps2 = Py.EmptyString;
}
}
// Now create an interpreter
InteractiveConsole interp = newInterpreter(opts.interactive);
systemState.__setattr__("_jy_interpreter", Py.java2py(interp));
// Print banner and copyright information (or not)
if (opts.interactive && opts.notice && !opts.runModule) {
System.err.println(InteractiveConsole.getDefaultBanner());
}
if (Options.importSite) {
try {
imp.load("site");
if (opts.interactive && opts.notice && !opts.runModule) {
System.err.println(COPYRIGHT);
}
} catch (PyException pye) {
if (!pye.match(Py.ImportError)) {
System.err.println("error importing site");
Py.printException(pye);
System.exit(-1);
}
}
}
if (opts.division != null) {
if ("old".equals(opts.division)) {
Options.divisionWarning = 0;
} else if ("warn".equals(opts.division)) {
Options.divisionWarning = 1;
} else if ("warnall".equals(opts.division)) {
Options.divisionWarning = 2;
} else if ("new".equals(opts.division)) {
Options.Qnew = true;
interp.cflags.setFlag(CodeFlag.CO_FUTURE_DIVISION);
}
}
// was there a filename on the command line?
if (opts.filename != null) {
String path;
try {
path = new File(opts.filename).getCanonicalFile().getParent();
} catch (IOException ioe) {
path = new File(opts.filename).getAbsoluteFile().getParent();
}
if (path == null) {
path = "";
}
Py.getSystemState().path.insert(0, new PyString(path));
if (opts.jar) {
try {
runJar(opts.filename);
} catch (Throwable t) {
Py.printException(t);
System.exit(-1);
}
} else if (opts.filename.equals("-")) {
try {
interp.globals.__setitem__(new PyString("__file__"), new PyString("<stdin>"));
interp.execfile(System.in, "<stdin>");
} catch (Throwable t) {
Py.printException(t);
}
} else {
try {
interp.globals.__setitem__(new PyString("__file__"),
new PyString(opts.filename));
FileInputStream file;
try {
file = new FileInputStream(new RelativeFile(opts.filename));
} catch (FileNotFoundException e) {