Search in sources :

Example 1 with PydevConsoleLaunchInfo

use of org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo in project ibex_gui by ISISComputingGroup.

the class GeniePythonConsoleFactory method createGeniePydevInterpreter.

/**
 * Creates a Genie Python Interpreter.
 *
 * @return Interpreter
 * @throws Exception
 *             can throw several different exceptions
 */
PydevConsoleInterpreter createGeniePydevInterpreter() throws Exception {
    IInterpreterManager manager = InterpreterManagersAPI.getPythonInterpreterManager();
    IInterpreterInfo interpreterInfo = manager.createInterpreterInfo(PreferenceSupplier.getPythonPath(), monitor, false);
    PydevIProcessFactory iprocessFactory = new PydevIProcessFactory();
    PydevConsoleLaunchInfo launchAndProcess = iprocessFactory.createLaunch(manager, interpreterInfo, interpreterInfo.getPythonPath(), null, null);
    return createPydevInterpreter(launchAndProcess, null, null);
}
Also used : PydevConsoleLaunchInfo(org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo) PydevIProcessFactory(org.python.pydev.debug.newconsole.env.PydevIProcessFactory) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) IInterpreterManager(org.python.pydev.core.IInterpreterManager)

Example 2 with PydevConsoleLaunchInfo

use of org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo in project Pydev by fabioz.

the class PydevConsoleFactory method createDebugConsole.

/**
 * Create a new Debug Console
 *
 * @param interpreter
 * @param additionalInitialComands
 * @return
 */
private PydevDebugConsole createDebugConsole(ILaunch launch, PyStackFrame frame, String additionalInitialComands, boolean addToManager, boolean bufferedOutput, IPyStackFrameProvider consoleFrameProvider) throws Exception {
    PydevConsoleLaunchInfo launchAndProcess = new PydevConsoleLaunchInfo(null, null, 0, null, frame, null, null, launch != null ? PydevIProcessFactory.getEncodingFromLaunch(launch) : PydevIProcessFactory.getEncodingFromFrame(frame));
    PydevConsoleInterpreter interpreter = createPydevDebugInterpreter(launchAndProcess, bufferedOutput, consoleFrameProvider);
    PydevDebugConsole console = new PydevDebugConsole(interpreter, additionalInitialComands);
    if (addToManager) {
        ScriptConsoleManager manager = ScriptConsoleManager.getInstance();
        manager.add(console, true);
    }
    return console;
}
Also used : PydevConsoleLaunchInfo(org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo) ScriptConsoleManager(org.python.pydev.shared_interactive_console.console.ui.ScriptConsoleManager)

Example 3 with PydevConsoleLaunchInfo

use of org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo in project Pydev by fabioz.

the class PydevConsoleFactory method createDefaultPydevInterpreter.

/**
 * @return A PydevConsoleInterpreter with its communication configured.
 *
 * @throws CoreException
 * @throws IOException
 * @throws UserCanceledException
 */
public static PydevConsoleInterpreter createDefaultPydevInterpreter() throws Exception, UserCanceledException {
    // import sys; sys.ps1=''; sys.ps2=''
    // import sys;print >> sys.stderr, ' '.join([sys.executable, sys.platform, sys.version])
    // print >> sys.stderr, 'PYTHONPATH:'
    // for p in sys.path:
    // print >> sys.stderr,  p
    // 
    // print >> sys.stderr, 'Ok, all set up... Enjoy'
    PydevIProcessFactory iprocessFactory = new PydevIProcessFactory();
    PydevConsoleLaunchInfo launchAndProcess = iprocessFactory.createInteractiveLaunch();
    if (launchAndProcess == null) {
        return null;
    }
    if (launchAndProcess.interpreter != null) {
        return createPydevInterpreter(launchAndProcess, iprocessFactory.getNaturesUsed(), launchAndProcess.encoding);
    } else {
        return createPydevDebugInterpreter(launchAndProcess, true, new AnyPyStackFrameSelected());
    }
}
Also used : PydevConsoleLaunchInfo(org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo) PydevIProcessFactory(org.python.pydev.debug.newconsole.env.PydevIProcessFactory)

Example 4 with PydevConsoleLaunchInfo

use of org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo in project Pydev by fabioz.

the class DjangoShell method run.

@Override
public void run(IAction action) {
    try {
        // this.launchDjangoCommand("shell", false);
        PythonNature nature = PythonNature.getPythonNature(selectedProject);
        if (nature == null) {
            MessageDialog.openError(EditorUtils.getShell(), "PyDev nature not found", "Unable to perform action because the Pydev nature is not properly set.");
            return;
        }
        IPythonPathNature pythonPathNature = nature.getPythonPathNature();
        String settingsModule = null;
        Map<String, String> variableSubstitution = null;
        try {
            variableSubstitution = pythonPathNature.getVariableSubstitution();
            settingsModule = variableSubstitution.get(DjangoConstants.DJANGO_SETTINGS_MODULE);
        } catch (Exception e1) {
            throw new RuntimeException(e1);
        }
        if (settingsModule == null) {
            InputDialog d = new InputDialog(EditorUtils.getShell(), "Settings module", "Please enter the settings module to be used.\n" + "\n" + "Note that it can be edited later in:\np" + "roject properties > pydev pythonpath > string substitution variables.", selectedProject.getName() + ".settings", new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText.length() == 0) {
                        return "Text must be entered.";
                    }
                    for (char c : newText.toCharArray()) {
                        if (c == ' ') {
                            return "Whitespaces not accepted";
                        }
                        if (c != '.' && !Character.isJavaIdentifierPart(c)) {
                            return "Invalid char: " + c;
                        }
                    }
                    return null;
                }
            });
            int retCode = d.open();
            if (retCode == InputDialog.OK) {
                settingsModule = d.getValue();
                variableSubstitution.put(DjangoConstants.DJANGO_SETTINGS_MODULE, settingsModule);
                try {
                    pythonPathNature.setVariableSubstitution(variableSubstitution);
                } catch (Exception e) {
                    Log.log(e);
                }
            }
            if (settingsModule == null) {
                return;
            }
        }
        List<IPythonNature> natures = Collections.singletonList((IPythonNature) nature);
        PydevConsoleFactory consoleFactory = new PydevConsoleFactory();
        PydevConsoleLaunchInfo launchInfo = new PydevIProcessFactory().createLaunch(nature.getRelatedInterpreterManager(), nature.getProjectInterpreter(), nature.getPythonPathNature().getCompleteProjectPythonPath(nature.getProjectInterpreter(), nature.getRelatedInterpreterManager()), nature, natures);
        PydevConsoleInterpreter interpreter = PydevConsoleFactory.createPydevInterpreter(launchInfo, natures, launchInfo.encoding);
        String djangoAdditionalCommands = PydevDebugPlugin.getDefault().getPreferenceStore().getString(PydevConsoleConstants.DJANGO_INTERPRETER_CMDS);
        djangoAdditionalCommands = djangoAdditionalCommands.replace("${" + DjangoConstants.DJANGO_SETTINGS_MODULE + "}", settingsModule);
        // os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fooproject.settings")
        consoleFactory.createConsole(interpreter, djangoAdditionalCommands);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) PydevConsoleInterpreter(org.python.pydev.debug.newconsole.PydevConsoleInterpreter) IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) PydevConsoleFactory(org.python.pydev.debug.newconsole.PydevConsoleFactory) IPythonPathNature(org.python.pydev.core.IPythonPathNature) IPythonNature(org.python.pydev.core.IPythonNature) PydevConsoleLaunchInfo(org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo) PydevIProcessFactory(org.python.pydev.debug.newconsole.env.PydevIProcessFactory) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

PydevConsoleLaunchInfo (org.python.pydev.debug.newconsole.env.PydevIProcessFactory.PydevConsoleLaunchInfo)4 PydevIProcessFactory (org.python.pydev.debug.newconsole.env.PydevIProcessFactory)3 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)1 IInterpreterManager (org.python.pydev.core.IInterpreterManager)1 IPythonNature (org.python.pydev.core.IPythonNature)1 IPythonPathNature (org.python.pydev.core.IPythonPathNature)1 PydevConsoleFactory (org.python.pydev.debug.newconsole.PydevConsoleFactory)1 PydevConsoleInterpreter (org.python.pydev.debug.newconsole.PydevConsoleInterpreter)1 PythonNature (org.python.pydev.plugin.nature.PythonNature)1 ScriptConsoleManager (org.python.pydev.shared_interactive_console.console.ui.ScriptConsoleManager)1