Code Duplication    Length = 37-37 lines in 2 locations

utils/fix-rules.py 1 location

@@ 136-172 (lines=37) @@
133
        print("%d: %s" % (line_num, file_contents[line_num]))
134
135
136
def find_section_lines(file_contents, sec):
137
    # Hack to find a global key ("section"/sec) in a YAML-like file.
138
    # All indented lines until the next global key are included in the range.
139
    # For example:
140
    #
141
    # 0: not_it:
142
    # 1:     - value
143
    # 2: this_one:
144
    # 3:      - 2
145
    # 4:      - 5
146
    # 5:
147
    # 6: nor_this:
148
    #
149
    # for the section "this_one", the result [(2, 5)] will be returned.
150
    # Note that multiple sections may exist in a file and each will be
151
    # identified and returned.
152
    sec_ranges = []
153
154
    sec_id = sec + ":"
155
    sec_len = len(sec_id)
156
    end_num = len(file_contents)
157
    line_num = 0
158
159
    while line_num < end_num:
160
        if len(file_contents[line_num]) >= sec_len:
161
            if file_contents[line_num][0:sec_len] == sec_id:
162
                begin = line_num
163
                line_num += 1
164
                while line_num < end_num:
165
                    if len(file_contents[line_num]) > 0 and file_contents[line_num][0] != ' ':
166
                        break
167
                    line_num += 1
168
169
                end = line_num - 1
170
                sec_ranges.append((begin, end))
171
        line_num += 1
172
    return sec_ranges
173
174
175
def remove_lines(file_contents, lines):

utils/fix_file_ocilclause.py 1 location

@@ 56-92 (lines=37) @@
53
    _f.close()
54
55
56
def find_section_lines(file_contents, sec):
57
    # Hack to find a global key ("section"/sec) in a YAML-like file.
58
    # All indented lines until the next global key are included in the range.
59
    # For example:
60
    #
61
    # 0: not_it:
62
    # 1:     - value
63
    # 2: this_one:
64
    # 3:      - 2
65
    # 4:      - 5
66
    # 5:
67
    # 6: nor_this:
68
    #
69
    # for the section "this_one", the result [(2, 5)] will be returned.
70
    # Note that multiple sections may exist in a file and each will be
71
    # identified and returned.
72
    sec_ranges = []
73
74
    sec_id = sec + ":"
75
    sec_len = len(sec_id)
76
    end_num = len(file_contents)
77
    line_num = 0
78
79
    while line_num < end_num:
80
        if len(file_contents[line_num]) >= sec_len:
81
            if file_contents[line_num][0:sec_len] == sec_id:
82
                begin = line_num
83
                line_num += 1
84
                while line_num < end_num:
85
                    if len(file_contents[line_num]) > 0 and file_contents[line_num][0] != ' ':
86
                        break
87
                    line_num += 1
88
89
                end = line_num - 1
90
                sec_ranges.append((begin, end))
91
        line_num += 1
92
    return sec_ranges
93
94
95
def update_key_value(contents, key, old_value, new_value):