CondaInterface/Conda.py

branch
conda
changeset 6728
ba077788a882
parent 6724
ca89c7d94c94
--- a/CondaInterface/Conda.py	Mon Feb 11 19:33:12 2019 +0100
+++ b/CondaInterface/Conda.py	Mon Feb 11 19:57:53 2019 +0100
@@ -24,7 +24,7 @@
 import Globals
 import Preferences
 
-from . import rootPrefix
+from . import rootPrefix, condaVersion
 from .CondaExecDialog import CondaExecDialog
 
 
@@ -456,8 +456,6 @@
         if not name and not prefix:
             raise RuntimeError("One of 'name' or 'prefix' must be given.")
         
-        # TODO: not implemented yet
-        
         if packages:
             args = [
                 "install",
@@ -517,8 +515,9 @@
                     "remove",
                     "--json",
                     "--yes",
-                    "--prune",
                 ]
+                if condaVersion() >= (4, 4, 0):
+                    args.append("--prune",)
                 if name:
                     args.extend(["--name", name])
                 elif prefix:
@@ -610,6 +609,9 @@
     def updateConda(self):
         """
         Public method to update conda itself.
+        
+        @return flag indicating success
+        @rtype bool
         """
         args = [
             "update",
@@ -630,7 +632,7 @@
         Public method to create a conda configuration with default values.
         """
         args = [
-            "config", 
+            "config",
             "--write-default",
             "--quiet"
         ]
@@ -660,7 +662,7 @@
         proc = QProcess()
         proc.start(exe, ["info", "--json"])
         if proc.waitForStarted(15000):
-            if proc.waitForFinished(15000):
+            if proc.waitForFinished(30000):
                 output = str(proc.readAllStandardOutput(),
                              Preferences.getSystem("IOEncoding"),
                              'replace').strip()
@@ -670,3 +672,63 @@
                     infoDict = {}
         
         return infoDict
+    
+    def runProcess(self, args):
+        """
+        Public method to execute the conda with the given arguments.
+        
+        The conda executable is called with the given arguments and
+        waited for its end.
+        
+        @param args list of command line arguments
+        @type list of str
+        @return tuple containing a flag indicating success and the output
+            of the process
+        @rtype tuple of (bool, str)
+        """
+        exe = Preferences.getConda("CondaExecutable")
+        if not exe:
+            exe = "conda"
+        
+        process = QProcess()
+        process.start(exe, args)
+        procStarted = process.waitForStarted(15000)
+        if procStarted:
+            finished = process.waitForFinished(30000)
+            if finished:
+                if process.exitCode() == 0:
+                    output = str(process.readAllStandardOutput(),
+                                 Preferences.getSystem("IOEncoding"),
+                                 'replace').strip()
+                    return True, output
+                else:
+                    return (False,
+                            self.tr("conda exited with an error ({0}).")
+                            .format(process.exitCode()))
+            else:
+                process.terminate()
+                process.waitForFinished(2000)
+                process.kill()
+                process.waitForFinished(3000)
+                return False, self.tr("conda did not finish within"
+                                      " 30 seconds.")
+        
+        return False, self.tr("conda could not be started.")
+    
+    def cleanConda(self, cleanAction):
+        """
+        Public method to update conda itself.
+        
+        @param cleanAction cleaning action to be performed (must be one of
+            the command line parameters without '--')
+        @type str
+        """
+        args = [
+            "clean",
+            "--yes",
+            "--{0}".format(cleanAction),
+        ]
+        
+        dlg = CondaExecDialog("clean", self.__ui)
+        dlg.start(args)
+        dlg.exec_()

eric ide

mercurial