diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-03-21 02:00:16 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-03-21 12:42:43 +0100 |
commit | ed79e3d28b34e4826196529a6a7c04518c91b71f (patch) | |
tree | 4d130a1471173baf01afb01cf5a843d21f99cc28 /vish.py | |
parent | 18f21ff584ebf84408d28ff03b2c9fb0da8d3675 (diff) |
Implement AND & OR instructions
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'vish.py')
-rwxr-xr-x | vish.py | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -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(): |