use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class InterpreterInfo method restorePythonpath.
/**
* Restores the path with the discovered libs
* @param path
*/
public void restorePythonpath(IProgressMonitor monitor) {
FastStringBuffer buffer = new FastStringBuffer();
for (Iterator<String> iter = libs.iterator(); iter.hasNext(); ) {
String folder = iter.next();
buffer.append(folder);
buffer.append("|");
}
restorePythonpath(buffer.toString(), monitor);
}
use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class FileUtilsFileBuffer method getCustomReturnFromFile.
/**
* @param f the file from where we want to get the contents
* @param returnType the class that specifies the return type of this method.
* If null, it'll return in the fastest possible way available.
* Valid options are:
* String.class
* IDocument.class
* FastStringBuffer.class
*
* @return an object with the contents from the file, having the return type
* of the object specified by the parameter returnType.
*/
public static Object getCustomReturnFromFile(java.io.File f, boolean loadIfNotInWorkspace, Class<? extends Object> returnType) throws IOException {
IPath path = Path.fromOSString(FileUtils.getFileAbsolutePath(f));
IDocument doc = getDocFromPath(path);
if (doc != null) {
if (returnType == null || returnType == IDocument.class) {
return doc;
} else if (returnType == String.class) {
return doc.get();
} else if (returnType == FastStringBuffer.class) {
return new FastStringBuffer(doc.get(), 16);
} else {
throw new RuntimeException("Don't know how to treat requested return type: " + returnType);
}
}
if (doc == null && loadIfNotInWorkspace) {
FileInputStream stream = new FileInputStream(f);
try {
String encoding;
try {
encoding = FileUtils.getPythonFileEncoding(f);
} catch (PyUnsupportedEncodingException e) {
// The encoding specified in the file is unsupported
encoding = null;
}
return FileUtils.getStreamContents(stream, encoding, null, returnType);
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (Exception e) {
Log.log(e);
}
}
}
return doc;
}
use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class SimpleRunner method run.
/**
* @return a tuple with the process created and a string representation of the cmdarray.
*/
public Tuple<Process, String> run(String[] cmdarray, File workingDir, IPythonNature nature, IProgressMonitor monitor, ICallback<String[], String[]> updateEnv) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
String executionString = getArgumentsAsStr(cmdarray);
monitor.setTaskName("Executing: " + executionString);
monitor.worked(5);
Process process = null;
try {
monitor.setTaskName("Making pythonpath environment..." + executionString);
String[] envp = null;
if (nature != null) {
// Don't remove as it *should* be updated based on the nature)
envp = getEnvironment(nature, nature.getProjectInterpreter(), nature.getRelatedInterpreterManager());
} else {
// work in Windows by default because the Library/bin and DLLs folder is not in the PATH).
if (PlatformUtils.isWindowsPlatform()) {
envp = getDefaultSystemEnvAsArray(null);
String executable = cmdarray[0];
File f = new File(executable);
File parentFile = f.getParentFile();
for (int i = 0; i < envp.length; i++) {
String string = envp[i];
if (string.startsWith("PATH=")) {
boolean changed = false;
FastStringBuffer buf = new FastStringBuffer(string, 50);
for (File check : new File[] { new File(parentFile, "DLLs"), new File(new File(parentFile, "Library"), "bin") }) {
try {
if (check.exists()) {
changed = true;
if (!buf.endsWith(File.pathSeparator)) {
buf.append(File.pathSeparator);
}
buf.appendObject(check);
}
} catch (Exception e) {
// ignore
}
}
if (changed) {
envp[i] = buf.toString();
}
break;
}
}
}
}
// Otherwise, use default (used when configuring the interpreter for instance).
monitor.setTaskName("Making exec..." + executionString);
if (workingDir != null) {
if (!workingDir.isDirectory()) {
throw new RuntimeException(StringUtils.format("Working dir must be an existing directory (received: %s)", workingDir));
}
}
if (updateEnv != null) {
envp = updateEnv.call(envp);
}
process = createProcess(cmdarray, envp, workingDir);
} catch (Exception e) {
throw new RuntimeException(e);
}
return new Tuple<Process, String>(process, executionString);
}
use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class ModulesKey method toString.
@Override
public String toString() {
FastStringBuffer ret = new FastStringBuffer(this.getClass().getSimpleName(), 40 + name.length());
ret.append('[');
ret.append(name);
if (file != null) {
ret.append(" - ");
ret.appendObject(file);
}
ret.append(']');
return ret.toString();
}
use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class ModulesKeyForZip method toString.
@Override
public String toString() {
FastStringBuffer ret = new FastStringBuffer(name, 40);
if (file != null) {
ret.append(" - ");
ret.appendObject(file);
}
if (zipModulePath != null) {
ret.append(" - zip path:");
ret.append(zipModulePath);
}
return ret.toString();
}
Aggregations