Example #1
0
class CmdBackend(ExtBackend):
    from sys import stdout

    def __init__(self):
        self.cf = CmdFilter()
        self.wait = False
        ExtBackend.__init__(self)

    def connection_made(self):
        print "\n" + self.prompt(),
        self.stdout.flush()

    def line_received(self, line):
        self.proc_input(line)
        if not self.wait:
            print self.prompt(),
            self.stdout.flush()

    def prompt(self):
        if self.controller:
            return "beah> "
        else:
            return "waiting for controller... "

    def set_controller(self, controller=None):
        ExtBackend.set_controller(self, controller)
        print "\n" + self.prompt(),
        self.stdout.flush()

    def proc_input(self, data):
        if not self.wait:
            cmd = self.cf.proc_line(data)
            if cmd:
                self.controller.proc_cmd(self, cmd)
                self.wait = True
        else:
            print "busy. waiting for echo..."

    def proc_evt_echo(self, evt):
        if self.wait:
            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."
                    return
                if evt.args()['rc'] == ECHO.EXCEPTION:
                    print "--- ERROR: Command raised an exception."
                    print evt.args()['exception']
                    return
            finally:
                print self.prompt(),
                self.stdout.flush()

    def post_proc(self, evt, answ):
        if self.wait:
            pprint.pprint(evt)
        return answ
Example #2
0
class CmdBackend(ExtBackend):
    from sys import stdout

    def __init__(self):
        self.cf = CmdFilter()
        self.wait = False
        ExtBackend.__init__(self)

    def connection_made(self):
        print "\n" + self.prompt(),
        self.stdout.flush()

    def line_received(self, line):
        self.proc_input(line)
        if not self.wait:
            print self.prompt(),
            self.stdout.flush()

    def prompt(self):
        if self.controller:
            return "beah> "
        else:
            return "waiting for controller... "

    def set_controller(self, controller=None):
        ExtBackend.set_controller(self, controller)
        print "\n" + self.prompt(),
        self.stdout.flush()

    def proc_input(self, data):
        if not self.wait:
            cmd = self.cf.proc_line(data)
            if cmd:
                self.controller.proc_cmd(self, cmd)
                self.wait = True
        else:
            print "busy. waiting for echo..."

    def proc_evt_echo(self, evt):
        if self.wait:
            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."
                    return
                if evt.args()['rc'] == ECHO.EXCEPTION:
                    print "--- ERROR: Command raised an exception."
                    print evt.args()['exception']
                    return
            finally:
                print self.prompt(),
                self.stdout.flush()

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