Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
research11111 committed Oct 27, 2023
1 parent e407afc commit 19dfe27
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
21 changes: 18 additions & 3 deletions avogadro/qtplugins/plugindownloader/pluginmanagerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void PluginManagerWidget::updatePluginsList()
m_repoList[i].zipballUrl = it.value().get<std::string>().c_str();
else if (it.key() == "has_release" && it.value().is_boolean())
m_repoList[i].hasRelease = it.value().get<bool>();
else if (it.key() == "repo_url" && it.value().is_string())
else if (it.key() == "repo" && it.value().is_string())
m_repoList[i].baseUrl = it.value().get<std::string>().c_str();
else if (it.key() == "readme_url" && it.value().is_string())
m_repoList[i].readmeUrl = it.value().get<std::string>().c_str();
Expand Down Expand Up @@ -392,6 +392,16 @@ void PluginManagerWidget::appendInstallationInformation(QString text) {
text
);
}

PluginManagerWidget::repo* PluginManagerWidget::getRepoByName(QString name) {
for(int i = 0; i < m_repoList.size(); i++) {
if ( name == m_repoList[i].name ) {
return &m_repoList[i];
}
}
return nullptr;
}

// Save and unzip the plugin zipball
QString PluginManagerWidget::unzipPlugin()
{
Expand All @@ -400,7 +410,12 @@ QString PluginManagerWidget::unzipPlugin()
QByteArray fileData = m_reply->readAll();
QDir().mkpath(m_filePath); // create any needed directories for the download
QString repoName = m_downloadList.last().name;
QString filename = repoName + ".zip";
PluginManagerWidget::repo* repoData = getRepoByName(repoName);
std::string repoBaseUrl = repoData->baseUrl.toUtf8().toStdString();
std::string::size_type lastSlash = repoBaseUrl.rfind('/');
QString pluginOutputDirName = QString::fromStdString(repoBaseUrl.substr(lastSlash + 1));

QString filename = pluginOutputDirName + ".zip";

QString absolutePath = m_filePath + "/" + filename;
QString extractDirectory;
Expand Down Expand Up @@ -466,7 +481,7 @@ QString PluginManagerWidget::unzipPlugin()
m_reply->deleteLater();
m_downloadList.removeLast();
installNextPlugin();
return extractDirectory + QDir::separator() + repoName;
return extractDirectory + QDir::separator() + pluginOutputDirName;
}
return NULL;
}
Expand Down
1 change: 1 addition & 0 deletions avogadro/qtplugins/plugindownloader/pluginmanagerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public slots:
void fetchPluginsList(QString url = "https://avogadro.cc/plugins.json");
void installNextPlugin();
bool checkSHA1(QByteArray);
repo* getRepoByName(QString name);

std::vector<repo> m_repoList;
Ui::PluginManagerWidget* m_ui;
Expand Down
30 changes: 16 additions & 14 deletions avogadro/qtplugins/plugindownloader/pythoncmdlineinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ void installRequirements(const QString& folderPath, const QString& installMethod
// Extract the environment name from pythonInstallation, if present
QString envName;
int colonIndex = pythonInstallation.indexOf(":");
int parenIndex = pythonInstallation.indexOf("(");
int parenIndex = pythonInstallation.indexOf(")");
if (parenIndex != -1 && colonIndex != -1) {
envName = pythonInstallation.mid(parenIndex + 1, colonIndex - parenIndex - 1).trimmed();
assert(colonIndex < parenIndex);
envName = pythonInstallation.mid(colonIndex + 1, parenIndex - colonIndex - 1).trimmed();
}

// Prepare environment activation command only if envName is not empty
QString activateCommand;
if (!envName.isEmpty()) {
if (pythonInstallation.contains("Conda")) {
activateCommand = (QSysInfo::productType() == "windows") ?
QString("activate %1 && ").arg(envName) :
QString("conda activate %1 && ").arg(envName);
if ( envName.isEmpty() ) {
activateCommand = QString("conda run ");
} else {
activateCommand = QString("conda run -n %1 ").arg(envName);
}
} else if (pythonInstallation.contains("VirtualEnv")) {
activateCommand = (QSysInfo::productType() == "windows") ?
QString("%1\\Scripts\\activate && ").arg(envName) :
Expand All @@ -56,18 +59,17 @@ void installRequirements(const QString& folderPath, const QString& installMethod
QMessageBox::information(nullptr, "Installation Info", "Conda cannot install from a pyproject.toml file.");
return;
}
} else {
QMessageBox::information(nullptr, "No Requirements Found", "Neither requirements.txt nor pyproject.toml found.");
return;
}

if (!installCommand.isEmpty()) {
QProcess process;
process.start(installCommand);
process.waitForFinished();
QProcess process;
process.start(installCommand);
process.waitForFinished();

if (process.exitCode() != 0) {
QMessageBox::critical(nullptr, "Installation Error", process.readAllStandardError());
}
} else {
QMessageBox::information(nullptr, "No Requirements Found", "Neither requirements.txt nor pyproject.toml found.");
if (process.exitCode() != 0) {
QMessageBox::critical(nullptr, "Installation Error", process.readAllStandardError());
}
}

Expand Down

0 comments on commit 19dfe27

Please sign in to comment.