Example #1
0
    def uninstallPackages(self, packages, name="", prefix=""):
        """
        Public method to uninstall packages of a conda environment (including
        all no longer needed dependencies).
        
        @param packages list of package names to be uninstalled
        @type list of str
        @param name name of the environment
        @type str
        @param prefix prefix of the environment
        @type str
        @return flag indicating success
        @rtype bool
        @exception RuntimeError raised to indicate an error in parameters
        
        Note: only one of name or prefix must be given.
        """
        if name and prefix:
            raise RuntimeError("Only one of 'name' or 'prefix' must be given.")

        if not name and not prefix:
            raise RuntimeError("One of 'name' or 'prefix' must be given.")

        if packages:
            from UI.DeleteFilesConfirmationDialog import (
                DeleteFilesConfirmationDialog)
            dlg = DeleteFilesConfirmationDialog(
                self.parent(), self.tr("Uninstall Packages"),
                self.tr("Do you really want to uninstall these packages and"
                        " their dependencies?"), packages)
            if dlg.exec_() == QDialog.Accepted:
                args = [
                    "remove",
                    "--json",
                    "--yes",
                ]
                if condaVersion() >= (4, 4, 0):
                    args.append("--prune", )
                if name:
                    args.extend(["--name", name])
                elif prefix:
                    args.extend(["--prefix", prefix])
                args.extend(packages)

                dlg = CondaExecDialog("remove", self.__ui)
                dlg.start(args)
                dlg.exec_()
                ok, _ = dlg.getResult()
            else:
                ok = False
        else:
            ok = False

        return ok