diff options
author | Raúl Benencia <rul@kalgan.cc> | 2012-10-10 18:34:21 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2012-10-10 18:34:21 -0300 |
commit | 7ef52c68574b54333c44c5be739049deac3a28ec (patch) | |
tree | d86418475ecaf17087a40c90a26c31519b770e5c /pywhoisd_dataloader.py | |
parent | b3fcf3b4e9dc49b0736e8ba1dfdab2e225999c6d (diff) |
Data loader
Diffstat (limited to 'pywhoisd_dataloader.py')
-rwxr-xr-x | pywhoisd_dataloader.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/pywhoisd_dataloader.py b/pywhoisd_dataloader.py new file mode 100755 index 0000000..7b80ef5 --- /dev/null +++ b/pywhoisd_dataloader.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 +import signal, sys + +from lib.outputmanager import OutputManager +from lib.commandmanager import CommandManager +from lib.completionmanager import CompletionManager + +from lib.exceptions import CmdNotFoundException, CommandException + +class Manager: + def __init__(self): + self.loader = None + self.completer = CompletionManager() + + def start(self): + try: + signal.signal(signal.SIGINT, signal.default_int_handler) + while True: + try: + try: + line = input('% ') + except KeyboardInterrupt: + output_manager.line_break() + continue + + cmd_name = line.strip().split(' ') + if len(cmd_name) > 0 and len(cmd_name[0]) > 0: + cmd = cmd_manager.find(cmd_name[0]) + cmd.execute(self.loader, line[1:] if len(line) > 1 else []) + + except CommandException as err: + output_manager.error(str(err)).linebreak() + if err.print_usage: + output_manager.normal('Usage: {0}'.format(cmd.usage(line[0]))).line_break() + + except CmdNotFoundException as err: + output_manager.error('Error: {0}'.format(str(err))).linebreak() + + except EOFError: + output_manager.line_break() + exit(0) + except: + raise + +if __name__ == '__main__': + try: + manager = Manager() + cmd_manager = CommandManager() + output_manager = OutputManager() + manager.start() + + except: # TODO: Improve exceptions handling + print("Unexpected error:", sys.exc_info()[0]) + raise |