def human_rule_sorter(r):
    """
    A function to help sort rules for human consumption.

    The idea here is to group rules by tables, priority, conjunction and port.
    """

    conjunctions = []

    dst_port = (r.fields.tp_dst if isinstance(r.fields.tp_dst, tuple)
                else (r.fields.tp_dst or 0, r.fields.tp_dst or 0))

    sort_keys = [r.table if r.table
                 else 0, -r.priority, conjunctions, dst_port]

    for action in r.actions:
        conj = action.conjunction
        if conj:
            conjunctions.append((-1 * conj.conj_id, conj.conj_k))
        conj_id = int(r.fields.get('conj_id', 0))
        if conj_id:
            conjunctions.insert(0, (-1 * conj_id, 99))

    conjunctions.sort()
    return sort_keys