src.cmd_types.output
Module to define command output
1""" 2Module to define command output 3""" 4from dataclasses import dataclass 5 6@dataclass 7class CommandOutput: 8 stdout: str = "" 9 stderr: str = "" 10 errcode: int = 0 11 12 def __add__(self, other): 13 if isinstance(other, str): 14 self.stdout += other 15 self.stderr += other 16 return self 17 elif not isinstance(other, CommandOutput): 18 raise TypeError 19 else: 20 if other.stdout: 21 self.stdout += other.stdout 22 if other.stderr: 23 self.stderr += other.stderr 24 if other.errcode != 0: 25 self.errcode = other.errcode 26 return self 27 28 def print(self): 29 if self.stderr: 30 print(self.stderr) 31 if self.stdout: 32 print(self.stdout) 33 34 def strip(self): 35 if self.stdout: 36 self.stdout = self.stdout.strip() 37 if self.stderr: 38 self.stderr = self.stderr.strip() 39 return self
@dataclass
class
CommandOutput:
7@dataclass 8class CommandOutput: 9 stdout: str = "" 10 stderr: str = "" 11 errcode: int = 0 12 13 def __add__(self, other): 14 if isinstance(other, str): 15 self.stdout += other 16 self.stderr += other 17 return self 18 elif not isinstance(other, CommandOutput): 19 raise TypeError 20 else: 21 if other.stdout: 22 self.stdout += other.stdout 23 if other.stderr: 24 self.stderr += other.stderr 25 if other.errcode != 0: 26 self.errcode = other.errcode 27 return self 28 29 def print(self): 30 if self.stderr: 31 print(self.stderr) 32 if self.stdout: 33 print(self.stdout) 34 35 def strip(self): 36 if self.stdout: 37 self.stdout = self.stdout.strip() 38 if self.stderr: 39 self.stderr = self.stderr.strip() 40 return self