Search in sources :

Example 1 with PythonExecutable

use of org.apache.netbeans.modules.python4nb.exec.PythonExecutable in project python4nb by ebresie.

the class PythonSupport method projectOpened.

void projectOpened() {
    FileUtil.addFileChangeListener(pythonSourcesListener, PythonUtils.getPythonSources());
    preferences.addPreferenceChangeListener(preferencesListener);
    pythonPackage.addPropertyChangeListener(packageJsonListener);
    // init node version
    PythonExecutable node = PythonExecutable.forProject(project, false);
    if (node != null) {
        node.getVersion();
    }
}
Also used : PythonExecutable(org.apache.netbeans.modules.python4nb.exec.PythonExecutable)

Example 2 with PythonExecutable

use of org.apache.netbeans.modules.python4nb.exec.PythonExecutable 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 PythonExecutable

use of org.apache.netbeans.modules.python4nb.exec.PythonExecutable 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

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