示例#1
0
文件: cli.py 项目: sssst315/beah
 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
示例#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
示例#3
0
 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
示例#4
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
示例#5
0
文件: cli.py 项目: 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
示例#6
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
示例#7
0
 def __init__(self):
     self.cf = CmdFilter()
     self.wait = False
     ExtBackend.__init__(self)
示例#8
0
 def __init__(self):
     self.cf = CmdFilter()
     self.wait = False
     ExtBackend.__init__(self)