Skip to content

Commit

Permalink
Add .rvpkg bundle support for rvpkg command line tools and UI (#471)
Browse files Browse the repository at this point in the history
<!--
Thanks for your contribution! Please read this comment in its entirety.
It's quite important.
When a contributor merges the pull request, the title and the
description will be used to build the merge commit!

### Pull Request TITLE

It should be in the following format:

[ 12345: Summary of the changes made ] Where 12345 is the corresponding
Github Issue

OR

[ Summary of the changes made ] If it's solving something trivial, like
fixing a typo.
-->

### Linked issues
<!--
Link the Issue(s) this Pull Request is related to.

Each PR should link to at least one issue, in the form:

Use one line for each Issue. This allows auto-closing the related issue
when the fix is merged.

Fixes #12345
Fixes #54345
-->

### Summarize your change.

Users can now upload multiple packages at the same time through a
compressed zip file using the extension **.rvpkgs**. These **.rvpkgs**
files can be uploaded using the `rvpkg -add ...` command in the shell,
or directly in the UI under the `Preferences/Packages` section of the
menu.

In either case, **.rvpkgs** files will be immediately unzipped into the
packages they contain before each package is added to OpenRV.

Users can also add and install these **.rvpkgs** bundles using a chain
command as follows.

`rvpkg -force -install -add <destination> <location of .rvpkgs file>`

### Describe the reason for the change.

### Describe what you have tested and on which operating system.

This change was tested on MacOS. To replicate the test, recreate the
following steps.

**Creating an .rvpkgs file**

1. Find the .rvpkg files you want to bundle
2. Create a zip folder containing these .rvpkg files
3. Rename this zip file following `<name>-<version>.rvpkgs`

**Testing UI upload**

1. Launch OpenRV
2. Navigate to the `Preferences/Packages` section of the menu
3. Select `Add Packages...` 
4. Select your own **.rvpkgs** file
5. Click open
6. The packages zipped into the **.rvpkgs** file should be added
directly into RV

**Testing Command Line**

1. Determine the location of your **.rvpkgs** file
2. Determine the location you want to add/install your  packages to
3. Execute either of the following commands

`rvpkg -force -install -add <destination> <location of .rvpkgs file>`
`rvpkg -add <destination> <location of .rvpkgs file>`

Note that packages are often installed to `~/Library/Application\
Support/RV/` on Mac.

### Add a list of changes, and note any that might need special
attention during the review.

- [ ] Added bundle detection and handling functionality to the rvpkg
main file (specifically -add and -install sections)
- [ ] Minor bug fix in RvPreferences where text indicated incorrectly
that packages could not be uninstalled
- [ ] Added a multitude of utility functions to the PackageManager,
compartmentalizing and globalizing unzip and bundle detection
functionality

Signed-off-by: Ben Chamberland <[email protected]>
  • Loading branch information
chxmberland authored Jun 11, 2024
1 parent 4639285 commit a2bfba4
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 38 deletions.
79 changes: 63 additions & 16 deletions src/bin/apps/rvpkg/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,18 @@ utf8Main(int argc, char *argv[])

if (inputArgs.empty() && !list && !info && !env)
{
cout << "ERROR: use -help for usage" << endl;
cerr << "ERROR: use -help for usage" << endl;
}

if (add && remove)
{
cout << "ERROR: only one of -add or -remove allowed" << endl;
cerr << "ERROR: only one of -add or -remove allowed" << endl;
exit(-1);
}

if (onlyDir && (withDir || addDir))
{
cout << "ERROR: -only cannot be used with -include or -add" << endl;
cerr << "ERROR: -only cannot be used with -include or -add" << endl;
exit(-1);
}

Expand All @@ -320,25 +320,25 @@ utf8Main(int argc, char *argv[])

if ((remove && install) || (add && uninstall))
{
cout << "ERROR: conflicting arguments" << endl;
cerr << "ERROR: conflicting arguments" << endl;
exit(-1);
}

if ((remove || add || install || uninstall) && (list || info))
{
cout << "ERROR: -list and -info do not work with other arguments" << endl;
cerr << "ERROR: -list and -info do not work with other arguments" << endl;
exit(-1);
}

if (list && info)
{
cout << "ERROR: only one of -list or -info allowed" << endl;
cerr << "ERROR: only one of -list or -info allowed" << endl;
exit(-1);
}

if ((info || install || uninstall || remove || add) && inputArgs.empty())
{
cout << "ERROR: need more arguments" << endl;
cerr << "ERROR: need more arguments" << endl;
exit(-1);
}

Expand Down Expand Up @@ -489,7 +489,7 @@ utf8Main(int argc, char *argv[])

if (!p.optional)
{
cout << "ERROR: " << p.file.toUtf8().constData()
cerr << "ERROR: " << p.file.toUtf8().constData()
<< " is not an optional package -- ignoring"
<< endl;
continue;
Expand All @@ -500,7 +500,7 @@ utf8Main(int argc, char *argv[])

if (!info.exists())
{
cout << "ERROR: " << p.file.toUtf8().constData() << " doesn't exist -- ignoring" << endl;
cerr << "ERROR: " << p.file.toUtf8().constData() << " doesn't exist -- ignoring" << endl;
continue;
}

Expand All @@ -512,7 +512,7 @@ utf8Main(int argc, char *argv[])

if (!rvloadInfo.exists())
{
cout << "ERROR: missing rvload2 file at "
cerr << "ERROR: missing rvload2 file at "
<< rvload2.toUtf8().constData()
<< " -- ignoring"
<< endl;
Expand Down Expand Up @@ -551,9 +551,49 @@ utf8Main(int argc, char *argv[])
{
QStringList files;

// Will hold added packages from a bundle if an bundle is passes
std::vector<QString> addedPackages = {};

for (size_t i = 0; i < inputArgs.size(); i++)
{
files.push_back(inputArgs[i].c_str());
string curFile = inputArgs[i];

// Checking to see if the file is a bundle
if (manager.isBundle(QString::fromStdString(curFile))) {
cout << "INFO: Bundle detected, unpacking now." << endl;

// Unpacking bundle
QString toUnzip = QString::fromStdString(curFile);
string addDirStr = addDir;
QString outputDir = QString::fromStdString(addDirStr.append("/Packages"));
addedPackages = manager.handleBundle(toUnzip, outputDir);

// Ensuring that the bundle unpacked successfully
if (addedPackages.size() > 0)
{
cout << "INFO: Bundle unpacked successfully " << endl;
cout << "INFO: Added the following packages..." << endl;

for (QString s : addedPackages)
{
cout << s.toStdString() << endl;
}
} else {
cerr << "ERROR: Unable to install bundle." << endl;
}
} else {
files.push_back(inputArgs[i].c_str());
}
}

// Adding bundle subpackages to input arguments to allow for chain calls (e.g. -install -add ...)
if (addedPackages.size() > 0)
{

for (QString s : addedPackages)
{
inputArgs.push_back(s.toStdString());
}
}

if (!manager.addPackages(files, addDir))
Expand All @@ -571,19 +611,24 @@ utf8Main(int argc, char *argv[])
{
QString name(inputArgs[i].c_str());
QString base = name.split("/").back();

// Bundles do not need to be modified and should instead be removed
if (manager.isBundle(base)) continue;

QDir dir(addDir);
dir.cd("Packages");
dir.cd("Packages"); // Automatically navigating into the Packages directory
if (!dir.exists()) exit(-1);

QString path = dir.absoluteFilePath(base);
inputArgs[i] = path.toUtf8().constData();
cout << inputArgs[i] << endl;
}
}


if (install)
{
cout << "INFO: Installing package..." << endl;

vector<int> indices;
matchingPackages(packages, indices);

Expand All @@ -596,17 +641,19 @@ utf8Main(int argc, char *argv[])
{
PackageManager::Package& p = packages[indices[i]];

// Ensuring package not installed already
if (p.installed)
{
cout << "WARNING: " << p.name << " is already installed" << endl;
}
}

else
{
cout << "INFO: installing " << p.file << endl;

if (!manager.installPackage(p))
{
cout << "ERROR: failed to install " << p.file << endl;
cerr << "ERROR: failed to install " << p.file << endl;
}
}
}
Expand Down Expand Up @@ -658,4 +705,4 @@ utf8Main(int argc, char *argv[])
}

return 0;
}
}
10 changes: 4 additions & 6 deletions src/lib/app/RvCommon/RvPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2937,7 +2937,7 @@ RvPreferences::addPackage(bool)
QFileDialog* fileDialog = new QFileDialog(this,
"Select rvpkg RV package files",
dirname,
"rvpkg Package Files (*.zip *.rvpkg)");
"rvpkg Package Files (*.zip *.rvpkg *.rvpkgs)");

QStringList files;
if (fileDialog->exec()) files = fileDialog->selectedFiles();
Expand All @@ -2961,7 +2961,7 @@ RvPreferences::addPackage(bool)
QStringList files = QFileDialog::getOpenFileNames(this,
"Select rvpkg RV package files",
dirname,
"rvpkg Package Files (*.zip *.rvpkg)",
"rvpkg Package Files (*.zip *.rvpkg *.rvpkgs, *.rvpkgs)",
&selectedFilter,
options);
#endif
Expand Down Expand Up @@ -3119,7 +3119,7 @@ RvPreferences::installDependantPackages(const QString& msg)
{
QMessageBox box(this);
box.setWindowTitle(tr("Some Packages Depend on This One"));
box.setText(tr("Can't uninstall package because some other packages dependend on this one. Try and uninstall them first?\n\nDetails:\n") + msg);
box.setText(tr("Can't install package because some other packages dependend on this one. Try and install them first?\n\nDetails:\n") + msg);

box.setWindowModality(Qt::WindowModal);
QPushButton* b1 = box.addButton(tr("Abort"), QMessageBox::RejectRole);
Expand Down Expand Up @@ -4025,6 +4025,4 @@ RvPreferences::formatProfileChanged(int index)
}


} // Rv


} // Rv
Loading

0 comments on commit a2bfba4

Please sign in to comment.