From 609fad38b5818806323757d816d9fac5ba3c8a4c Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 20 Mar 2020 19:58:03 +0100 Subject: Add first version capable of parsing very simple commands The script is able to parse very simple commands that don't wrap multiple lines. Signed-off-by: Olivier Gayot --- vish.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 vish.py (limited to 'vish.py') diff --git a/vish.py b/vish.py new file mode 100755 index 0000000..a8febc3 --- /dev/null +++ b/vish.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +import os +import re +import argparse + +class EOFException(Exception): + pass + + +class Instruction(): + def __init__(self, string: str): + # TODO handle quoting and escapments + keywords = string.split() + self.prog = keywords[0] + self.arguments = keywords[1:] + + + def execute(self): + cpid = os.fork() + if cpid == 0: + os.execvp(self.prog, [self.prog] + self.arguments) + else: + os.waitpid(cpid, 0) + + +def read_instruction(fh): + # TODO We should be reading an instruction, not a line. + while True: + line = fh.readline() + if line == "": + raise EOFException() + + line = line.strip() + # We ignore empty lines and lines which start with # + if not line.startswith("#") and not line == "": + break + + return Instruction(line) + + +def main(arguments): + for script in arguments["