Sun, 27 Jan 2019 19:52:37 +0100
Continued implementing environment creation with conda.
6677
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

1  # * coding: utf8 * 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

2  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

3  # Copyright (c) 2019 Detlev Offenbach <detlev@dieoffenbachs.de> 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

4  # 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

5  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

6  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

7  Module implementing a dialog to show the output of a conda execution. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

8  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

9  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

10  from __future__ import unicode_literals 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

11  try: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

12  str = unicode 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

13  except NameError: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

14  pass 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

15  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

16  import json 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

17  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

18  from PyQt5.QtCore import pyqtSlot, QProcess, QTimer 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

19  from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

20  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

21  from E5Gui import E5MessageBox 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

22  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

23  from .Ui_CondaExecDialog import Ui_CondaExecDialog 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

24  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

25  import Preferences 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

26  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

27  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

28  class CondaExecDialog(QDialog, Ui_CondaExecDialog): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

29  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

30  Class documentation goes here. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

31  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

32  def __init__(self, configuration, venvManager, parent=None): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

33  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

34  Constructor 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

35  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

36  @param parent reference to the parent widget 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

37  @type QWidget 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

38  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

39  super(CondaExecDialog, self).__init__(parent) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

40  self.setupUi(self) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

41  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

42  self.__venvName = configuration["logicalName"] 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

43  self.__venvManager = venvManager 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

44  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

45  self.__process = None 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

46  self.__condaExe = Preferences.getConda("CondaExecutable") 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

47  if not self.__condaExe: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

48  self.__condaExe = "conda" 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

49  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

50  @pyqtSlot(QAbstractButton) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

51  def on_buttonBox_clicked(self, button): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

52  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

53  Private slot called by a button of the button box clicked. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

54  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

55  @param button button that was clicked 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

56  @type QAbstractButton 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

57  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

58  if button == self.buttonBox.button(QDialogButtonBox.Close): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

59  self.accept() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

60  elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

61  self.__finish() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

62  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

63  def start(self, arguments): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

64  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

65  Public slot to start the conda command. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

66  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

67  @param arguments commandline arguments for conda program 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

68  @type list of str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

69  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

70  self.errorGroup.hide() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

71  self.progressLabel.hide() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

72  self.progressBar.hide() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

73  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

74  self.contents.clear() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

75  self.errors.clear() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

76  self.progressLabel.clear() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

77  self.progressBar.setValue(0) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

78  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

79  self.__bufferedStdout = None 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

80  self.__json = "json" in arguments 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

81  self.__firstProgress = True 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

82  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

83  self.__process = QProcess() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

84  self.__process.readyReadStandardOutput.connect(self.__readStdout) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

85  self.__process.readyReadStandardError.connect(self.__readStderr) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

86  self.__process.finished.connect(self.__finish) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

87  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

88  self.__process.start(self.__condaExe, arguments) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

89  procStarted = self.__process.waitForStarted(5000) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

90  if not procStarted: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

91  E5MessageBox.critical( 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

92  self, 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

93  self.tr("Conda Execution"), 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

94  self.tr("""The conda executable could not be started. Is it""" 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

95  """ configured correctly?""")) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

96  self.__finish(1, 0) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

97  else: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

98  self.__logOutput(self.tr("Operation started.\n")) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

99  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

100  def __finish(self, exitCode, exitStatus, giveUp=False): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

101  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

102  Private slot called when the process finished. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

103  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

104  It is called when the process finished or 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

105  the user pressed the button. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

106  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

107  @param exitCode exit code of the process (integer) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

108  @param exitStatus exit status of the process (QProcess.ExitStatus) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

109  @keyparam giveUp flag indicating to not start another attempt (boolean) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

110  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

111  if self.__process is not None and \ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

112  self.__process.state() != QProcess.NotRunning: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

113  self.__process.terminate() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

114  QTimer.singleShot(2000, self.__process.kill) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

115  self.__process.waitForFinished(3000) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

116  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

117  self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

118  self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

119  self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

120  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

121  self.__logOutput(self.tr("Operation finished.\n")) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

122  if self.__json: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

123  if self.__bufferedStdout: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

124  try: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

125  jsonDict = json.loads(self.__bufferedStdout) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

126  except Exception as error: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

127  self.__logError(str(error)) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

128  return 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

129  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

130  if "success" in jsonDict and jsonDict["success"]: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

131  if "prefix" in jsonDict: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

132  prefix = jsonDict["prefix"] 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

133  elif "dst_prefix" in jsonDict: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

134  prefix = jsonDict["dst_prefix"] 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

135  else: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

136  prefix = "" 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

137  self.__venvManager.addVirtualEnv(self.__venvName, 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

138  prefix, 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

139  isConda=True) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

140  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

141  def __progressLabelString(self, text): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

142  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

143  Private method to process a string and format it for the progress 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

144  label. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

145  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

146  @param text text to be processed 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

147  @type str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

148  @return formatted progress label string 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

149  @rtype str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

150  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

151  parts = text.split("") 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

152  return self.tr("{0} (Size: {1})".format(parts[0].strip(), 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

153  parts[1].strip())) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

154  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

155  def __readStdout(self): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

156  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

157  Private slot to handle the readyReadStandardOutput signal. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

158  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

159  It reads the output of the process, formats it and inserts it into 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

160  the contents pane. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

161  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

162  all_stdout = str(self.__process.readAllStandardOutput(), 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

163  Preferences.getSystem("IOEncoding"), 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

164  'replace') 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

165  all_stdout = all_stdout.replace("\x00", "") 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

166  if self.__json: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

167  for stdout in all_stdout.splitlines(): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

168  try: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

169  jsonDict = json.loads(stdout.replace("\x00", "").strip()) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

170  if "progress" in jsonDict: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

171  self.progressLabel.setText( 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

172  self.__progressLabelString(jsonDict["fetch"])) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

173  self.progressBar.setValue( 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

174  int(jsonDict["progress"] * 100)) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

175  if self.__firstProgress: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

176  self.progressLabel.show() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

177  self.progressBar.show() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

178  self.__firstProgress = False 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

179  else: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

180  if self.__bufferedStdout is None: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

181  self.__bufferedStdout = stdout 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

182  else: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

183  self.__bufferedStdout += stdout 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

184  except (TypeError, ValueError): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

185  if self.__bufferedStdout is None: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

186  self.__bufferedStdout = stdout 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

187  else: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

188  self.__bufferedStdout += stdout 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

189  else: 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

190  self.__logOutput(all_stdout) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

191  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

192  def __readStderr(self): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

193  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

194  Private slot to handle the readyReadStandardError signal. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

195  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

196  It reads the error output of the process and inserts it into the 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

197  error pane. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

198  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

199  self.__process.setReadChannel(QProcess.StandardError) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

200  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

201  while self.__process.canReadLine(): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

202  stderr = str(self.__process.readLine(), 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

203  Preferences.getSystem("IOEncoding"), 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

204  'replace') 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

205  self.__logError(stderr) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

206  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

207  def __logOutput(self, stdout): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

208  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

209  Private method to log some output. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

210  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

211  @param stdout output string to log 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

212  @type str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

213  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

214  self.contents.insertPlainText(stdout) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

215  self.contents.ensureCursorVisible() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

216  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

217  def __logError(self, stderr): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

218  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

219  Private method to log an error. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

220  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

221  @param stderr error string to log 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

222  @type str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

223  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

224  self.errorGroup.show() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

225  self.errors.insertPlainText(stderr) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

226  self.errors.ensureCursorVisible() 