From ed79e3d28b34e4826196529a6a7c04518c91b71f Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sat, 21 Mar 2020 02:00:16 +0100 Subject: Implement AND & OR instructions Signed-off-by: Olivier Gayot --- vish.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'vish.py') diff --git a/vish.py b/vish.py index 608a8b4..8d8f6e1 100755 --- a/vish.py +++ b/vish.py @@ -49,7 +49,30 @@ class Instruction(): os.execvp(self.prog, [self.prog] + self.args) else: - os.waitpid(cpid, 0) + _, status = os.waitpid(cpid, 0) + return status + + +class AndInstruction(Instruction): + def __init__(self, instruction1: Instruction, instruction2: Instruction): + self.instruction1 = instruction1 + self.instruction2 = instruction2 + + def execute(self): + status = self.instruction1.execute() + if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0: + return self.instruction2.execute() + + +class OrInstruction(Instruction): + def __init__(self, instruction1: Instruction, instruction2: Instruction): + self.instruction1 = instruction1 + self.instruction2 = instruction2 + + def execute(self): + status = self.instruction1.execute() + if not os.WIFEXITED(status) or not os.WEXITSTATUS(status) == 0: + return self.instruction2.execute() class PipelineParser(): -- cgit v1.2.3