use of org.python.pydev.debug.newconsole.PydevConsoleFactory 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);
}
}
use of org.python.pydev.debug.newconsole.PydevConsoleFactory in project Pydev by fabioz.
the class InteractiveConsoleConfigurationDelegate method launch.
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
// We need to cancel this automatic recreation because we are launching from scratch again
monitor.setCanceled(true);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
PydevConsoleFactory pydevConsoleFactory = new PydevConsoleFactory();
pydevConsoleFactory.openConsole();
}
});
}
Aggregations