private static CommandLineArgumentsProvider createCommandLineArgumentsProvider(
      final Sdk sdk, final Map<String, String> environmentVariables, int[] ports) {
    final ArrayList<String> args = new ArrayList<String>();
    args.add(sdk.getHomePath());
    final String versionString = sdk.getVersionString();
    if (versionString == null || !versionString.toLowerCase().contains("jython")) {
      args.add("-u");
    }
    args.add(
        FileUtil.toSystemDependentName(PythonHelpersLocator.getHelperPath(PYDEV_PYDEVCONSOLE_PY)));
    for (int port : ports) {
      args.add(String.valueOf(port));
    }
    return new CommandLineArgumentsProvider() {
      @Override
      public String[] getArguments() {
        return ArrayUtil.toStringArray(args);
      }

      @Override
      public boolean passParentEnvs() {
        return false;
      }

      @Override
      public Map<String, String> getAdditionalEnvs() {
        return addDefaultEnvironments(sdk, environmentVariables);
      }
    };
  }
 @NotNull
 private static ImmutableMap<String, String> loadPackageAliases() {
   final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
   try (FileReader reader =
       new FileReader(PythonHelpersLocator.getHelperPath("/tools/packages"))) {
     final String text = FileUtil.loadTextAndClose(reader);
     final List<String> lines = StringUtil.split(text, "\n");
     for (String line : lines) {
       final List<String> split = StringUtil.split(line, " ");
       builder.put(split.get(0), split.get(1));
     }
   } catch (IOException e) {
     LOG.error("Cannot find \"packages\". " + e.getMessage());
   }
   return builder.build();
 }
 private void buildForKeyword(@NotNull final String name) {
   try {
     final FileReader reader =
         new FileReader(PythonHelpersLocator.getHelperPath("/tools/python_keywords/" + name));
     try {
       final String text = FileUtil.loadTextAndClose(reader);
       myEpilog.addItem(text);
     } catch (IOException ignored) {
     } finally {
       try {
         reader.close();
       } catch (IOException ignored) {
       }
     }
   } catch (FileNotFoundException ignored) {
   }
 }
 private boolean generateSkeletonsForList(
     @NotNull final PySkeletonRefresher refresher,
     ProgressIndicator indicator,
     @Nullable final String currentBinaryFilesPath)
     throws InvalidSdkException {
   final PySkeletonGenerator generator =
       new PySkeletonGenerator(refresher.getSkeletonsPath(), mySdk, currentBinaryFilesPath);
   indicator.setIndeterminate(false);
   final String homePath = mySdk.getHomePath();
   if (homePath == null) return false;
   final ProcessOutput runResult =
       PySdkUtil.getProcessOutput(
           new File(homePath).getParent(),
           new String[] {
             homePath, PythonHelpersLocator.getHelperPath("extra_syspath.py"), myQualifiedName
           },
           PythonSdkType.getVirtualEnvExtraEnv(homePath),
           5000);
   if (runResult.getExitCode() == 0 && !runResult.isTimeout()) {
     final String extraPath = runResult.getStdout();
     final PySkeletonGenerator.ListBinariesResult binaries =
         generator.listBinaries(mySdk, extraPath);
     final List<String> names = Lists.newArrayList(binaries.modules.keySet());
     Collections.sort(names);
     final int size = names.size();
     for (int i = 0; i != size; ++i) {
       final String name = names.get(i);
       indicator.setFraction((double) i / size);
       if (needBinaryList(name)) {
         indicator.setText2(name);
         final PySkeletonRefresher.PyBinaryItem item = binaries.modules.get(name);
         final String modulePath = item != null ? item.getPath() : "";
         //noinspection unchecked
         refresher.generateSkeleton(
             name, modulePath, new ArrayList<String>(), Consumer.EMPTY_CONSUMER);
       }
     }
   }
   return true;
 }