Example #1
0
  /**
   * This method should traverse the pythonpath passed and return a structure with the info that
   * could be collected about the files that are related to python modules.
   */
  public ModulesFoundStructure getModulesFoundStructure(IProgressMonitor monitor) {
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    List<String> pythonpathList = getPythonpath();

    ModulesFoundStructure ret = new ModulesFoundStructure();

    for (Iterator<String> iter = pythonpathList.iterator(); iter.hasNext(); ) {
      String element = iter.next();

      if (monitor.isCanceled()) {
        break;
      }

      // the slow part is getting the files... not much we can do (I think).
      File root = new File(element);
      PyFileListing below = getModulesBelow(root, monitor);
      if (below != null) {

        Iterator<PyFileInfo> e1 = below.getFoundPyFileInfos().iterator();
        while (e1.hasNext()) {
          PyFileInfo pyFileInfo = e1.next();
          File file = pyFileInfo.getFile();
          String scannedModuleName = pyFileInfo.getModuleName();

          String modName;
          if (scannedModuleName.length() != 0) {
            modName =
                new StringBuffer(scannedModuleName)
                    .append('.')
                    .append(stripExtension(file.getName()))
                    .toString();
          } else {
            modName = stripExtension(file.getName());
          }
          if (isValidModuleLastPart(FullRepIterable.getLastPart(modName))) {
            ret.regularModules.put(file, modName);
          }
        }

      } else { // ok, it was null, so, maybe this is not a folder, but zip file with java classes...
        ModulesFoundStructure.ZipContents zipContents = getFromZip(root, monitor);
        if (zipContents != null) {
          ret.zipContents.add(zipContents);
        }
      }
    }
    return ret;
  }