Example #1
0
def main():
    # parse arguments and get command
    parser = CommandParser()
    command = parser.parse(sys.argv[1:])

    # execute command
    invoker = CommandInvoker()
    invoker.invoke(command)
Example #2
0
    try:

        network_manager.start()

        while True:

            network_manager.accept_client()
            ctrl = Controller(config)
            logger.info('Ready to receive commands from client')

            while True:

                try:
                    req = network_manager.receive()
                    cmd = parser.parse(req)
                    if not isinstance(cmd, Disconnect):
                        cmd.validate_arguments()
                        result = ctrl.exec_cmd(cmd)
                        response = Response(HTTPStatus.OK, result)
                        network_manager.send(response)
                    else:
                        network_manager.stop()
                        break
                except ParseError as e:
                    logger.warning('Invalid command received')
                    response = Response(HTTPStatus.BAD_REQUEST, e.errors)
                    network_manager.send(response)
                except ValidationError as e:
                    logger.warning('Invalid command received')
                    response = Response(HTTPStatus.BAD_REQUEST, e.get_msg())