Code Duplication    Length = 16-27 lines in 4 locations

utils/duplicated_prodtypes.py 1 location

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

utils/fix_file_ocilclause.py 1 location

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

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):