Ejemplo n.º 1
0
def list_with_base_rules(rawrules):
    """Combine the list of rules set by the user with the default push rules

    :param list rawrules: The rules the user has modified or set.
    :returns: A new list with the rules set by the user combined with the
        defaults.
    """
    ruleslist = []

    # Grab the base rules that the user has modified.
    # The modified base rules have a priority_class of -1.
    modified_base_rules = {
        r['rule_id']: r
        for r in rawrules if r['priority_class'] < 0
    }

    # Remove the modified base rules from the list, They'll be added back
    # in the default postions in the list.
    rawrules = [r for r in rawrules if r['priority_class'] >= 0]

    # shove the server default rules for each kind onto the end of each
    current_prio_class = PRIORITY_CLASS_INVERSE_MAP.keys()[-1]

    ruleslist.extend(
        make_base_prepend_rules(PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
                                modified_base_rules))

    for r in rawrules:
        if r['priority_class'] < current_prio_class:
            while r['priority_class'] < current_prio_class:
                ruleslist.extend(
                    make_base_append_rules(
                        PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
                        modified_base_rules,
                    ))
                current_prio_class -= 1
                if current_prio_class > 0:
                    ruleslist.extend(
                        make_base_prepend_rules(
                            PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
                            modified_base_rules,
                        ))

        ruleslist.append(r)

    while current_prio_class > 0:
        ruleslist.extend(
            make_base_append_rules(
                PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
                modified_base_rules,
            ))
        current_prio_class -= 1
        if current_prio_class > 0:
            ruleslist.extend(
                make_base_prepend_rules(
                    PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
                    modified_base_rules,
                ))

    return ruleslist
Ejemplo n.º 2
0
def list_with_base_rules(rawrules):
    ruleslist = []

    # shove the server default rules for each kind onto the end of each
    current_prio_class = PRIORITY_CLASS_INVERSE_MAP.keys()[-1]

    ruleslist.extend(make_base_prepend_rules(
        PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
    ))

    for r in rawrules:
        if r['priority_class'] < current_prio_class:
            while r['priority_class'] < current_prio_class:
                ruleslist.extend(make_base_append_rules(
                    PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
                ))
                current_prio_class -= 1
                if current_prio_class > 0:
                    ruleslist.extend(make_base_prepend_rules(
                        PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
                    ))

        ruleslist.append(r)

    while current_prio_class > 0:
        ruleslist.extend(make_base_append_rules(
            PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
        ))
        current_prio_class -= 1
        if current_prio_class > 0:
            ruleslist.extend(make_base_prepend_rules(
                PRIORITY_CLASS_INVERSE_MAP[current_prio_class]
            ))

    return ruleslist
Ejemplo n.º 3
0
def list_with_base_rules(rawrules):
    """Combine the list of rules set by the user with the default push rules

    Args:
        rawrules(list): The rules the user has modified or set.

    Returns:
        A new list with the rules set by the user combined with the defaults.
    """
    ruleslist = []

    # Grab the base rules that the user has modified.
    # The modified base rules have a priority_class of -1.
    modified_base_rules = {
        r['rule_id']: r for r in rawrules if r['priority_class'] < 0
    }

    # Remove the modified base rules from the list, They'll be added back
    # in the default postions in the list.
    rawrules = [r for r in rawrules if r['priority_class'] >= 0]

    # shove the server default rules for each kind onto the end of each
    current_prio_class = PRIORITY_CLASS_INVERSE_MAP.keys()[-1]

    ruleslist.extend(make_base_prepend_rules(
        PRIORITY_CLASS_INVERSE_MAP[current_prio_class], modified_base_rules
    ))

    for r in rawrules:
        if r['priority_class'] < current_prio_class:
            while r['priority_class'] < current_prio_class:
                ruleslist.extend(make_base_append_rules(
                    PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
                    modified_base_rules,
                ))
                current_prio_class -= 1
                if current_prio_class > 0:
                    ruleslist.extend(make_base_prepend_rules(
                        PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
                        modified_base_rules,
                    ))

        ruleslist.append(r)

    while current_prio_class > 0:
        ruleslist.extend(make_base_append_rules(
            PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
            modified_base_rules,
        ))
        current_prio_class -= 1
        if current_prio_class > 0:
            ruleslist.extend(make_base_prepend_rules(
                PRIORITY_CLASS_INVERSE_MAP[current_prio_class],
                modified_base_rules,
            ))

    return ruleslist
Ejemplo n.º 4
0
def list_with_base_rules(rawrules, user_name):
    ruleslist = []

    # shove the server default rules for each kind onto the end of each
    current_prio_class = PRIORITY_CLASS_INVERSE_MAP.keys()[-1]

    ruleslist.extend(
        make_base_prepend_rules(
            user_name, PRIORITY_CLASS_INVERSE_MAP[current_prio_class]))

    for r in rawrules:
        if r['priority_class'] < current_prio_class:
            while r['priority_class'] < current_prio_class:
                ruleslist.extend(
                    make_base_append_rules(
                        user_name,
                        PRIORITY_CLASS_INVERSE_MAP[current_prio_class]))
                current_prio_class -= 1
                if current_prio_class > 0:
                    ruleslist.extend(
                        make_base_prepend_rules(
                            user_name,
                            PRIORITY_CLASS_INVERSE_MAP[current_prio_class]))

        ruleslist.append(r)

    while current_prio_class > 0:
        ruleslist.extend(
            make_base_append_rules(
                user_name, PRIORITY_CLASS_INVERSE_MAP[current_prio_class]))
        current_prio_class -= 1
        if current_prio_class > 0:
            ruleslist.extend(
                make_base_prepend_rules(
                    user_name, PRIORITY_CLASS_INVERSE_MAP[current_prio_class]))

    return ruleslist