From 1d3b155039881ce93bc560169555fa01d0cadd47 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Tue, 5 Sep 2017 17:28:05 -0400 Subject: [PATCH] Separate Python installation verification. --- .../PythonConfigurationPanel2.java | 27 +++++++-- .../cbit/vcell/resource/CondaSupport.java | 60 ++++++++++++++++--- 2 files changed, 72 insertions(+), 15 deletions(-) diff --git a/vcell-client/src/main/java/cbit/vcell/client/configuration/PythonConfigurationPanel2.java b/vcell-client/src/main/java/cbit/vcell/client/configuration/PythonConfigurationPanel2.java index cf3beb9488..de8ca2a3a5 100644 --- a/vcell-client/src/main/java/cbit/vcell/client/configuration/PythonConfigurationPanel2.java +++ b/vcell-client/src/main/java/cbit/vcell/client/configuration/PythonConfigurationPanel2.java @@ -200,10 +200,23 @@ private void initialize() { // -------------------------------------------------- gridy++; + + gbc = new GridBagConstraints(); + gbc.gridx = 0; + gbc.gridy = gridy; + gbc.weightx = 1; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.anchor = GridBagConstraints.WEST; + gbc.insets = new Insets(4, 4, 4, 10); + upper.add(new JLabel(""), gbc); + gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = gridy; - //gbc.fill = GridBagConstraints.HORIZONTAL; + //gbc.weightx = 1; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.EAST; gbc.insets = new Insets(4, 4, 4, 10); // top, left, bottom, right upper.add(getTestConfigurationButton(), gbc); @@ -212,7 +225,9 @@ private void initialize() { gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = gridy; - // gbc.fill = GridBagConstraints.HORIZONTAL; + //gbc.weightx = 1; + gbc.gridwidth = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.EAST; gbc.insets = new Insets(4, 4, 4, 10); upper.add(getInstallPythonButton(), gbc); @@ -255,14 +270,14 @@ private void initialize() { private JButton getTestConfigurationButton() { if (testConfigurationButton == null) { - testConfigurationButton = new javax.swing.JButton(" Test Configuration "); + testConfigurationButton = new javax.swing.JButton("Test Configuration"); testConfigurationButton.setName("TestConfigurationButton"); } return testConfigurationButton; } private JButton getInstallPythonButton() { if (installPythonButton == null) { - installPythonButton = new javax.swing.JButton(" Python Installation"); + installPythonButton = new javax.swing.JButton("Install Python"); installPythonButton.setName("InstallPythonButton"); } return installPythonButton; @@ -272,7 +287,7 @@ private void verifyInstallation() { getTestConfigurationButton().setEnabled(false); getInstallPythonButton().setEnabled(false); try { - CondaSupport.verifyInstall(false, false, false); + CondaSupport.verifyInstallation(); } catch (Exception e) { String ret = e.getMessage(); testConfigurationResults.setText("" + ret + ""); @@ -293,7 +308,7 @@ private void installPython() { public void run() { try { //Thread.sleep(5000); // use this for faster testing of the UI - CondaSupport.verifyInstall(true, true, true); + CondaSupport.installAsNeeded(true, true, true); } catch (Exception e) { String ret = e.getMessage(); if(ret.length() > 250) { diff --git a/vcell-core/src/main/java/cbit/vcell/resource/CondaSupport.java b/vcell-core/src/main/java/cbit/vcell/resource/CondaSupport.java index f490d5d417..c1a86bcdb4 100644 --- a/vcell-core/src/main/java/cbit/vcell/resource/CondaSupport.java +++ b/vcell-core/src/main/java/cbit/vcell/resource/CondaSupport.java @@ -105,7 +105,7 @@ public void run() { boolean bForceInstallPython = false; boolean bForceInstallPackages = false; - verifyInstall(bForceDownload, bForceInstallPython, bForceInstallPackages); + installAsNeeded(bForceDownload, bForceInstallPython, bForceInstallPackages); }catch (Throwable e){ e.printStackTrace(); } @@ -157,7 +157,55 @@ private static AnacondaInstallation getAnacondaInstallation(File anacondaInstall return new AnacondaInstallation(anacondaInstallDir, pythonExeFile, condaExeFile); } - public static synchronized void verifyInstall(boolean bForceDownload, boolean bForceInstallPython, boolean bForceInstallPackages) throws IOException { + public static synchronized void verifyInstallation() throws IOException { + + for (PythonPackage pkg : PythonPackage.values()){ + getPackageStatusMap().put(pkg, InstallStatus.INITIALIZING); + } + // if anaconda directory not specified using vcell.anaconda.installdir property, then use a managed Miniconda installation + File providedAnacondaDir = VCellConfiguration.getFileProperty(PropertyLoader.anacondaInstallDir); + File managedMinicondaInstallDir = new File(ResourceUtil.getVcellHome(),"Miniconda"); + if (providedAnacondaDir == null) { + final File downloadDir = new File(ResourceUtil.getVcellHome(),"download"); + final File archive; + + OperatingSystemInfo operatingSystemInfo = OperatingSystemInfo.getInstance(); + if (operatingSystemInfo.isWindows()) { + if (operatingSystemInfo.is64bit()) { + archive = new File(downloadDir,win64py27); + }else{ + archive = new File(downloadDir,win32py27); + } + }else if (operatingSystemInfo.isLinux()) { + if (operatingSystemInfo.is64bit()){ + archive = new File(downloadDir,lin64py27); + }else{ + archive = new File(downloadDir,lin32py27); + } + }else if (operatingSystemInfo.isMac()) { + archive = new File(downloadDir,osx64py27); + }else{ + throw new RuntimeException("python installation now supported on this platform"); + } + + // check if miniconda python installation already exists + AnacondaInstallation managedMiniconda = getAnacondaInstallation(managedMinicondaInstallDir); + boolean bPythonExists = false; + if (managedMiniconda.pythonExe.exists()) { + boolean ret = checkPython(managedMiniconda); + if (ret) { + bPythonExists = true; + } + } + + if(!bPythonExists || !archive.exists()) { + // We are just verifying. Since it's missing, we produce a good message and exit + throw new RuntimeException("The vCell python component is missing. To get access to full vCell features we recommend installing it"); + } + } + } + + public static synchronized void installAsNeeded(boolean bForceDownload, boolean bForceInstallPython, boolean bForceInstallPackages) throws IOException { isInstallingOrVerifying = true; for (PythonPackage pkg : PythonPackage.values()){ @@ -236,12 +284,6 @@ public static synchronized void verifyInstall(boolean bForceDownload, boolean bF // // Step 2: download installer archive if doesn't exist // - if((!bPythonExists || !archive.exists()) && !bForceDownload) { - // - // We are just verifying. Since it's missing, we produce a good message and exit - // - throw new RuntimeException("The vCell python component is missing. To get access to full vCell features we recommend installing it"); - } URL url = new URL(minicondaWeb + archive.getName()); if (!bPythonExists || !archive.exists() || bForceDownload) { FileUtils.copyURLToFile(url, archive); // download the archive @@ -419,7 +461,7 @@ public static void main(String[] args){ boolean bForceInstallPython = false; boolean bForceInstallPackages = false; - verifyInstall(bForceDownload, bForceInstallPython, bForceInstallPackages); + installAsNeeded(bForceDownload, bForceInstallPython, bForceInstallPackages); System.out.println("verified Python = " + getPythonExe());