eric6/DebugClients/Python/QProcessExtension.py

Tue, 11 Feb 2020 18:58:38 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 11 Feb 2020 18:58:38 +0100
branch
multi_processing
changeset 7409
1413bfe73d41
parent 7407
a0b6acee2c20
child 7410
401791e6f50f
permissions
-rw-r--r--

Continued with the multiprocess debugger.

7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de>
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a function to patch QProcess to support debugging of the
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 process.
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
13 _debugClient = None
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
16 def patchQProcess(module, debugClient):
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 Function to patch the QtCore module's QProcess.
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 @param module reference to the imported module to be patched
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @type module
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
22 @param debugClient reference to the debug client object
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
23 @type DebugClient
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """ # __IGNORE_WARNING_D234__
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
25 global _debugClient
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 class QProcessWrapper(module.QProcess):
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Wrapper class for *.QProcess.
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 def __init__(self, parent=None):
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 Constructor
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 super(QProcessWrapper, self).__init__(parent)
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
37 def __modifyArgs(self, arguments, multiprocessSupport):
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 Private method to modify the arguments given to the start method.
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @param arguments list of program arguments
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 @type list of str
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @return modified argument list
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @rtype list of str
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 (wd, host, port, exceptions, tracePython, redirect,
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
47 noencoding) = _debugClient.startOptions[:7]
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
48
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 modifiedArguments = [
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 os.path.join(os.path.dirname(__file__), "DebugClient.py"),
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 "-h", host,
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 "-p", str(port),
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
53 "--no-passive",
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 ]
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 if wd:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 modifiedArguments.extend(["-w", wd])
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 if not exceptions:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 modifiedArguments.append("-e")
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 if tracePython:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 modifiedArguments.append("-t")
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 if not redirect:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 modifiedArguments.append("-n")
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 if noencoding:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 modifiedArguments.append("--no-encoding")
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
66 if multiprocessSupport:
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
67 modifiedArguments.append("--multiprocess")
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 modifiedArguments.append("--")
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 # end the arguments for DebugClient
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 modifiedArguments.extend(arguments)
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 return modifiedArguments
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 def start(self, *args, **kwargs):
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 Public method to start the process.
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 This method patches the arguments such, that a debug client is
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 started for the Python script. A Python script is assumed, if the
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 program to be started contains the string 'python'.
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @param args arguments of the start call
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @type list
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @param kwargs keyword arguments of the start call
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @type dict
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if (
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
88 _debugClient.debugging and
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
89 _debugClient.multiprocessSupport and
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
90 ((len(args) >= 2 and isinstance(args[1], list)) or
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
91 (len(args) == 1 and not isinstance(args[0], str)) or
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
92 len(args) == 0)
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 ):
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 # TODO: implement this
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 if len(args) >= 2:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 program = args[0]
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 arguments = args[1]
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if len(args) > 2:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 mode = args[2]
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 else:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 mode = module.QIODevice.ReadWrite
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 else:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 program = self.program()
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 arguments = self.arguments()
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 if len(args) == 1:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 mode = args[0]
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 else:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 mode = module.QIODevice.ReadWrite
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
109 if "python" in program.lower() and arguments[0] != "-m":
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 # assume a Python script is to be started
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
111 # '-m' option to python is not (yet) supported
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
112 newArgs = self.__modifyArgs(
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
113 arguments, _debugClient.multiprocessSupport)
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 super(QProcessWrapper, self).start(program, newArgs, mode)
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 else:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 super(QProcessWrapper, self).start(*args, **kwargs)
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 else:
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 super(QProcessWrapper, self).start(*args, **kwargs)
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7407
diff changeset
120 _debugClient = debugClient
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 module.QProcess = QProcessWrapper

eric ide

mercurial