Fix copying .egg files from remote host to libraries folder (PY-13044).

This commit is contained in:
Dmitry Trofimov
2014-07-14 17:22:56 +02:00
parent f41f9c370a
commit 86b7bf5c1e
5 changed files with 60 additions and 17 deletions
@@ -2,7 +2,6 @@ package com.intellij.remote;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author traff
@@ -25,14 +24,14 @@ public class RemoteFile {
this(resolveChild(parent, child, isWin), isWin);
}
@Nullable
@NotNull
public String getName() {
int ind = myPath.lastIndexOf(getSeparator(myWin));
if (ind != -1 && ind < myPath.length() - 1) { //not last char
return myPath.substring(ind + 1);
}
else {
return null;
return myPath;
}
}
@@ -88,6 +87,10 @@ public class RemoteFile {
return detectSystemByPath(path).createRemoteFile(path, script);
}
public static RemoteFile createRemoteFile(String path) {
return detectSystemByPath(path).createRemoteFile(path);
}
public static RemoteFile createRemoteFile(final String path, final String script, final boolean isWindows) {
return new RemoteFileBuilder(isWindows).createRemoteFile(path, script);
}
+3
View File
@@ -161,6 +161,9 @@ def list_sources(paths):
path = os.path.normpath(path)
if path.endswith('.egg') and os.path.isfile(path):
say("%s\t%s\t%d", path, path, os.path.getsize(path))
for root, files in walk_python_path(path):
for name in files:
if name.endswith('.py'):
@@ -19,16 +19,16 @@ import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Lists;
import com.intellij.ide.highlighter.ArchiveFileType;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.*;
import com.intellij.util.PlatformIcons;
import com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase;
import com.jetbrains.python.sdk.PySdkUtil;
@@ -75,11 +75,16 @@ public class PyRemoteLibrariesNode extends PsiDirectoryNode {
return FluentIterable.from(Lists.newArrayList(getValue().getChildren())).transform(new Function<PsiElement, AbstractTreeNode>() {
@Override
public AbstractTreeNode apply(PsiElement input) {
if (input instanceof PsiDirectory) {
PsiDirectory directory = (PsiDirectory)input;
if (myRemoteSdkData.getPathMappings().canReplaceLocal((directory.getVirtualFile().getPath()))) {
return new PyRemoteRootNode(myRemoteSdkData.getPathMappings().convertToRemote(directory.getVirtualFile().getPath()),
getProject(), directory, getSettings());
if (input instanceof PsiFileSystemItem) {
String path = ((PsiFileSystemItem)input).getVirtualFile().getPath();
PsiDirectory dir = input instanceof PsiDirectory ? (PsiDirectory)input : getDirectoryForJar((PsiFile)input);
if (myRemoteSdkData.getPathMappings().canReplaceLocal(path)) {
return new PyRemoteRootNode(myRemoteSdkData.getPathMappings().convertToRemote(path),
getProject(), dir, getSettings());
}
}
@@ -88,6 +93,26 @@ public class PyRemoteLibrariesNode extends PsiDirectoryNode {
}).filter(Predicates.notNull()).toList();
}
@Nullable
private PsiDirectory getDirectoryForJar(PsiFile input) {
VirtualFile jarRoot = getJarRoot(input);
if (myProject != null && jarRoot != null) {
return PsiManager.getInstance(myProject).findDirectory(jarRoot);
}
else {
return null;
}
}
@Nullable
private static VirtualFile getJarRoot(PsiFile input) {
final VirtualFile file = input.getVirtualFile();
if (file == null || !file.isValid() || !(file.getFileType() instanceof ArchiveFileType)) {
return null;
}
return JarFileSystem.getInstance().getJarRootForLocalFile(file);
}
public static class PyRemoteRootNode extends PsiDirectoryNode {
private String myRemotePath;
@@ -28,6 +28,8 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkTypeId;
import com.intellij.openapi.roots.JdkOrderEntry;
import com.intellij.openapi.roots.LibraryOrSdkOrderEntry;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -50,7 +52,9 @@ import java.util.List;
public class PyTreeStructureProvider implements SelectableTreeStructureProvider, DumbAware {
@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent,
@NotNull Collection<AbstractTreeNode> children,
ViewSettings settings) {
final Project project = parent.getProject();
final Sdk sdk = getPythonSdk(parent);
if (sdk != null && project != null) {
@@ -111,7 +115,15 @@ public class PyTreeStructureProvider implements SelectableTreeStructureProvider,
if (directory.getVirtualFile().equals(PyUserSkeletonsUtil.getUserSkeletonsDirectory())) {
continue;
}
PsiDirectory dirParent = directory.getParent();
VirtualFile dir = directory.getVirtualFile();
if (dir.getFileSystem() instanceof JarFileSystem) {
dir = ((JarFileSystem)directory.getVirtualFile().getFileSystem()).getLocalVirtualFileFor(directory.getVirtualFile());
}
if (dir == null) {
continue;
}
VirtualFile dirParent = dir.getParent();
if (dirParent != null && dirParent.getName().equals(PythonSdkType.SKELETON_DIR_NAME)) {
continue;
}
@@ -120,7 +132,7 @@ public class PyTreeStructureProvider implements SelectableTreeStructureProvider,
continue;
}
if (dirParent != null) {
PsiDirectory grandParent = dirParent.getParent();
VirtualFile grandParent = dirParent.getParent();
if (grandParent != null && grandParent.getName().equals(PythonSdkType.REMOTE_SOURCES_DIR_NAME)) {
continue;
@@ -158,8 +170,8 @@ public class PyTreeStructureProvider implements SelectableTreeStructureProvider,
}
}
if (parents.size() > 0) {
return parents.get(parents.size()-1);
return parents.get(parents.size() - 1);
}
return element.getContainingFile();
return element.getContainingFile();
}
}
@@ -57,6 +57,6 @@ public class PyRemoteSdkFlavor extends CPythonSdkFlavor {
@Nullable
private static String getExecutableName(String path) {
return RemoteFile.detectSystemByPath(path).createRemoteFile(path).getName();
return RemoteFile.createRemoteFile(path).getName();
}
}