CondaInterface/CondaExecDialog.py

branch
conda
changeset 6697
2f5c951bdf14
parent 6685
fbaee9890715
child 6706
d792e054cde2
diff -r 706185900558 -r 2f5c951bdf14 CondaInterface/CondaExecDialog.py
--- a/CondaInterface/CondaExecDialog.py	Sun Feb 03 16:31:53 2019 +0100
+++ b/CondaInterface/CondaExecDialog.py	Sun Feb 03 16:59:36 2019 +0100
@@ -23,35 +23,29 @@
 from .Ui_CondaExecDialog import Ui_CondaExecDialog
 
 import Preferences
-from Globals import dataString
+import Globals
 
 
 class CondaExecDialog(QDialog, Ui_CondaExecDialog):
     """
     Class implementing a dialog to show the output of a conda execution.
     """
-    def __init__(self, configuration, venvManager, parent=None):
+    def __init__(self, command, parent=None):
         """
         Constructor
         
-        @param configuration dictionary containing the configuration parameters
-            as returned by the command configuration dialog
-        @type dict
-        @param venvManager reference to the virtual environment manager
-        @type VirtualenvManager
+        @param command conda command executed
+        @type str
         @param parent reference to the parent widget
         @type QWidget
         """
         super(CondaExecDialog, self).__init__(parent)
         self.setupUi(self)
         
-        self.__finishCommandMethods = {
-            "create": self.__finishCreate,
-        }
+        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
+        self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
         
-        self.__venvName = configuration["logicalName"]
-        self.__venvManager = venvManager
-        self.__condaCommand = configuration["command"]
+        self.__condaCommand = command
         
         self.__process = None
         self.__condaExe = Preferences.getConda("CondaExecutable")
@@ -92,6 +86,9 @@
         self.__firstProgress = True
         self.__lastFetchFile = ""
         
+        self.__statusOk = False
+        self.__result = None
+        
         self.__process = QProcess()
         self.__process.readyReadStandardOutput.connect(self.__readStdout)
         self.__process.readyReadStandardError.connect(self.__readStderr)
@@ -116,9 +113,12 @@
         It is called when the process finished or
         the user pressed the button.
         
-        @param exitCode exit code of the process (integer)
-        @param exitStatus exit status of the process (QProcess.ExitStatus)
-        @keyparam giveUp flag indicating to not start another attempt (boolean)
+        @param exitCode exit code of the process
+        @type int
+        @param exitStatus exit status of the process
+        @type QProcess.ExitStatus
+        @param giveUp flag indicating to not start another attempt
+        @type bool
         """
         if self.__process is not None and \
            self.__process.state() != QProcess.NotRunning:
@@ -133,48 +133,41 @@
         self.progressLabel.hide()
         self.progressBar.hide()
         
+        self.__statusOk = exitCode == 0
+        
         self.__logOutput(self.tr("Operation finished.\n"))
-        if self.__json:
-            if self.__bufferedStdout:
+        if not self.__json and self.__bufferedStdout:
+            self.__logOutput(self.__bufferedStdout)
+        
+        if self.__json and self.__bufferedStdout:
                 index = self.__bufferedStdout.find("{")
                 rindex = self.__bufferedStdout.rfind("}")
                 self.__bufferedStdout = self.__bufferedStdout[index:rindex + 1]
                 try:
-                    jsonDict = json.loads(self.__bufferedStdout)
+                    self.__result = json.loads(self.__bufferedStdout)
                 except Exception as error:
+                    self.__result = {}
                     self.__logError(str(error))
                     return
                 
-                if "error" in jsonDict:
-                    self.__logError(jsonDict["error"])
-                elif "success" in jsonDict and jsonDict["success"]:
-                    self.__finishCommandMethods[self.__condaCommand](jsonDict)
-                else:
+                if "error" in self.__result:
+                    self.__logError(self.__result["error"])
+                    self.__statusOk = False
+                elif "success" in self.__result and \
+                        not self.__result["success"]:
                     self.__logError(
                         self.tr("Conda command '{0}' did not return success.")
                         .format(self.__condaCommand))
-        elif self.__bufferedStdout:
-            self.__logOutput(self.__bufferedStdout)
+                    self.__statusOk = False
     
-    def __finishCreate(self, resultDict):
-        """
-        Private method to finish the 'create' command.
-        
-        @param resultDict dictionary containing the 'create' result data
-        @type dict
+    def getResult(self):
         """
-        if "actions" in resultDict and \
-                "PREFIX" in resultDict["actions"]:
-            prefix = resultDict["actions"]["PREFIX"]
-        elif "prefix" in resultDict:
-            prefix = resultDict["prefix"]
-        elif "dst_prefix" in resultDict:
-            prefix = resultDict["dst_prefix"]
-        else:
-            prefix = ""
-        self.__venvManager.addVirtualEnv(self.__venvName,
-                                         prefix,
-                                         isConda=True)
+        Public method to the result of the command execution.
+        
+        @return tuple containing a flag indicating success and the result data.
+        @rtype tuple of (bool, dict)
+        """
+        return self.__statusOk, self.__result
     
     def __setProgressValues(self, jsonDict, progressType):
         """
@@ -200,7 +193,7 @@
                 self.progressBar.setMaximum(jsonDict["maxval"])
                 self.progressBar.setValue(jsonDict["progress"])
                 filename = jsonDict["fetch"].strip()
-                filesize = dataString(int(jsonDict["maxval"]))
+                filesize = Globals.dataString(int(jsonDict["maxval"]))
             
             self.progressLabel.setText(
                 self.tr("{0} (Size: {1})").format(filename, filesize))

eric ide

mercurial