Example #1
0
File: cli.py Project: sssst315/beah
class CmdLineBackend(ExtBackend):
    def __init__(self, cmdline):
        from beah.filters.cmdfilter import CmdFilter
        self.wait = False
        self.cmd = CmdFilter().proc_line(cmdline)
        if not self.cmd:
            print "--- ERROR: Command error."
            raise exceptions.Exception

    def set_controller(self, controller=None):
        ExtBackend.set_controller(self, controller)
        if controller:
            #controller.proc_cmd(self, command.ping("Are you there?"))
            controller.proc_cmd(self, command.no_output())
            controller.proc_cmd(self, self.cmd)
            self.wait = True

    def proc_evt_echo(self, evt):
        if evt.arg('cmd_id', '') == self.cmd.id():
            global rc
            try:
                self.wait = False
                if evt.args()['rc'] == ECHO.OK:
                    print "OK"
                    return
                if evt.args()['rc'] == ECHO.NOT_IMPLEMENTED:
                    print "--- ERROR: Command is not implemented."
                    rc = 1
                    return
                if evt.args()['rc'] == ECHO.EXCEPTION:
                    print "--- ERROR: Command raised an exception."
                    print evt.args()['exception']
                    rc = 1
                    return
                return
            finally:
                self.proc_evt_bye(evt)

    def post_proc(self, evt, answ):
        if self.wait:
            pprint.pprint(evt)
        return answ
Example #2
0
class CmdLineBackend(ExtBackend):
    def __init__(self, cmdline):
        from beah.filters.cmdfilter import CmdFilter
        self.wait = False
        self.cmd = CmdFilter().proc_line(cmdline)
        if not self.cmd:
            print "--- ERROR: Command error."
            raise exceptions.Exception

    def set_controller(self, controller=None):
        ExtBackend.set_controller(self, controller)
        if controller:
            #controller.proc_cmd(self, command.ping("Are you there?"))
            controller.proc_cmd(self, command.no_output())
            controller.proc_cmd(self, self.cmd)
            self.wait = True

    def proc_evt_echo(self, evt):
        if evt.arg('cmd_id', '') == self.cmd.id():
            global rc
            try:
                self.wait = False
                if evt.args()['rc'] == ECHO.OK:
                    print "OK"
                    return
                if evt.args()['rc'] == ECHO.NOT_IMPLEMENTED:
                    print "--- ERROR: Command is not implemented."
                    rc = 1
                    return
                if evt.args()['rc'] == ECHO.EXCEPTION:
                    print "--- ERROR: Command raised an exception."
                    print evt.args()['exception']
                    rc = 1
                    return
                return
            finally:
                self.proc_evt_bye(evt)

    def post_proc(self, evt, answ):
        if self.wait:
            pprint.pprint(evt)
        return answ