improve docstrings

This commit is contained in:
Bastian Schroll 2019-03-05 08:33:35 +01:00
parent 0b3d71cd4a
commit 0cb79569dd

View file

@ -21,6 +21,7 @@ logging.debug("- %s loaded", __name__)
class ProcessManager: class ProcessManager:
"""!class to manage a extern sub process"""
def __init__(self, process, textMode=False): def __init__(self, process, textMode=False):
logging.debug("create process instance %s - textMode: %s", process, textMode) logging.debug("create process instance %s - textMode: %s", process, textMode)
self._args = [] self._args = []
@ -35,13 +36,18 @@ class ProcessManager:
self.stop() self.stop()
def addArgument(self, arg): def addArgument(self, arg):
"""!add a new argument
@param arg: argument to add as string"""
logging.debug("add argument to process: %s -> %s", self._args[0], arg) logging.debug("add argument to process: %s -> %s", self._args[0], arg)
self._args.append(arg) self._args.append(arg)
def clearArguments(self): def clearArguments(self):
self._args = [] """!clear all arguments"""
self._args = self._args[0:1] # kept first element (process name)
def start(self): def start(self):
"""!start the new process"""
logging.debug("start new process: %s", self._args[0]) logging.debug("start new process: %s", self._args[0])
self._processHandle = subprocess.Popen(self._args, self._processHandle = subprocess.Popen(self._args,
stdin=self._stdin, stdin=self._stdin,
@ -50,6 +56,9 @@ class ProcessManager:
universal_newlines=self._textMode) universal_newlines=self._textMode)
def stop(self): def stop(self):
"""!Stop the process by sending SIGTERM and wait for ending
@return return code of process"""
if self._processHandle and self.isRunning: if self._processHandle and self.isRunning:
logging.debug("stopping process: %s", self._args[0]) logging.debug("stopping process: %s", self._args[0])
self._processHandle.terminate() self._processHandle.terminate()
@ -60,7 +69,9 @@ class ProcessManager:
return 0 return 0
def readline(self): def readline(self):
"""!Read one line from stdout stream or None""" """!Read one line from stdout stream
@return singe line or None"""
if self.isRunning and self._stdout is not None: if self.isRunning and self._stdout is not None:
try: try:
line = self._processHandle.stdout.readline().strip() line = self._processHandle.stdout.readline().strip()
@ -71,29 +82,32 @@ class ProcessManager:
return None return None
def setStdin(self, stdin): def setStdin(self, stdin):
"""!Set the stdin stream""" """!Set the stdin stream instance"""
self._stdin = stdin self._stdin = stdin
def setStdout(self, stdout): def setStdout(self, stdout):
"""!Set the stdout stream""" """!Set the stdout stream instance"""
self._stdout = stdout self._stdout = stdout
def setStderr(self, stderr): def setStderr(self, stderr):
"""!Set the stderr stream""" """!Set the stderr stream instance"""
self._stderr = stderr self._stderr = stderr
@property @property
def stdout(self): def stdout(self):
"""!Get the stdout stream""" """!Property to get the stdout stream"""
return self._processHandle.stdout return self._processHandle.stdout
@property @property
def stderr(self): def stderr(self):
"""!Get the stderr stream""" """!Property to get the stderr stream"""
return self._processHandle.stderr return self._processHandle.stderr
@property @property
def isRunning(self): def isRunning(self):
"""!Property to get process running state
@return True or False"""
if self._processHandle: if self._processHandle:
if self._processHandle.poll() is None: if self._processHandle.poll() is None:
return True return True