CondaInterface/Conda.py

branch
conda
changeset 6706
d792e054cde2
parent 6705
8cf1c3851b5c
child 6712
91fa67e8ebbc
diff -r 8cf1c3851b5c -r d792e054cde2 CondaInterface/Conda.py
--- a/CondaInterface/Conda.py	Wed Feb 06 19:52:33 2019 +0100
+++ b/CondaInterface/Conda.py	Thu Feb 07 18:54:38 2019 +0100
@@ -16,7 +16,8 @@
 import json
 import os
 
-from PyQt5.QtCore import QObject, QProcess
+from PyQt5.QtCore import pyqtSignal, QObject, QProcess
+from PyQt5.QtWidgets import QDialog
 
 from E5Gui import E5MessageBox
 
@@ -29,7 +30,15 @@
 class Conda(QObject):
     """
     Class implementing the conda GUI logic.
+    
+    @signal condaEnvironmentCreated() emitted to indicate the creation of
+        a new environment
+    @signal condaEnvironmentRemoved() emitted to indicate the removal of
+        an environment
     """
+    condaEnvironmentCreated = pyqtSignal()
+    condaEnvironmentRemoved = pyqtSignal()
+    
     def __init__(self, parent=None):
         """
         Constructor
@@ -96,6 +105,7 @@
             else:
                 python = ""
             
+            self.condaEnvironmentCreated.emit()
             return True, prefix, python
         else:
             return False, "", ""
@@ -165,7 +175,12 @@
                             "<p>{0}</p>").format(jsonDict["message"]))
                 return False
             
+            if jsonDict["success"]:
+                self.condaEnvironmentRemoved.emit()
+            
             return jsonDict["success"]
+        
+        return False
     
     def getCondaEnvironmentsList(self):
         """
@@ -222,7 +237,6 @@
         @return list of installed packages. Each entry is a tuple containing
             the package name, version and build.
         @rtype list of tuples of (str, str, str)
-        @rtype bool
         @exception RuntimeError raised to indicate an error in parameters
         
         Note: only one of name or prefix must be given.
@@ -284,7 +298,6 @@
         @return list of installed packages. Each entry is a tuple containing
             the package name, version and build.
         @rtype list of tuples of (str, str, str)
-        @rtype bool
         @exception RuntimeError raised to indicate an error in parameters
         
         Note: only one of name or prefix must be given.
@@ -349,9 +362,7 @@
         @type str
         @param prefix prefix of the environment
         @type str
-        @return list of installed packages. Each entry is a tuple containing
-            the package name, version and build.
-        @rtype list of tuples of (str, str, str)
+        @return flag indicating success
         @rtype bool
         @exception RuntimeError raised to indicate an error in parameters
         
@@ -363,7 +374,28 @@
         if not name and not prefix:
             raise RuntimeError("One of 'name' or 'prefix' must be given.")
         
-        # TODO: not implemented yet
+        if packages:
+            from .CondaExecDialog import CondaExecDialog
+            
+            args = [
+                "update",
+                "--json",
+                "--yes",
+            ]
+            if name:
+                args.extend(["--name", name])
+            elif prefix:
+                args.extend(["--prefix", prefix])
+            args.extend(packages)
+            
+            dlg = CondaExecDialog("update", self.__ui)
+            dlg.start(args)
+            dlg.exec_()
+            ok, _ = dlg.getResult()
+        else:
+            ok = False
+        
+        return ok
     
     def updateAllPackages(self, name="", prefix=""):
         """
@@ -373,9 +405,7 @@
         @type str
         @param prefix prefix of the environment
         @type str
-        @return list of installed packages. Each entry is a tuple containing
-            the package name, version and build.
-        @rtype list of tuples of (str, str, str)
+        @return flag indicating success
         @rtype bool
         @exception RuntimeError raised to indicate an error in parameters
         
@@ -387,7 +417,25 @@
         if not name and not prefix:
             raise RuntimeError("One of 'name' or 'prefix' must be given.")
         
-        # TODO: not implemented yet
+        from .CondaExecDialog import CondaExecDialog
+        
+        args = [
+            "update",
+            "--json",
+            "--yes",
+            "--all"
+        ]
+        if name:
+            args.extend(["--name", name])
+        elif prefix:
+            args.extend(["--prefix", prefix])
+        
+        dlg = CondaExecDialog("update", self.__ui)
+        dlg.start(args)
+        dlg.exec_()
+        ok, _ = dlg.getResult()
+        
+        return ok
     
     def installPackages(self, packages, name="", prefix=""):
         """
@@ -399,9 +447,7 @@
         @type str
         @param prefix prefix of the environment
         @type str
-        @return list of installed packages. Each entry is a tuple containing
-            the package name, version and build.
-        @rtype list of tuples of (str, str, str)
+        @return flag indicating success
         @rtype bool
         @exception RuntimeError raised to indicate an error in parameters
         
@@ -425,9 +471,7 @@
         @type str
         @param prefix prefix of the environment
         @type str
-        @return list of installed packages. Each entry is a tuple containing
-            the package name, version and build.
-        @rtype list of tuples of (str, str, str)
+        @return flag indicating success
         @rtype bool
         @exception RuntimeError raised to indicate an error in parameters
         
@@ -439,4 +483,36 @@
         if not name and not prefix:
             raise RuntimeError("One of 'name' or 'prefix' must be given.")
         
-        # TODO: not implemented yet
+        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?"),
+                packages)
+            if dlg.exec_() == QDialog.Accepted:
+                from .CondaExecDialog import CondaExecDialog
+                
+                args = [
+                    "remove",
+                    "--json",
+                    "--yes",
+                ]
+                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

eric ide

mercurial