Search in sources :

Example 1 with Version

use of org.apache.netbeans.modules.python4nb.util.Version in project python4nb by ebresie.

the class PythonExecutable method detectVersion.

@NbBundle.Messages({ "PythonExecutable.version.detecting=Detecting Python version..." })
private void detectVersion() {
    if (VERSIONS.get(pythonPath) != null) {
        return;
    }
    assert !EventQueue.isDispatchThread();
    VersionOutputProcessorFactory versionOutputProcessorFactory = new VersionOutputProcessorFactory();
    try {
        // NOI18N
        getExecutable("python --version").additionalParameters(getVersionParams()).runAndWait(getSilentDescriptor(), versionOutputProcessorFactory, Bundle.PythonExecutable_version_detecting());
        String detectedVersion = versionOutputProcessorFactory.getVersion();
        if (detectedVersion != null) {
            Version version = Version.fromDottedNotationWithFallback(detectedVersion);
            VERSIONS.put(pythonPath, version);
            return;
        }
        // no version detected, store UNKNOWN_VERSION
        VERSIONS.put(pythonPath, UNKNOWN_VERSION);
    } catch (CancellationException ex) {
        // cancelled, cannot happen
        assert false;
    } catch (ExecutionException ex) {
        LOGGER.log(Level.INFO, null, ex);
    }
}
Also used : Version(org.apache.netbeans.modules.python4nb.util.Version) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with Version

use of org.apache.netbeans.modules.python4nb.util.Version in project python4nb by ebresie.

the class PythonPathPanel method downloadSources.

@NbBundle.Messages({ "# {0} - version", "PythonPathPanel.sources.exists=Sources for version {0} already exist. Download again?", "PythonPathPanel.sources.downloading=Downloading...", "PythonPathPanel.download.success=Python sources downloaded successfully.", "# {0} - file URL", "PythonPathPanel.download.failure=File {0} cannot be downloaded.", "PythonPathPanel.download.error=Error occured during download (see IDE log)." })
private void downloadSources() {
    assert EventQueue.isDispatchThread();
    downloadSourcesButton.setEnabled(false);
    String pythonPath = getPython();
    final PythonExecutable python = PythonExecutable.forPath(pythonPath);
    assert python != null : pythonPath;
    final Version version = python.getVersion();
    assert version != null : pythonPath;
    final Version realVersion = python.getRealVersion();
    assert realVersion != null : version;
    if (PythonUtils.hasPythonSources(version)) {
        pythonSources = null;
        setPythonSourcesDescription(version, realVersion);
        NotifyDescriptor.Confirmation confirmation = new NotifyDescriptor.Confirmation(Bundle.PythonPathPanel_sources_exists(version.toString()), NotifyDescriptor.YES_NO_OPTION);
        if (DialogDisplayer.getDefault().notify(confirmation) == NotifyDescriptor.NO_OPTION) {
            downloadSourcesButton.setEnabled(true);
            return;
        }
    }
    sourcesTextField.setText(Bundle.PythonPathPanel_sources_downloading());
    RP.post(new Runnable() {

        @Override
        public void run() {
            LOGGER.log(Level.WARNING, "Current implementation does not support download.");
            // TODO: For python account for downloading where applicable
            // try {0
            // if (FileUtils.downloadNodeSources(version, python.isJython())) {
            // StatusDisplayer.getDefault().setStatusText(Bundle.PythonPathPanel_download_success());
            // }
            // pythonSources = null;
            // } catch (NetworkException ex) {
            // LOGGER.log(Level.INFO, null, ex);
            // informUser(Bundle.PythonPathPanel_download_failure(ex.getFailedRequests().get(0)));
            // } catch (IOException ex) {
            // LOGGER.log(Level.INFO, null, ex);
            // informUser(Bundle.PythonPathPanel_download_error());
            // }
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    setPythonSourcesDescription(version, realVersion);
                    downloadSourcesButton.setEnabled(true);
                }
            });
        }
    });
}
Also used : PythonExecutable(org.apache.netbeans.modules.python4nb.exec.PythonExecutable) NotifyDescriptor(org.openide.NotifyDescriptor) Version(org.apache.netbeans.modules.python4nb.util.Version)

Example 3 with Version

use of org.apache.netbeans.modules.python4nb.util.Version in project python4nb by ebresie.

the class PythonUtils method getPythonSources.

// 
// @CheckForNull
// public static PackageJson getPackageJson(Lookup context) {
// return getProjectAndPackageJson(context).second();
// }
// 
// @CheckForNull
// public static Project getPackageJsonProject(Lookup context) {
// return getProjectAndPackageJson(context).first();
// }
// 
// public static Pair<Project, PackageJson> getProjectAndPackageJson(Lookup context) {
// Project project = context.lookup(Project.class);
// PackageJson packageJson = null;
// if (project != null) {
// // project action
// packageJson = new PackageJson(project.getProjectDirectory());
// } else {
// // package.json directly
// FileObject file = context.lookup(FileObject.class);
// if (file == null) {
// DataObject dataObject = context.lookup(DataObject.class);
// if (dataObject != null) {
// file = dataObject.getPrimaryFile();
// }
// }
// if (file != null) {
// packageJson = new PackageJson(file.getParent());
// project = FileOwnerQuery.getOwner(file);
// }
// }
// if (project == null) {
// return Pair.of(null, null);
// }
// if (packageJson == null) {
// return Pair.of(null, null);
// }
// if (!packageJson.exists()) {
// return Pair.of(null, null);
// }
// assert project != null;
// assert packageJson != null;
// return Pair.of(project, packageJson);
// }
@CheckForNull
public static File getPythonSources(Project project) {
    PythonPreferences preferences = PythonSupport.forProject(project).getPreferences();
    if (preferences.isDefaultPython()) {
        // default python
        String pythonSources = PythonOptions.getInstance().getPythonSources();
        if (pythonSources != null) {
            return new File(pythonSources);
        }
        PythonExecutable python = PythonExecutable.getDefault(project, false);
        if (python == null) {
            return null;
        }
        Version version = python.getVersion();
        if (version == null) {
            return null;
        }
        return getPythonSources(version);
    }
    // custom python
    String pythonSources = preferences.getPythonSources();
    if (pythonSources != null) {
        return new File(pythonSources);
    }
    PythonExecutable python = PythonExecutable.forProject(project, false);
    if (python == null) {
        return null;
    }
    Version version = python.getVersion();
    if (version == null) {
        return null;
    }
    return PythonUtils.getPythonSources(project);
}
Also used : PythonExecutable(org.apache.netbeans.modules.python4nb.exec.PythonExecutable) Version(org.apache.netbeans.modules.python4nb.util.Version) PythonPreferences(org.apache.netbeans.modules.python4nb.preferences.PythonPreferences) File(java.io.File) CheckForNull(org.netbeans.api.annotations.common.CheckForNull)

Aggregations

Version (org.apache.netbeans.modules.python4nb.util.Version)3 PythonExecutable (org.apache.netbeans.modules.python4nb.exec.PythonExecutable)2 File (java.io.File)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 PythonPreferences (org.apache.netbeans.modules.python4nb.preferences.PythonPreferences)1 CheckForNull (org.netbeans.api.annotations.common.CheckForNull)1 NotifyDescriptor (org.openide.NotifyDescriptor)1