from sqlite3 import connect from shell.Handlers.InstanceHandler import InstanceHandler class Handler: def __init__(self): self.exec_succeed = True self.global_commands = GlobalCommandsHandler() self.instance_commands = InstanceHandler() pass def handle(self, command: list[str]): if len(command) == 0: return verb = command[0].upper() if verb == 'CHECK': if not self.exec_succeed: raise RuntimeWarning("Last command execution failed") else: return else: self.exec_succeed = False if verb == 'PYTHONAPP': self.instance_commands.handle(command[1:]) else: self.global_commands.handle(command) self.exec_succeed = True class GlobalCommandsHandler: def __init__(self): pass def _unknown_command(self, command: list[str]): command_str = '' for word in command: command_str += word + ' ' raise ValueError(f"Unknown command: {command_str}") def handle(self, command: list[str]): if len(command) == 0: return verb = command[0].upper() if verb == "TELL": command_str = '' for word in command[1:]: command_str += word + ' ' print(command_str) elif verb == "EXIT": raise KeyboardInterrupt else: self._unknown_command(command) return