CondaInterface/CondaExecDialog.py

branch
conda
changeset 6683
aca9d39fbfbd
parent 6679
c5f7b2e9a06d
child 6685
fbaee9890715
equal deleted inserted replaced
6682:4326e802ff56 6683:aca9d39fbfbd
21 from E5Gui import E5MessageBox 21 from E5Gui import E5MessageBox
22 22
23 from .Ui_CondaExecDialog import Ui_CondaExecDialog 23 from .Ui_CondaExecDialog import Ui_CondaExecDialog
24 24
25 import Preferences 25 import Preferences
26 from Globals import dataString
26 27
27 28
28 class CondaExecDialog(QDialog, Ui_CondaExecDialog): 29 class CondaExecDialog(QDialog, Ui_CondaExecDialog):
29 """ 30 """
30 Class implementing a dialog to show the output of a conda execution. 31 Class implementing a dialog to show the output of a conda execution.
82 self.progressBar.setValue(0) 83 self.progressBar.setValue(0)
83 84
84 self.__bufferedStdout = None 85 self.__bufferedStdout = None
85 self.__json = "--json" in arguments 86 self.__json = "--json" in arguments
86 self.__firstProgress = True 87 self.__firstProgress = True
88 self.__lastFetchFile = ""
87 89
88 self.__process = QProcess() 90 self.__process = QProcess()
89 self.__process.readyReadStandardOutput.connect(self.__readStdout) 91 self.__process.readyReadStandardOutput.connect(self.__readStdout)
90 self.__process.readyReadStandardError.connect(self.__readStderr) 92 self.__process.readyReadStandardError.connect(self.__readStderr)
91 self.__process.finished.connect(self.__finish) 93 self.__process.finished.connect(self.__finish)
121 123
122 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 124 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
123 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 125 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
124 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 126 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
125 127
128 self.progressLabel.hide()
129 self.progressBar.hide()
130
126 self.__logOutput(self.tr("Operation finished.\n")) 131 self.__logOutput(self.tr("Operation finished.\n"))
127 if self.__json: 132 if self.__json:
128 if self.__bufferedStdout: 133 if self.__bufferedStdout:
134 index = self.__bufferedStdout.find("{")
135 rindex = self.__bufferedStdout.rfind("}")
136 self.__bufferedStdout = self.__bufferedStdout[index:rindex + 1]
129 try: 137 try:
130 jsonDict = json.loads(self.__bufferedStdout) 138 jsonDict = json.loads(self.__bufferedStdout)
131 except Exception as error: 139 except Exception as error:
132 self.__logError(str(error)) 140 self.__logError(str(error))
133 return 141 return
134 142
135 if "success" in jsonDict and jsonDict["success"]: 143 if "error" in jsonDict:
136 if "prefix" in jsonDict: 144 self.__logError(jsonDict["error"])
145
146 elif "success" in jsonDict and jsonDict["success"]:
147 if "actions" in jsonDict and \
148 "PREFIX" in jsonDict["actions"]:
149 prefix = jsonDict["actions"]["PREFIX"]
150 elif "prefix" in jsonDict:
137 prefix = jsonDict["prefix"] 151 prefix = jsonDict["prefix"]
138 elif "dst_prefix" in jsonDict: 152 elif "dst_prefix" in jsonDict:
139 prefix = jsonDict["dst_prefix"] 153 prefix = jsonDict["dst_prefix"]
140 else: 154 else:
141 prefix = "" 155 prefix = ""
142 self.__venvManager.addVirtualEnv(self.__venvName, 156 self.__venvManager.addVirtualEnv(self.__venvName,
143 prefix, 157 prefix,
144 isConda=True) 158 isConda=True)
159 elif self.__bufferedStdout:
160 self.__logOutput(self.__bufferedStdout)
145 161
146 def __progressLabelString(self, text): 162 def __progressLabelString(self, text):
147 """ 163 """
148 Private method to process a string and format it for the progress 164 Private method to process a string and format it for the progress
149 label. 165 label.
152 @type str 168 @type str
153 @return formatted progress label string 169 @return formatted progress label string
154 @rtype str 170 @rtype str
155 """ 171 """
156 parts = text.split("|") 172 parts = text.split("|")
157 return self.tr("{0} (Size: {1})".format(parts[0].strip(), 173 if len(parts) > 1:
158 parts[1].strip())) 174 return self.tr("{0} (Size: {1})".format(parts[0].strip(),
175 parts[1].strip()))
176 else:
177 return parts[0].strip()
178
179 def __setProgressValues(self, jsonDict, progressType):
180 """
181 Private method to set the value of the progress bar.
182
183 @param jsonDict dictionary containing the progress info
184 @type dict
185 @param progressType action type to check for
186 @type str
187 @return flag indicating success
188 @rtype bool
189 """
190 if progressType in jsonDict and "progress" in jsonDict:
191 if jsonDict["maxval"] == 1:
192 self.progressBar.setMaximum(100)
193 # percent values
194 self.progressBar.setValue(
195 int(jsonDict["progress"] * 100))
196 parts = jsonDict["fetch"].split("|")
197 filename = parts[0].strip()
198 filesize = parts[1].strip()
199 else:
200 self.progressBar.setMaximum(jsonDict["maxval"])
201 self.progressBar.setValue(jsonDict["progress"])
202 filename = jsonDict["fetch"].strip()
203 filesize = dataString(int(jsonDict["maxval"]))
204
205 self.progressLabel.setText(
206 self.tr("{0} (Size: {1})").format(filename, filesize))
207
208 if progressType == "fetch":
209 if filename != self.__lastFetchFile:
210 self.__logOutput(
211 self.tr("Fetching {0} ...").format(filename))
212 self.__lastFetchFile = filename
213 elif jsonDict["finished"]:
214 self.__logOutput(self.tr("Done.\n"))
215
216 if self.__firstProgress:
217 self.progressLabel.show()
218 self.progressBar.show()
219 self.__firstProgress = False
220
221 return True
222
223 return False
159 224
160 def __readStdout(self): 225 def __readStdout(self):
161 """ 226 """
162 Private slot to handle the readyReadStandardOutput signal. 227 Private slot to handle the readyReadStandardOutput signal.
163 228
170 all_stdout = all_stdout.replace("\x00", "") 235 all_stdout = all_stdout.replace("\x00", "")
171 if self.__json: 236 if self.__json:
172 for stdout in all_stdout.splitlines(): 237 for stdout in all_stdout.splitlines():
173 try: 238 try:
174 jsonDict = json.loads(stdout.replace("\x00", "").strip()) 239 jsonDict = json.loads(stdout.replace("\x00", "").strip())
175 if "progress" in jsonDict: 240 if self.__setProgressValues(jsonDict, "fetch"):
176 self.progressLabel.setText( 241 # nothing to do anymore
177 self.__progressLabelString(jsonDict["fetch"])) 242 pass
178 self.progressBar.setValue( 243 elif "progress" not in jsonDict:
179 int(jsonDict["progress"] * 100))
180 if self.__firstProgress:
181 self.progressLabel.show()
182 self.progressBar.show()
183 self.__firstProgress = False
184 else:
185 if self.__bufferedStdout is None: 244 if self.__bufferedStdout is None:
186 self.__bufferedStdout = stdout 245 self.__bufferedStdout = stdout
187 else: 246 else:
188 self.__bufferedStdout += stdout 247 self.__bufferedStdout += stdout
189 except (TypeError, ValueError): 248 except (TypeError, ValueError):

eric ide

mercurial