use of org.python.pydev.shared_core.utils.IProcessInfo in project Pydev by fabioz.
the class ProcessListWin32 method parseListTasks.
public IProcessInfo[] parseListTasks(InputStreamReader reader) {
BufferedReader br = new BufferedReader(reader);
CSVReader csvReader = new CSVReader(br);
List<ProcessInfo> processList = new ArrayList<>();
String[] next;
do {
try {
next = csvReader.readNext();
if (next != null) {
int pid = Integer.parseInt(next[1]);
String name = StringUtils.join(" - ", next[0], next[next.length - 1]);
processList.add(new ProcessInfo(pid, name));
}
} catch (IOException e) {
break;
}
} while (next != null);
return processList.toArray(new IProcessInfo[processList.size()]);
}
use of org.python.pydev.shared_core.utils.IProcessInfo in project Pydev by fabioz.
the class ProcessListWin32Internal method getProcessList.
@Override
public IProcessInfo[] getProcessList() {
Process p = null;
String command = null;
InputStream in = null;
Bundle bundle = Platform.getBundle(SharedCorePlugin.SHARED_CORE_PLUGIN_ID);
IProcessInfo[] procInfos = NOPROCESS;
try {
File file;
IPath relative = new Path("win32").addTrailingSeparator().append("listtasks.exe");
file = BundleUtils.getRelative(relative, bundle);
if (file != null && file.exists()) {
command = FileUtils.getFileAbsolutePath(file);
if (command != null) {
try {
p = ProcessUtils.createProcess(new String[] { command }, null, null);
in = p.getInputStream();
InputStreamReader reader = new InputStreamReader(in);
procInfos = parseListTasks(reader);
} finally {
if (in != null) {
in.close();
}
if (p != null) {
p.destroy();
}
}
}
}
} catch (IOException e) {
}
return procInfos;
}
use of org.python.pydev.shared_core.utils.IProcessInfo in project Pydev by fabioz.
the class ProcessListWin32Internal method parseListTasks.
public IProcessInfo[] parseListTasks(InputStreamReader reader) {
BufferedReader br = new BufferedReader(reader);
List<IProcessInfo> processList = new ArrayList<>();
try {
String line;
while ((line = br.readLine()) != null) {
int tab = line.indexOf('\t');
if (tab != -1) {
String proc = line.substring(0, tab).trim();
String name = line.substring(tab).trim();
if (proc.length() > 0 && name.length() > 0) {
try {
int pid = Integer.parseInt(proc);
processList.add(new ProcessInfo(pid, name));
} catch (NumberFormatException e) {
}
}
}
}
} catch (IOException e) {
}
return processList.toArray(new IProcessInfo[processList.size()]);
}
use of org.python.pydev.shared_core.utils.IProcessInfo in project Pydev by fabioz.
the class ProcessListLinux method getProcessList.
/**
* Insert the method's description here.
* @see IProcessList#getProcessList
*/
@Override
public IProcessInfo[] getProcessList() {
// $NON-NLS-1$
File proc = new File("/proc");
File[] pidFiles = null;
// We are only interested in the pid so filter the rest out.
try {
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
boolean isPID = false;
try {
Integer.parseInt(name);
isPID = true;
} catch (NumberFormatException e) {
}
return isPID;
}
};
pidFiles = proc.listFiles(filter);
} catch (SecurityException e) {
}
ProcessInfo[] processInfo = empty;
if (pidFiles != null) {
processInfo = new ProcessInfo[pidFiles.length];
for (int i = 0; i < pidFiles.length; i++) {
// $NON-NLS-1$
File cmdLine = new File(pidFiles[i], "cmdline");
String name = FileUtils.getFileContents(cmdLine).replace('\0', ' ');
if (name.length() == 0) {
// $NON-NLS-1$
name = "Unknown";
}
processInfo[i] = new ProcessInfo(pidFiles[i].getName(), name);
}
} else {
pidFiles = new File[0];
}
return processInfo;
}
use of org.python.pydev.shared_core.utils.IProcessInfo in project Pydev by fabioz.
the class AttachToProcess method doIt.
protected void doIt() throws Exception {
IProcessList processList = PlatformUtils.getProcessList();
IProcessInfo[] processList2 = processList.getProcessList();
TreeNode<Object> root = new TreeNode<Object>(null, null);
for (IProcessInfo iProcessInfo : processList2) {
new TreeNode<>(root, iProcessInfo);
}
TreeNode<Object> element = new Select1Dialog() {
@Override
protected String getInitialFilter() {
return "*python*";
}
@Override
protected ILabelProvider getLabelProvider() {
return new TreeNodeLabelProvider() {
@Override
public Image getImage(Object element) {
return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PUBLIC_ATTR_ICON));
}
@SuppressWarnings("unchecked")
@Override
public String getText(Object element) {
if (element == null) {
return "null";
}
TreeNode<Object> node = (TreeNode<Object>) element;
Object data = node.data;
if (data instanceof IProcessInfo) {
IProcessInfo iProcessInfo = (IProcessInfo) data;
return iProcessInfo.getPid() + " - " + iProcessInfo.getName();
}
return "Unexpected: " + data;
}
};
}
}.selectElement(root);
if (element != null) {
IProcessInfo p = (IProcessInfo) element.data;
int pid = p.getPid();
if (!PydevRemoteDebuggerServer.isRunning()) {
// I.e.: the remote debugger server must be on so that we can attach to it.
PydevRemoteDebuggerServer.startServer();
}
// Select interpreter
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IInterpreterManager interpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
if (interpreterManager == null) {
MessageDialog.openError(workbenchWindow.getShell(), "No interpreter manager.", "No interpreter manager was available for attaching to a process.");
}
IInterpreterInfo[] interpreters = interpreterManager.getInterpreterInfos();
if (interpreters == null || interpreters.length == 0) {
MessageDialog.openError(workbenchWindow.getShell(), "No interpreters for creating console", "An interpreter that matches the architecture of the target process must be configured in the interpreter preferences.");
return;
}
SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(workbenchWindow, interpreters, "Select interpreter which matches the architecture of the target process (i.e.: 32/64 bits).", false);
int open = listDialog.open();
if (open != ListDialog.OK || listDialog.getResult().length != 1) {
return;
}
Object[] result = listDialog.getResult();
IInterpreterInfo interpreter;
if (result == null || result.length == 0) {
interpreter = interpreters[0];
} else {
interpreter = ((IInterpreterInfo) result[0]);
}
SimplePythonRunner runner = new SimplePythonRunner();
IPath relative = new Path("pysrc").append("pydevd_attach_to_process").append("attach_pydevd.py");
String script = CorePlugin.getBundleInfo().getRelativePath(relative).getAbsolutePath();
String[] args = new String[] { "--port", "" + DebugPluginPrefsInitializer.getRemoteDebuggerPort(), "--pid", "" + pid, "--protocol", "http" };
IPythonNature nature = new SystemPythonNature(interpreterManager, interpreter);
String[] s = SimplePythonRunner.preparePythonCallParameters(interpreter.getExecutableOrJar(), script, args);
Tuple<Process, String> run = runner.run(s, (File) null, nature, new NullProgressMonitor());
if (run.o1 != null) {
ShowProcessOutputDialog dialog = new ShowProcessOutputDialog(UIUtils.getActiveShell(), run.o1);
dialog.open();
}
}
}
Aggregations