VirtualEnv/VirtualenvExecDialog.py

Sat, 02 Mar 2019 11:15:24 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 02 Mar 2019 11:15:24 +0100
branch
maintenance
changeset 6826
c6dda2cbe081
parent 6696
706185900558
permissions
-rw-r--r--

Merged with default branch to prepare a new release.

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
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6495
diff changeset
3 # Copyright (c) 2014 - 2019 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 from __future__ import unicode_literals
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 try:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 str = unicode
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 except NameError:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 pass
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import sys
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import os
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 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
20 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
21 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
22
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 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
24
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 import Preferences
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 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
27
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 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
30 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 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
32
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 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
34 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
35 """
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
36 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
37 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Constructor
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
40 @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
41 as returned by the command configuration dialog
6678
5f1de9e59227 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
42 @type dict
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
43 @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
44 @type VirtualenvManager
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
45 @param parent reference to the parent widget
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
46 @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
47 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 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
49 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
50
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 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
52 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
53
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
54 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
55 self.__targetDir = configuration["targetDirectory"]
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
56 self.__openTarget = configuration["openTarget"]
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
57 self.__createLog = configuration["createLog"]
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
58 self.__createScript = configuration["createScript"]
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
59 self.__venvName = configuration["logicalName"]
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
60 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
61
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
62 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
63 self.__cmd = ""
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
65 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
66 self.__calls = []
6676
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
67 if configuration["pythonExe"]:
536ad4fa35aa VirtualenvExecDialog: changed the interface to use a configuration dictionary.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
68 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
69 ["-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
70 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
71 (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
72 ["-m", "venv"]),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 ("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
74 ("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
75 ])
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.__calls = [
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 (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
79 ["-m", "virtualenv"]),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 ("virtualenv", []),
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 ]
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83 self.__callArgs = []
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 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
86 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 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
88
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 @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
90 (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
91 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 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
93 # 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
94 # 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
95 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
96 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
97 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
98
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
99 self.__process = QProcess()
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
100 self.__process.readyReadStandardOutput.connect(self.__readStdout)
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
101 self.__process.readyReadStandardError.connect(self.__readStderr)
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
102 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
103
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 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
105 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
106 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
107 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
108 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
109 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
110 break
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 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
112
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 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
114 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
115 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
116 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
117 self.__cmd))
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
118 self.__process.start(prog, args)
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
119 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
120 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
121 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
122 self.__nextAttempt()
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 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
125 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 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
127
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @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
129 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 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
131 self.accept()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 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
133 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
134
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 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
136 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 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
138
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 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
140 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
141
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 @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
143 @param exitStatus exit status of the process (QProcess.ExitStatus)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 @keyparam giveUp flag indicating to not start another attempt (boolean)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
146 if self.__process is not None and \
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
147 self.__process.state() != QProcess.NotRunning:
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
148 self.__process.terminate()
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
149 QTimer.singleShot(2000, self.__process.kill)
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
150 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
151
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 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
153 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
154 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
155
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 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
157 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
158 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
159 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
160 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
161 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
162 self.__nextAttempt()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 return
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
165 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
166
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 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
168 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
169 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 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
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 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
173 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
174 self.__writeScriptFile()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 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
177 self.__writeLogFile()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 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
180 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
181 self.__targetDir))
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
182
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
183 self.__venvManager.addVirtualEnv(self.__venvName,
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
184 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
185
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 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
187 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 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
189 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 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
191 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
192 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
193 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 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
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 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
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 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 self.__logError(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 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
201 ' started.\n'))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 self.__cmd = ""
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 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
204
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 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
206 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 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
208
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 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
210 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
211 """
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
212 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
213
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
214 while self.__process.canReadLine():
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
215 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
216 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
217 'replace')
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 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
219
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 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
221 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 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
223
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 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
225 error pane.
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 """
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
227 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
228
6337
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
229 while self.__process.canReadLine():
c6af560e0039 VirtualEnv: started implementing a virtualenv manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
230 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
231 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
232 'replace')
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 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
234
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 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
236 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 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
238
6677
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6676
diff changeset
239 @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
240 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 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
242 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
243
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 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
245 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 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
247
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 @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
249 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 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
251 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
252 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
253
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 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
255 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 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
257 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 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
259 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
260 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
261 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 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
263 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
264 .format(logFile))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 try:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 f = open(logFile, "w", encoding="utf-8")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 f.write(self.tr("Output:\n"))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 f.write(outtxt)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 errtxt = self.errors.toPlainText()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 if errtxt:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 f.write("\n")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 f.write(self.tr("Errors:\n"))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 f.write(errtxt)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 f.close()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 except (IOError, OSError) as err:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 self.__logError(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 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
279 """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
280 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
281
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 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
283 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 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
285 """
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 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
287 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
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 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
290 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
291 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
292 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
293 else:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 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
295 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
296
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 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
298 .format(script))
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 try:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 f = open(script, "w", encoding="utf-8")
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 f.write(txt)
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 f.close()
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 except (IOError, OSError) as err:
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 self.__logError(
d3375a0a3240 Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 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
307 """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
308 self.__logOutput(self.tr("Done.\n"))

eric ide

mercurial