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

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

utils/fix_file_ocilclause.py 1 location

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