eric6/VirtualEnv/VirtualenvExecDialog.py

Wed, 30 Dec 2020 11:00:05 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:05 +0100
changeset 7923
91e843545d9a
parent 7900
72b88fb20261
child 8043
0acf98cd089a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7900
diff changeset
3 # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the virtualenv execution dialog.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import sys
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt5.QtCore import QProcess, QTimer, QUrl
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from PyQt5.QtGui import QDesktopServices
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from .Ui_VirtualenvExecDialog import Ui_VirtualenvExecDialog
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import Preferences
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 from Globals import isWindowsPlatform
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 class VirtualenvExecDialog(QDialog, Ui_VirtualenvExecDialog):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Class implementing the virtualenv execution dialog.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 This class starts a QProcess and displays a dialog that
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 shows the output of the virtualenv or pyvenv process.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
30 def __init__(self, configuration, venvManager, parent=None):
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Constructor
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
34 @param configuration dictionary containing the configuration parameters
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
35 as returned by the command configuration dialog
6678
5f1de9e59227 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
36 @type dict
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
37 @param venvManager reference to the virtual environment manager
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
38 @type VirtualenvManager
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
39 @param parent reference to the parent widget
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
40 @type QWidget
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 super(VirtualenvExecDialog, self).__init__(parent)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.setupUi(self)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
48 self.__pyvenv = configuration["envType"] == "pyvenv"
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
49 self.__targetDir = configuration["targetDirectory"]
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
50 self.__openTarget = configuration["openTarget"]
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
51 self.__createLog = configuration["createLog"]
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
52 self.__createScript = configuration["createScript"]
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
53 self.__venvName = configuration["logicalName"]
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
54 self.__venvManager = venvManager
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
56 self.__process = None
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__cmd = ""
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
59 if self.__pyvenv:
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__calls = []
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
61 if configuration["pythonExe"]:
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
62 self.__calls.append((configuration["pythonExe"],
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
63 ["-m", "venv"]))
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.__calls.extend([
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 (sys.executable.replace("w.exe", ".exe"),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 ["-m", "venv"]),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 ("python3", ["-m", "venv"]),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 ("python", ["-m", "venv"]),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 ])
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__calls = [
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 (sys.executable.replace("w.exe", ".exe"),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 ["-m", "virtualenv"]),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 ("virtualenv", []),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 ]
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.__callIndex = 0
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.__callArgs = []
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def start(self, arguments):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 Public slot to start the virtualenv command.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @param arguments commandline arguments for virtualenv/pyvenv program
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 (list of strings)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 if self.__callIndex == 0:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 # first attempt, add a given python interpreter and do
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 # some other setup
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.errorGroup.hide()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.contents.clear()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.errors.clear()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
93 self.__process = QProcess()
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
94 self.__process.readyReadStandardOutput.connect(self.__readStdout)
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
95 self.__process.readyReadStandardError.connect(self.__readStderr)
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
96 self.__process.finished.connect(self.__finish)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if not self.__pyvenv:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 for arg in arguments:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 if arg.startswith("--python="):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 prog = arg.replace("--python=", "")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.__calls.insert(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 0, (prog, ["-m", "virtualenv"]))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 break
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.__callArgs = arguments
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 prog, args = self.__calls[self.__callIndex]
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 args.extend(self.__callArgs)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.__cmd = "{0} {1}".format(prog, " ".join(args))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.__logOutput(self.tr("Executing: {0}\n").format(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.__cmd))
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
112 self.__process.start(prog, args)
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
113 procStarted = self.__process.waitForStarted(5000)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 if not procStarted:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 self.__logOutput(self.tr("Failed\n\n"))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 self.__nextAttempt()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 def on_buttonBox_clicked(self, button):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 Private slot called by a button of the button box clicked.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @param button button that was clicked (QAbstractButton)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if button == self.buttonBox.button(QDialogButtonBox.Close):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 self.accept()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
6674
f7b68db81452 VirtualenvExecDialog: fixed an issue causing 'Cancel' to throw an exception.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
127 self.__finish(0, 0, giveUp=True)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 def __finish(self, exitCode, exitStatus, giveUp=False):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 Private slot called when the process finished.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 It is called when the process finished or
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 the user pressed the button.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 @param exitCode exit code of the process (integer)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 @param exitStatus exit status of the process (QProcess.ExitStatus)
7900
72b88fb20261 Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
138 @param giveUp flag indicating to not start another attempt (boolean)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 """
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
140 if (
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
141 self.__process is not None and
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
142 self.__process.state() != QProcess.NotRunning
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
143 ):
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
144 self.__process.terminate()
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
145 QTimer.singleShot(2000, self.__process.kill)
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
146 self.__process.waitForFinished(3000)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if not giveUp:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 if exitCode != 0:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 self.__logOutput(self.tr("Failed\n\n"))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 if len(self.errors.toPlainText().splitlines()) == 1:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.errors.clear()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 self.errorGroup.hide()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.__nextAttempt()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 return
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
161 self.__process = None
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 if self.__pyvenv:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.__logOutput(self.tr('\npyvenv finished.\n'))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.__logOutput(self.tr('\nvirtualenv finished.\n'))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 if os.path.exists(self.__targetDir):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 if self.__createScript:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 self.__writeScriptFile()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 if self.__createLog:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self.__writeLogFile()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 if self.__openTarget:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 QDesktopServices.openUrl(QUrl.fromLocalFile(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 self.__targetDir))
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
178
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
179 self.__venvManager.addVirtualEnv(self.__venvName,
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
180 self.__targetDir)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 def __nextAttempt(self):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 Private method to start another attempt.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 self.__callIndex += 1
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 if self.__callIndex < len(self.__calls):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 self.start(self.__callArgs)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 if self.__pyvenv:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.__logError(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 self.tr('No suitable pyvenv program could be'
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 ' started.\n'))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.__logError(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 self.tr('No suitable virtualenv program could be'
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 ' started.\n'))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 self.__cmd = ""
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 self.__finish(0, 0, giveUp=True)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 def __readStdout(self):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 Private slot to handle the readyReadStandardOutput signal.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 It reads the output of the process, formats it and inserts it into
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 the contents pane.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 """
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
208 self.__process.setReadChannel(QProcess.StandardOutput)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
210 while self.__process.canReadLine():
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
211 s = str(self.__process.readLine(),
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 Preferences.getSystem("IOEncoding"),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 'replace')
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.__logOutput(s)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 def __readStderr(self):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 Private slot to handle the readyReadStandardError signal.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 It reads the error output of the process and inserts it into the
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 error pane.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 """
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
223 self.__process.setReadChannel(QProcess.StandardError)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
225 while self.__process.canReadLine():
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
226 s = str(self.__process.readLine(),
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 Preferences.getSystem("IOEncoding"),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 'replace')
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 self.__logError(s)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 def __logOutput(self, s):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 Private method to log some output.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234
6677
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6676
diff changeset
235 @param s output string to log (string)
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 self.contents.insertPlainText(s)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 self.contents.ensureCursorVisible()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 def __logError(self, s):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 Private method to log an error.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @param s error string to log (string)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 self.errorGroup.show()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 self.errors.insertPlainText(s)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 self.errors.ensureCursorVisible()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 def __writeLogFile(self):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 Private method to write a log file to the virtualenv directory.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 outtxt = self.contents.toPlainText()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 if self.__pyvenv:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 logFile = os.path.join(self.__targetDir, "pyvenv.log")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 logFile = os.path.join(self.__targetDir, "virtualenv.log")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 self.__logOutput(self.tr("\nWriting log file '{0}'.\n")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 .format(logFile))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
263 with open(logFile, "w", encoding="utf-8") as f:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
264 f.write(self.tr("Output:\n"))
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
265 f.write(outtxt)
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
266 errtxt = self.errors.toPlainText()
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
267 if errtxt:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
268 f.write("\n")
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
269 f.write(self.tr("Errors:\n"))
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
270 f.write(errtxt)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
271 except OSError as err:
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 self.__logError(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 self.tr("""The logfile '{0}' could not be written.\n"""
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 """Reason: {1}\n""").format(logFile, str(err)))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 self.__logOutput(self.tr("Done.\n"))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 def __writeScriptFile(self):
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 Private method to write a script file to the virtualenv directory.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 if self.__pyvenv:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 basename = "create_pyvenv"
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 basename = "create_virtualenv"
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 if isWindowsPlatform():
6495
6e73d31af3af Changed the extension of the generated script files for Windows from '.bat' to '.cmd'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6337
diff changeset
286 script = os.path.join(self.__targetDir, basename + ".cmd")
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 txt = self.__cmd
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 script = os.path.join(self.__targetDir, basename + ".sh")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 txt = "#!/usr/bin/env sh\n\n" + self.__cmd
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 self.__logOutput(self.tr("\nWriting script file '{0}'.\n")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 .format(script))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
296 with open(script, "w", encoding="utf-8") as f:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
297 f.write(txt)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
298 except OSError as err:
6014
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 self.__logError(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 self.tr("""The script file '{0}' could not be written.\n"""
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 """Reason: {1}\n""").format(script, str(err)))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 self.__logOutput(self.tr("Done.\n"))

eric ide

mercurial