--- a/CondaInterface/CondaExecDialog.py Tue Jan 29 20:21:26 2019 +0100 +++ b/CondaInterface/CondaExecDialog.py Tue Jan 29 20:22:17 2019 +0100 @@ -23,6 +23,7 @@ from .Ui_CondaExecDialog import Ui_CondaExecDialog import Preferences +from Globals import dataString class CondaExecDialog(QDialog, Ui_CondaExecDialog): @@ -84,6 +85,7 @@ self.__bufferedStdout = None self.__json = "--json" in arguments self.__firstProgress = True + self.__lastFetchFile = "" self.__process = QProcess() self.__process.readyReadStandardOutput.connect(self.__readStdout) @@ -123,17 +125,29 @@ self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) + self.progressLabel.hide() + self.progressBar.hide() + self.__logOutput(self.tr("Operation finished.\n")) if self.__json: if self.__bufferedStdout: + index = self.__bufferedStdout.find("{") + rindex = self.__bufferedStdout.rfind("}") + self.__bufferedStdout = self.__bufferedStdout[index:rindex + 1] try: jsonDict = json.loads(self.__bufferedStdout) except Exception as error: self.__logError(str(error)) return - if "success" in jsonDict and jsonDict["success"]: - if "prefix" in jsonDict: + if "error" in jsonDict: + self.__logError(jsonDict["error"]) + + elif "success" in jsonDict and jsonDict["success"]: + if "actions" in jsonDict and \ + "PREFIX" in jsonDict["actions"]: + prefix = jsonDict["actions"]["PREFIX"] + elif "prefix" in jsonDict: prefix = jsonDict["prefix"] elif "dst_prefix" in jsonDict: prefix = jsonDict["dst_prefix"] @@ -142,6 +156,8 @@ self.__venvManager.addVirtualEnv(self.__venvName, prefix, isConda=True) + elif self.__bufferedStdout: + self.__logOutput(self.__bufferedStdout) def __progressLabelString(self, text): """ @@ -154,8 +170,57 @@ @rtype str """ parts = text.split("|") - return self.tr("{0} (Size: {1})".format(parts[0].strip(), - parts[1].strip())) + if len(parts) > 1: + return self.tr("{0} (Size: {1})".format(parts[0].strip(), + parts[1].strip())) + else: + return parts[0].strip() + + def __setProgressValues(self, jsonDict, progressType): + """ + Private method to set the value of the progress bar. + + @param jsonDict dictionary containing the progress info + @type dict + @param progressType action type to check for + @type str + @return flag indicating success + @rtype bool + """ + if progressType in jsonDict and "progress" in jsonDict: + if jsonDict["maxval"] == 1: + self.progressBar.setMaximum(100) + # percent values + self.progressBar.setValue( + int(jsonDict["progress"] * 100)) + parts = jsonDict["fetch"].split("|") + filename = parts[0].strip() + filesize = parts[1].strip() + else: + self.progressBar.setMaximum(jsonDict["maxval"]) + self.progressBar.setValue(jsonDict["progress"]) + filename = jsonDict["fetch"].strip() + filesize = dataString(int(jsonDict["maxval"])) + + self.progressLabel.setText( + self.tr("{0} (Size: {1})").format(filename, filesize)) + + if progressType == "fetch": + if filename != self.__lastFetchFile: + self.__logOutput( + self.tr("Fetching {0} ...").format(filename)) + self.__lastFetchFile = filename + elif jsonDict["finished"]: + self.__logOutput(self.tr("Done.\n")) + + if self.__firstProgress: + self.progressLabel.show() + self.progressBar.show() + self.__firstProgress = False + + return True + + return False def __readStdout(self): """ @@ -172,16 +237,10 @@ for stdout in all_stdout.splitlines(): try: jsonDict = json.loads(stdout.replace("\x00", "").strip()) - if "progress" in jsonDict: - self.progressLabel.setText( - self.__progressLabelString(jsonDict["fetch"])) - self.progressBar.setValue( - int(jsonDict["progress"] * 100)) - if self.__firstProgress: - self.progressLabel.show() - self.progressBar.show() - self.__firstProgress = False - else: + if self.__setProgressValues(jsonDict, "fetch"): + # nothing to do anymore + pass + elif "progress" not in jsonDict: if self.__bufferedStdout is None: self.__bufferedStdout = stdout else: