Пример #1
0
        def result_from_commands():
            while True:
                msg = self.results.recv_json()

                # -- Block here

                status = msg[command.STATUS]

                # Status: OK
                #  __________
                # |          |
                # |    OK    |
                # |__________|

                if status == command.OK:
                    self.post_command(msg)

                # Status: FAIL
                #  __________
                # |          |
                # |   FAIL   |
                # |__________|

                elif status == command.FAIL:
                    time.sleep(0.1)
                    print "\nE: %s" % msg[command.INFO]
                    command.init_shell()

                # Status: ERROR
                #  ___________
                # |           |
                # |   ERROR   |
                # |___________|

                else:
                    print "This should not happen"

                # Prepare output message
                msg = {
                    command.STATUS: command.OK,
                    command.INFO: None
                }

                self.results.send_json(msg)
Пример #2
0
    def post_command(self, message):
        """The command has been transmitted and executed successfully

        Note:
            Undo and redo commands aren't processed on the client until
            the server has confirmed their successful execution.

            This is the main reason why Undo is blocking by default.

        """

        # A command was undone, remove from history.
        #  __________
        # |          |
        # |   Undo   |
        # |__________|

        if command.UNDO in message:
            undo_id = message[command.UNDO]

            try:
                self.HISTORY.remove(undo_id)
            except ValueError:
                print ("This isn't supposed to happen "
                       "(undo_id=%s)" % undo_id)
                command.init_shell()

            self.FUTURE.append(undo_id)

        # A command was redone, remove from future.
        #  __________
        # |          |
        # |   Redo   |
        # |__________|

        elif command.REDO in message:
            redo_id = message[command.REDO]

            try:
                self.FUTURE.remove(redo_id)
            except ValueError:
                print ("This isn't supposed to happen "
                       "(undo_id=%s)" % undo_id)
                command.init_shell()

            self.HISTORY.append(redo_id)

        # A command was executed, store it in history.
        #  ___________
        # |           |
        # |   Store   |
        # |___________|

        elif command.ID in message:
            command_id = message[command.ID]

            # Clear redo queue
            while self.FUTURE:
                self.FUTURE.pop()

            self.HISTORY.append(command_id)

        if command.INFO in message:
            reply = message[command.INFO]
            if reply is not None:
                if message.get(command.BLOCKING):
                    print reply
                else:
                    # If messages are returned asynchronously,
                    # make sure to notify user that there is
                    # a message coming in.
                    print "- incoming message -"
                    print reply
                    command.init_shell()
Пример #3
0
        command.cls()

    def exit(self):
        raise KeyboardInterrupt


if __name__ == '__main__':
    """Client ('customer')"""
    import sys
    command.cls()

    try:
        invoker = Invoker(*sys.argv[1:])

    except command.Connection as e:
        print e

    else:
        try:
            while True:
                command.init_shell()
                input_ = raw_input()

                parts = input_.split()
                cmd, args = parts[0], parts[1:]

                invoker.execute(cmd, *args)

        except KeyboardInterrupt:
            print "\nGood bye"