Example #1
0
 // ------------------------------------------------------------------------------------------
 // LOCAL CACHES
 public void clearCaches(boolean clearGlobalModulesCache) {
   this.interpreterType = null;
   this.versionPropertyCache = null;
   this.interpreterPropertyCache = null;
   this.pythonPathNature.clearCaches();
   if (clearGlobalModulesCache) {
     ModulesManager.clearCache();
   }
 }
Example #2
0
  /**
   * @param systemModulesManager
   * @param workspaceMetadataFile
   * @throws IOException
   */
  public static void loadFromFile(ModulesManager modulesManager, File workspaceMetadataFile)
      throws IOException {
    if (workspaceMetadataFile.exists() && !workspaceMetadataFile.isDirectory()) {
      throw new IOException("Expecting: " + workspaceMetadataFile + " to be a directory.");
    }
    File modulesKeysFile = new File(workspaceMetadataFile, "modulesKeys");
    File pythonpatHelperFile = new File(workspaceMetadataFile, "pythonpath");
    if (!modulesKeysFile.isFile()) {
      throw new IOException("Expecting: " + modulesKeysFile + " to exist (and be a file).");
    }
    if (!pythonpatHelperFile.isFile()) {
      throw new IOException("Expecting: " + pythonpatHelperFile + " to exist (and be a file).");
    }

    String fileContents = FileUtils.getFileContents(modulesKeysFile);
    if (!fileContents.startsWith(MODULES_MANAGER_V2)) {
      throw new RuntimeException(
          "Could not load modules manager from " + modulesKeysFile + " (version changed).");
    }

    HashMap<Integer, String> intToString = new HashMap<Integer, String>();
    fileContents = fileContents.substring(MODULES_MANAGER_V2.length());
    if (fileContents.startsWith("--COMMON--\n")) {
      String header = fileContents.substring("--COMMON--\n".length());
      header = header.substring(0, header.indexOf("--END-COMMON--\n"));
      fileContents =
          fileContents.substring(
              fileContents.indexOf("--END-COMMON--\n") + "--END-COMMON--\n".length());

      for (String line : StringUtils.iterLines(header)) {
        line = line.trim();
        List<String> split = StringUtils.split(line, '=');
        if (split.size() == 2) {
          try {
            int i = Integer.parseInt(split.get(0));
            intToString.put(i, split.get(1));
          } catch (NumberFormatException e) {
            Log.log(e);
          }
        }
      }
      if (fileContents.startsWith(MODULES_MANAGER_V2)) {
        fileContents = fileContents.substring(MODULES_MANAGER_V2.length());
      }
    }

    handleFileContents(modulesManager, fileContents, intToString);

    if (modulesManager.pythonPathHelper == null) {
      throw new IOException(
          "Pythonpath helper not properly restored. "
              + modulesManager.getClass().getName()
              + " dir:"
              + workspaceMetadataFile);
    }
    modulesManager.pythonPathHelper.loadFromFile(pythonpatHelperFile);

    if (modulesManager.pythonPathHelper.getPythonpath() == null) {
      throw new IOException(
          "Pythonpath helper pythonpath not properly restored. "
              + modulesManager.getClass().getName()
              + " dir:"
              + workspaceMetadataFile);
    }

    if (modulesManager.pythonPathHelper.getPythonpath().size() == 0) {
      throw new IOException(
          "Pythonpath helper pythonpath restored with no contents. "
              + modulesManager.getClass().getName()
              + " dir:"
              + workspaceMetadataFile);
    }

    if (modulesManager.modulesKeys.size()
        < 2) { // if we have few modules, that may indicate a problem...
      // if the project is really small, modulesManager will be fast, otherwise, it'll fix the
      // problem.
      // Note: changed to a really low value because we now make a check after it's restored
      // anyways.
      throw new IOException(
          "Only "
              + modulesManager.modulesKeys.size()
              + " modules restored in I/O. "
              + modulesManager.getClass().getName()
              + " dir:"
              + workspaceMetadataFile);
    }
  }