public void checkAllNow() {
    // Add all to be tracked
    Map<IInterpreterManager, Map<String, IInterpreterInfo>> addedToTrack = job.addAllToTrack();

    // remove from the preferences any ignore the user had set previously
    Set<Entry<IInterpreterManager, Map<String, IInterpreterInfo>>> entrySet =
        addedToTrack.entrySet();
    IPreferenceStore preferences = PydevPrefs.getPreferences();
    for (Entry<IInterpreterManager, Map<String, IInterpreterInfo>> entry : entrySet) {
      Set<Entry<String, IInterpreterInfo>> entrySet2 = entry.getValue().entrySet();
      for (Entry<String, IInterpreterInfo> entry2 : entrySet2) {
        String key = SynchSystemModulesManager.createKeyForInfo(entry2.getValue());
        preferences.setValue(key, "");
      }
    }
    if (preferences instanceof IPersistentPreferenceStore) {
      IPersistentPreferenceStore iPersistentPreferenceStore =
          (IPersistentPreferenceStore) preferences;
      try {
        iPersistentPreferenceStore.save();
      } catch (IOException e) {
        Log.log(e);
      }
    }

    // schedule changes to be executed.
    job.scheduleLater(0);
  }
  /**
   * To be called when we start the plugin.
   *
   * <p>Should be called only once (when we'll make a full check for the current integrity of the
   * information) Later on, we'll start to check if things change in the PYTHONPATH based on changes
   * in the filesystem.
   */
  public void start() {

    boolean scheduleInitially = false;
    boolean reCheckOnFilesystemChanges =
        InterpreterGeneralPreferencesPage.getReCheckOnFilesystemChanges();

    IInterpreterManager[] managers = PydevPlugin.getAllInterpreterManagers();
    for (IInterpreterManager iInterpreterManager : managers) {
      if (iInterpreterManager != null) {
        IInterpreterInfo[] interpreterInfos = iInterpreterManager.getInterpreterInfos();
        if (reCheckOnFilesystemChanges) {
          this.registerInterpreterManager(iInterpreterManager, interpreterInfos);
        }
        scheduleInitially =
            scheduleInitially || (interpreterInfos != null && interpreterInfos.length > 0);
      }
    }

    int timeout = 1000 * 30; // Default is waiting 30 seconds after startup

    IPreferenceStore preferences = PydevPrefs.getPreferences();
    boolean alreadyChecked =
        preferences.getBoolean(
            "INTERPRETERS_CHECKED_ONCE"); // Now we add builtin indexing on our checks (so, force it
                                          // at least once).
    boolean force = false;
    if (!alreadyChecked) {
      preferences.setValue(
          "INTERPRETERS_CHECKED_ONCE",
          true); // Now we add builtin indexing on our checks (so, force it at least once).
      force = true;
      timeout = 1000 * 7; // In this case, wait only 7 seconds after startup
    }

    if (force || InterpreterGeneralPreferencesPage.getCheckConsistentOnStartup()) {
      if (scheduleInitially) {
        // Only do the initial schedule if there's something to be tracked (otherwise, wait for some
        // interpreter
        // to be configured and work only on deltas already).

        // The initial job will do a full check on what's available and if it's synched with the
        // filesystem.
        job.addAllToTrack();
        job.scheduleLater(timeout); // Wait a minute before starting our sync process.
      }
    }
  }
Exemplo n.º 3
0
  /**
   * Sets defaults.
   *
   * @throws InvalidRunException
   * @throws MisconfigurationException
   */
  @SuppressWarnings("unchecked")
  public PythonRunnerConfig(
      ILaunchConfiguration conf, String mode, String run, boolean makeArgumentsVariableSubstitution)
      throws CoreException, InvalidRunException, MisconfigurationException {
    // 1st thing, see if this is a valid run.
    project = getProjectFromConfiguration(conf);

    if (project == null) { // Ok, we could not find it out
      throw Log.log("Could not get project for configuration: " + conf);
    }

    // We need the project to find out the default interpreter from the InterpreterManager.
    IPythonNature pythonNature = PythonNature.getPythonNature(project);
    if (pythonNature == null) {
      CoreException e = Log.log("No python nature for project: " + project.getName());
      throw e;
    }

    // now, go on configuring other things
    this.configuration = conf;
    this.run = run;
    isDebug = mode.equals(ILaunchManager.DEBUG_MODE);
    isInteractive = mode.equals("interactive");

    resource = getLocation(conf, pythonNature);
    arguments = getArguments(conf, makeArgumentsVariableSubstitution);
    IPath workingPath = getWorkingDirectory(conf, pythonNature);
    workingDirectory = workingPath == null ? null : workingPath.toFile();
    acceptTimeout = PydevPrefs.getPreferences().getInt(PydevEditorPrefs.CONNECT_TIMEOUT);

    interpreterLocation =
        getInterpreterLocation(conf, pythonNature, this.getRelatedInterpreterManager());
    interpreter = getInterpreter(interpreterLocation, conf, pythonNature);

    // make the environment
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    envp = launchManager.getEnvironment(conf);
    IInterpreterManager manager;
    if (isJython()) {
      manager = PydevPlugin.getJythonInterpreterManager();
    } else if (isIronpython()) {
      manager = PydevPlugin.getIronpythonInterpreterManager();
    } else {
      manager = PydevPlugin.getPythonInterpreterManager();
    }

    boolean win32 = PlatformUtils.isWindowsPlatform();

    if (envp == null) {
      // ok, the user has done nothing to the environment, just get all the default environment
      // which has the pythonpath in it
      envp = SimpleRunner.getEnvironment(pythonNature, interpreterLocation, manager);

    } else {
      // ok, the user has done something to configure it, so, just add the pythonpath to the
      // current env (if he still didn't do so)
      Map envMap = conf.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null);

      String pythonpath =
          SimpleRunner.makePythonPathEnvString(pythonNature, interpreterLocation, manager);
      updateVar(pythonNature, manager, win32, envMap, "PYTHONPATH", pythonpath);
      if (isJython()) {
        // Also update the classpath env variable.
        updateVar(pythonNature, manager, win32, envMap, "CLASSPATH", pythonpath);
        // And the jythonpath env variable
        updateVar(pythonNature, manager, win32, envMap, "JYTHONPATH", pythonpath);

      } else if (isIronpython()) {
        // Also update the ironpythonpath env variable.
        updateVar(pythonNature, manager, win32, envMap, "IRONPYTHONPATH", pythonpath);
      }

      // And we also must get the environment variables specified in the interpreter manager.
      envp = interpreterLocation.updateEnv(envp, envMap.keySet());
    }

    boolean hasDjangoNature = project.hasNature(PythonNature.DJANGO_NATURE_ID);

    String settingsModule = null;
    Map<String, String> variableSubstitution = null;
    final String djangoSettingsKey = "DJANGO_SETTINGS_MODULE";
    String djangoSettingsEnvEntry = null;
    try {
      variableSubstitution = pythonNature.getPythonPathNature().getVariableSubstitution();
      settingsModule = variableSubstitution.get(djangoSettingsKey);
      if (settingsModule != null) {
        if (settingsModule.trim().length() > 0) {
          djangoSettingsEnvEntry = djangoSettingsKey + "=" + settingsModule.trim();
        }
      }
    } catch (Exception e1) {
      Log.log(e1);
    }
    if (djangoSettingsEnvEntry == null && hasDjangoNature) {
      // Default if not specified (only add it if the nature is there).
      djangoSettingsEnvEntry = djangoSettingsKey + "=" + project.getName() + ".settings";
    }

    // Note: set flag even if not debugging as the user may use remote-debugging later on.
    boolean geventSupport =
        DebugPrefsPage.getGeventDebugging()
            && pythonNature.getInterpreterType() == IPythonNature.INTERPRETER_TYPE_PYTHON;

    // Now, set the pythonpathUsed according to what's in the environment.
    String p = "";
    for (int i = 0; i < envp.length; i++) {
      String s = envp[i];
      Tuple<String, String> tup = StringUtils.splitOnFirst(s, '=');
      String var = tup.o1;
      if (win32) {
        // On windows it doesn't matter, always consider uppercase.
        var = var.toUpperCase();
      }

      if (var.equals("PYTHONPATH")) {
        p = tup.o2;

      } else if (var.equals(djangoSettingsKey)) {
        // Update it.
        if (djangoSettingsEnvEntry != null) {
          envp[i] = djangoSettingsEnvEntry;
          djangoSettingsEnvEntry = null;
        }
      }

      if (geventSupport) {
        if (var.equals("GEVENT_SUPPORT")) {
          // Flag already set in the environment
          geventSupport = false;
        }
      }
    }

    // Still not added, let's do that now.
    if (djangoSettingsEnvEntry != null) {
      envp = StringUtils.addString(envp, djangoSettingsEnvEntry);
    }
    if (geventSupport) {
      envp = StringUtils.addString(envp, "GEVENT_SUPPORT=True");
    }
    this.pythonpathUsed = p;
  }
Exemplo n.º 4
0
 /** @return */
 public static boolean isFoldingEnabled() {
   return PydevPrefs.getPreferences().getBoolean(PyDevCodeFoldingPrefPage.USE_CODE_FOLDING);
 }
 public static boolean getReCheckOnFilesystemChanges() {
   return PydevPrefs.getPreferences().getBoolean(UPDATE_INTERPRETER_INFO_ON_FILESYSTEM_CHANGES);
 }
 public static boolean getCheckConsistentOnStartup() {
   return PydevPrefs.getPreferences().getBoolean(CHECK_CONSISTENT_ON_STARTUP);
 }
    @Override
    protected IStatus run(IProgressMonitor monitor) {
      boolean selectingElementsInDialog = fSynchManager.getSelectingElementsInDialog();
      if (selectingElementsInDialog) {
        // No point in starting a process if the user already has a dialog related to this process
        // open.
        if (SynchSystemModulesManager.DEBUG) {
          System.out.println("Dialog already showing: rescheduling new check for later.");
        }
        this.scheduleLater(20000);
        return Status.OK_STATUS;
      }
      if (SynchSystemModulesManager.DEBUG) {
        System.out.println("Running SynchJob!");
      }

      if (monitor == null) {
        monitor = new NullProgressMonitor();
      }
      ManagerInfoToUpdate managerToNameToInfo;
      synchronized (fManagerToNameToInfoLock) {
        if (this.fManagerToNameToInfo == null || this.fManagerToNameToInfo.size() == 0) {
          return Status.OK_STATUS; // nothing to do if there's nothing there...
        }
        managerToNameToInfo = new ManagerInfoToUpdate(this.fManagerToNameToInfo);
        this.fManagerToNameToInfo = null;
      }

      long initialTime = System.currentTimeMillis();
      ThreadPriorityHelper priorityHelper = new ThreadPriorityHelper(this.getThread());
      priorityHelper.setMinPriority();

      try {
        final DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
        if (monitor.isCanceled()) {
          return Status.OK_STATUS;
        }

        fSynchManager.updateStructures(
            monitor, root, managerToNameToInfo, new CreateInterpreterInfoCallback());
        long delta = System.currentTimeMillis() - initialTime;
        if (SynchSystemModulesManager.DEBUG) {
          System.out.println(
              "Time to check polling for changes in interpreters: " + delta / 1000.0 + " secs.");
        }

        List<TreeNode> initialSelection = new ArrayList<>(0);
        if (root.hasChildren()) {
          initialSelection =
              fSynchManager.createInitialSelectionForDialogConsideringPreviouslyIgnored(
                  root, PydevPrefs.getPreferences());
        }

        if (root.hasChildren() && initialSelection.size() > 0) {
          if (SynchSystemModulesManager.DEBUG) {
            System.out.println("Changes found in PYTHONPATH.");
          }
          fSynchManager.asyncSelectAndScheduleElementsToChangePythonpath(
              root, managerToNameToInfo, initialSelection);
        } else {
          if (SynchSystemModulesManager.DEBUG) {
            System.out.println("PYTHONPATH remained the same.");
          }
          fSynchManager.synchronizeManagerToNameToInfoPythonpath(
              monitor, managerToNameToInfo, null);
        }

      } finally {
        // As jobs are from a thread pool, restore the priority afterwards
        priorityHelper.restoreInitialPriority();
      }
      return Status.OK_STATUS;
    }