Mon, 10 Feb 2020 18:49:49 +0100
Continued with the multiprocess debugger. Started with QProcess support.
# -*- coding: utf-8 -*- # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a function to patch QProcess to support debugging of the process. """ import os _startOptions = [] def patchQProcess(module, startOptions): """ Function to patch the QtCore module's QProcess. @param module reference to the imported module to be patched @type module @param startOptions reference to the saved start options @type tuple """ # __IGNORE_WARNING_D234__ global _startOptions class QProcessWrapper(module.QProcess): """ Wrapper class for *.QProcess. """ def __init__(self, parent=None): """ Constructor """ super(QProcessWrapper, self).__init__(parent) def __modifyArgs(self, arguments): """ Private method to modify the arguments given to the start method. @param arguments list of program arguments @type list of str @return modified argument list @rtype list of str """ (wd, host, port, exceptions, tracePython, redirect, noencoding) = _startOptions[:7] modifiedArguments = [ os.path.join(os.path.dirname(__file__), "DebugClient.py"), "-h", host, "-p", str(port), "--no-passive" ] if wd: modifiedArguments.extend(["-w", wd]) if not exceptions: modifiedArguments.append("-e") if tracePython: modifiedArguments.append("-t") if not redirect: modifiedArguments.append("-n") if noencoding: modifiedArguments.append("--no-encoding") modifiedArguments.append("--") # end the arguments for DebugClient modifiedArguments.extend(arguments) return modifiedArguments def start(self, *args, **kwargs): """ Public method to start the process. This method patches the arguments such, that a debug client is started for the Python script. A Python script is assumed, if the program to be started contains the string 'python'. @param args arguments of the start call @type list @param kwargs keyword arguments of the start call @type dict """ if ( (len(args) >= 2 and isinstance(args[1], list)) or (len(args) == 1 and not isinstance(args[0], str)) or len(args) == 0 ): # TODO: implement this if len(args) >= 2: program = args[0] arguments = args[1] if len(args) > 2: mode = args[2] else: mode = module.QIODevice.ReadWrite else: program = self.program() arguments = self.arguments() if len(args) == 1: mode = args[0] else: mode = module.QIODevice.ReadWrite if "python" in program.lower(): # assume a Python script is to be started newArgs = self.__modifyArgs(arguments) super(QProcessWrapper, self).start(program, newArgs, mode) else: super(QProcessWrapper, self).start(*args, **kwargs) else: super(QProcessWrapper, self).start(*args, **kwargs) _startOptions = startOptions[:] module.QProcess = QProcessWrapper