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