Beispiel #1
0
def pretty_print(prelude, msg, format, format_payload, verbose_debug=False):
    service = msg[MSG_KEY_SERVICE]
    command_def = message_map.get(service, {}).get(msg[MSG_KEY_COMMAND_ID], None)
    command_name = command_def and command_def.get("name", None) or \
                                    '<id: %d>' % msg[MSG_KEY_COMMAND_ID]
    message_type = message_type_map[msg[MSG_KEY_TYPE]]
    if not MessageMap.filter or check_message(service, command_name, message_type): 
        print prelude
        if format:
            print "  message type:", message_type
            print "  service:", service
            print "  command:", command_name
            print "  format:", format_type_map[msg[MSG_KEY_FORMAT]]
            if MSG_KEY_STATUS in msg:
                print "  status:", status_map[msg[MSG_KEY_STATUS]]
            if MSG_KEY_CLIENT_ID in msg:
                print "  cid:", msg[MSG_KEY_CLIENT_ID]
            if MSG_KEY_UUID in msg:
                print "  uuid:", msg[MSG_KEY_UUID]
            if MSG_KEY_TAG in msg:
                print "  tag:", msg[MSG_KEY_TAG]
            if format_payload and not msg[MSG_KEY_TYPE] == MSG_TYPE_ERROR:
                payload = parse_json(msg[MSG_KEY_PAYLOAD])
                print "  payload:"
                if payload and command_def:
                    definition = command_def.get(msg[MSG_KEY_TYPE], None)
                    try:
                        pretty_print_payload(payload, definition, verbose_debug=verbose_debug)
                    except Exception, msg:
                        # print msg 
                        print "failed to pretty print the paylod. wrong message structure?"
                        print "%spayload: %s" % (INDENT, payload)
                        print "%sdefinition: %s" % (INDENT, definition)
                else:
                    print "    ", msg[MSG_KEY_PAYLOAD]
                print "\n"
            else:
                print "  payload:", msg[MSG_KEY_PAYLOAD], "\n"
        else:
            print msg
Beispiel #2
0
 def get_cmd_name(service, cmd_id):
     name = None
     if message_map:
         name = message_map.get(service, {}).get(int(cmd_id), {}).get("name")
     return name or cmd_id