Code Duplication    Length = 16-27 lines in 4 locations

utils/move_rules.py 1 location

@@ 72-87 (lines=16) @@
69
    return sec_ranges
70
71
72
def update_key_value(contents, key, old_value, new_value):
73
    new_contents = contents[:]
74
    old_line = key + ": " + old_value
75
    updated = False
76
77
    for line_num in range(0, len(new_contents)):
78
        line = new_contents[line_num]
79
        if line == old_line:
80
            new_contents[line_num] = key + ": " + new_value
81
            updated = True
82
            break
83
84
    if not updated:
85
        assert(False)
86
87
    return new_contents
88
89
90
def update_subkey_value(contents, key, subkey, old_value, new_value):

ssg/rule_yaml.py 1 location

@@ 84-110 (lines=27) @@
81
    return new_contents
82
83
84
def update_key_value(contents, key, old_value, new_value):
85
    """
86
    Find key in the contents of a file and replace its value with the new value,
87
    returning the resulting file. This validates that the old value is constant and
88
    hasn't changed since parsing its value.
89
90
    Raises a ValueError when the key cannot be found in the given contents.
91
92
    Does not modify the value of contents.
93
    """
94
95
    new_contents = contents[:]
96
    old_line = key + ": " + old_value
97
    updated = False
98
99
    for line_num in range(0, len(new_contents)):
100
        line = new_contents[line_num]
101
        if line == old_line:
102
            new_contents[line_num] = key + ": " + new_value
103
            updated = True
104
            break
105
106
    if not updated:
107
        raise ValueError("For key:%s, cannot find the old value (%s) in the given "
108
                         "contents." % (key, old_value))
109
110
    return new_contents
111
112
113
def remove_lines(contents, lines):

utils/duplicated_prodtypes.py 1 location

@@ 96-111 (lines=16) @@
93
    return sec_ranges
94
95
96
def update_key_value(contents, key, old_value, new_value):
97
    new_contents = contents[:]
98
    old_line = key + ": " + old_value
99
    updated = False
100
101
    for line_num in range(0, len(new_contents)):
102
        line = new_contents[line_num]
103
        if line == old_line:
104
            new_contents[line_num] = key + ": " + new_value
105
            updated = True
106
            break
107
108
    if not updated:
109
        assert(False)
110
111
    return new_contents
112
113
114
def update_subkey_value(contents, key, subkey, old_value, new_value):

utils/fix_file_ocilclause.py 1 location

@@ 96-111 (lines=16) @@
93
    return sec_ranges
94
95
96
def update_key_value(contents, key, old_value, new_value):
97
    new_contents = contents[:]
98
    old_line = key + ": " + old_value
99
    updated = False
100
101
    for line_num in range(0, len(new_contents)):
102
        line = new_contents[line_num]
103
        if line == old_line:
104
            new_contents[line_num] = key + ": " + new_value
105
            updated = True
106
            break
107
108
    if not updated:
109
        assert(False)
110
111
    return new_contents
112
113
114
def update_subkey_value(contents, key, subkey, old_value, new_value):