Sun, 10 Dec 2017 12:27:28 +0100
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
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 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2014 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
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 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | def __init__(self, pyvenv, targetDir, openTarget, createLog, createScript, |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | interpreter, parent=None): |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | Constructor |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | @param pyvenv flag indicating the use of 'pyvenv' (boolean) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | @param targetDir name of the virtualenv directory (string) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | @param openTarget flag indicating to open 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
|
44 | in a file manager (boolean) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | @param createLog flag indicating to create a log file of the |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | creation process (boolean) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | @param createScript flag indicating to create a script to recreate |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | the virtual environment (boolean) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | @param interpreter name of the python interpreter to use (string) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | @param parent reference to the parent widget (QWidget) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | 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
|
53 | 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
|
54 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | 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
|
56 | 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
|
57 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | self.__pyvenv = pyvenv |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | self.__targetDir = targetDir |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | self.__openTarget = openTarget |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | self.__createLog = createLog |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | self.__createScript = createScript |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | self.process = None |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | self.__cmd = "" |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | if pyvenv: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | self.__calls = [] |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | if interpreter: |
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.append((interpreter, ["-m", "venv"])) |
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.extend([ |
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", "venv"]), |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | ("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
|
75 | ("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
|
76 | ]) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | else: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | self.__calls = [ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | (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
|
80 | ["-m", "virtualenv"]), |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | ("virtualenv", []), |
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 | 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
|
84 | self.__callArgs = [] |
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 | 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
|
87 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | 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
|
89 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | @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
|
91 | (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
|
92 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | 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
|
94 | # 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
|
95 | # 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
|
96 | 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
|
97 | 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
|
98 | 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
|
99 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | self.process = QProcess() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | self.process.readyReadStandardOutput.connect(self.__readStdout) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | self.process.readyReadStandardError.connect(self.__readStderr) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | self.process.finished.connect(self.__finish) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | 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
|
106 | 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
|
107 | 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
|
108 | 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
|
109 | 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
|
110 | 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
|
111 | break |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | 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
|
113 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | 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
|
115 | 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
|
116 | 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
|
117 | 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
|
118 | self.__cmd)) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | self.process.start(prog, args) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | procStarted = self.process.waitForStarted(5000) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | 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
|
122 | 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
|
123 | self.__nextAttempt() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | 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
|
126 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | 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
|
128 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | @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
|
130 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | 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
|
132 | self.accept() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | self.__finish() |
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 | 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
|
137 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | 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
|
139 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | 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
|
141 | 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
|
142 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | @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
|
144 | @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
|
145 | @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
|
146 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | if self.process is not None and \ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | self.process.state() != QProcess.NotRunning: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | self.process.terminate() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | QTimer.singleShot(2000, self.process.kill) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | self.process.waitForFinished(3000) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | |
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.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
|
154 | 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
|
155 | 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
|
156 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | 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
|
158 | 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
|
159 | 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
|
160 | 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
|
161 | 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
|
162 | 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
|
163 | self.__nextAttempt() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | return |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | self.process = None |
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 self.__pyvenv: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | 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
|
170 | else: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | 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
|
172 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | 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
|
174 | 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
|
175 | self.__writeScriptFile() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | 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
|
178 | self.__writeLogFile() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | 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
|
181 | 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
|
182 | self.__targetDir)) |
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 | 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
|
185 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | 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
|
187 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | 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
|
189 | 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
|
190 | 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
|
191 | else: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | 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
|
193 | self.__logError( |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | 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
|
195 | ' started.\n')) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | else: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | self.__logError( |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | 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
|
199 | ' started.\n')) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | self.__cmd = "" |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | 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
|
202 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | 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
|
204 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | 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
|
206 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | 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
|
208 | 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
|
209 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | self.process.setReadChannel(QProcess.StandardOutput) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | while self.process.canReadLine(): |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | s = str(self.process.readLine(), |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | 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
|
215 | 'replace') |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | 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
|
217 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | 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
|
219 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | 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
|
221 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | 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
|
223 | error pane. |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | self.process.setReadChannel(QProcess.StandardError) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | while self.process.canReadLine(): |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | s = str(self.process.readLine(), |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | 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
|
230 | 'replace') |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | 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
|
232 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | 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
|
234 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | 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
|
236 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | @param s output sstring 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
|
238 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | 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
|
240 | 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
|
241 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | 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
|
243 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | 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
|
245 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | @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
|
247 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | 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
|
249 | 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
|
250 | 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
|
251 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | 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
|
253 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | 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
|
255 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | 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
|
257 | 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
|
258 | 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
|
259 | else: |
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, "virtualenv.log") |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | 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
|
262 | .format(logFile)) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | try: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | 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
|
266 | 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
|
267 | 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
|
268 | 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
|
269 | if errtxt: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | 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
|
271 | 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
|
272 | 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
|
273 | f.close() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | 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
|
275 | self.__logError( |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | 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
|
277 | """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
|
278 | 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
|
279 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | 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
|
281 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | 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
|
283 | """ |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | 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
|
285 | 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
|
286 | else: |
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_virtualenv" |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | if isWindowsPlatform(): |
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 + ".bat") |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | 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
|
291 | else: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | 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
|
293 | 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
|
294 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | 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
|
296 | .format(script)) |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | try: |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | 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
|
300 | 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
|
301 | f.close() |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | 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
|
303 | self.__logError( |
d3375a0a3240
Added the virtualenv/pyvenv interface plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | 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
|
305 | """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
|
306 | self.__logOutput(self.tr("Done.\n")) |