Skip to content

Commit

Permalink
Separate Python installation verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
danv61 committed Sep 5, 2017
1 parent bf21394 commit 1d3b155
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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("<html><font color=#8C001A>" + ret + "</font></html>");
Expand All @@ -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) {
Expand Down
60 changes: 51 additions & 9 deletions vcell-core/src/main/java/cbit/vcell/resource/CondaSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 1d3b155

Please sign in to comment.