Search in sources :

Example 1 with DefaultPathsForInterpreterInfo

use of org.python.pydev.ast.interpreter_managers.DefaultPathsForInterpreterInfo in project Pydev by fabioz.

the class SyncSystemModulesManager method updateStructures.

/**
 * Here we'll update the tree structure to be shown to the user with the changes (root).
 * The managerToNameToInfo structure has the information on the interpreter manager and related
 * interpreter infos for which the changes should be checked.
 */
public void updateStructures(IProgressMonitor monitor, final DataAndImageTreeNode root, ManagerInfoToUpdate managerToNameToInfo, CreateInterpreterInfoCallback callback) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    IImageCache imageCache = SharedCorePlugin.getImageCache();
    if (imageCache == null) {
        imageCache = new IImageCache() {

            @Override
            public IImageHandle getStringDecorated(String key, String stringToAddToDecoration) {
                return null;
            }

            @Override
            public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation, String secondDecoration, int secondDecorationLocation) {
                return null;
            }

            @Override
            public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation) {
                return null;
            }

            @Override
            public IImageHandle getImageDecorated(String key, String decoration) {
                return null;
            }

            @Override
            public IImageDescriptor getDescriptor(String projectIcon) {
                return null;
            }

            @Override
            public IImageHandle get(String key) {
                return null;
            }
        };
    }
    for (Tuple<IInterpreterManager, IInterpreterInfo> infos : managerToNameToInfo.getManagerAndInfos()) {
        IInterpreterManager manager = infos.o1;
        IInterpreterInfo internalInfo = infos.o2;
        String executable = internalInfo.getExecutableOrJar();
        IInterpreterInfo newInterpreterInfo = callback.createInterpreterInfo(manager, executable, monitor);
        if (newInterpreterInfo == null) {
            continue;
        }
        DefaultPathsForInterpreterInfo defaultPaths = new DefaultPathsForInterpreterInfo();
        OrderedSet<String> newEntries = new OrderedSet<String>(newInterpreterInfo.getPythonPath());
        newEntries.removeAll(internalInfo.getPythonPath());
        // Iterate over the new entries to suggest what should be added (we already have only what's not there).
        for (Iterator<String> it = newEntries.iterator(); it.hasNext(); ) {
            String entryInPythonpath = it.next();
            if (!defaultPaths.selectByDefault(entryInPythonpath) || !defaultPaths.exists(entryInPythonpath)) {
                // Don't suggest the addition of entries in the workspace or entries which do not exist.
                it.remove();
            }
        }
        // Iterate over existing entries to suggest what should be removed.
        OrderedSet<String> removedEntries = new OrderedSet<String>();
        List<String> pythonPath = internalInfo.getPythonPath();
        for (String string : pythonPath) {
            if (!new File(string).exists()) {
                // Only suggest a removal if it was removed from the filesystem.
                removedEntries.add(string);
            }
        }
        if (newEntries.size() > 0 || removedEntries.size() > 0) {
            DataAndImageTreeNode<IInterpreterInfo> interpreterNode = new DataAndImageTreeNode<IInterpreterInfo>(root, internalInfo, imageCache.get(UIConstants.PY_INTERPRETER_ICON));
            for (String s : newEntries) {
                new DataAndImageTreeNode(interpreterNode, new PythonpathChange(s, true), imageCache.get(UIConstants.LIB_SYSTEM));
            }
            for (String s : removedEntries) {
                new DataAndImageTreeNode(interpreterNode, new PythonpathChange(s, false), imageCache.get(UIConstants.REMOVE_LIB_SYSTEM));
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OrderedSet(org.python.pydev.shared_core.structure.OrderedSet) IImageCache(org.python.pydev.shared_core.image.IImageCache) IImageDescriptor(org.python.pydev.shared_core.image.IImageDescriptor) DefaultPathsForInterpreterInfo(org.python.pydev.ast.interpreter_managers.DefaultPathsForInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterManager(org.python.pydev.core.IInterpreterManager) IImageHandle(org.python.pydev.shared_core.image.IImageHandle) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) File(java.io.File)

Aggregations

File (java.io.File)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 DefaultPathsForInterpreterInfo (org.python.pydev.ast.interpreter_managers.DefaultPathsForInterpreterInfo)1 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)1 IInterpreterManager (org.python.pydev.core.IInterpreterManager)1 IImageCache (org.python.pydev.shared_core.image.IImageCache)1 IImageDescriptor (org.python.pydev.shared_core.image.IImageDescriptor)1 IImageHandle (org.python.pydev.shared_core.image.IImageHandle)1 DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)1 OrderedSet (org.python.pydev.shared_core.structure.OrderedSet)1