Code Duplication    Length = 26-26 lines in 2 locations

utils/move_rules.py 1 location

@@ 312-337 (lines=26) @@
309
    print()
310
311
312
def fix_ocil_clause(ssg_root, path, obj_name):
313
    is_file_templated = obj_name[0:4] == 'file'
314
    is_permissions = '_permissions_' in obj_name
315
    is_groupowner = '_groupowner_' in obj_name
316
    is_owner = '_owner_' in obj_name
317
318
    if not is_file_templated or not (is_permissions or is_groupowner or is_owner):
319
        return
320
321
    loaded_file = read_file(path)
322
    sections = get_sections(loaded_file)
323
    if not 'ocil_clause' in sections:
324
        ocil_lines = find_section_lines(loaded_file, 'ocil')
325
        assert(len(ocil_lines) == 1)
326
        ocil_lines = ocil_lines[0]
327
328
        ocil = parse_from_yaml(loaded_file, ocil_lines)['ocil']
329
        if '{{{' not in ocil:
330
            print(path)
331
332
        ocil_clause_str = ocil.replace('ocil_', 'ocil_clause_')
333
        new_line = "ocil_clause: '%s'" % ocil_clause_str
334
        new_file = loaded_file[:ocil_lines[0]]
335
        new_file.extend([new_line, ''])
336
        new_file.extend(loaded_file[ocil_lines[0]:])
337
        write_file(path, new_file)
338
339
340
def parse_from_yaml(file_contents, lines):

utils/fix_file_ocilclause.py 1 location

@@ 175-200 (lines=26) @@
172
    return '{{' and '}}' in "\n".join(file_contents[range[0]:range[1]+1])
173
174
175
def fix_ocil_clause(ssg_root, path, obj_name):
176
    is_file_templated = obj_name[0:4] == 'file'
177
    is_permissions = '_permissions_' in obj_name
178
    is_groupowner = '_groupowner_' in obj_name
179
    is_owner = '_owner_' in obj_name
180
181
    if not is_file_templated or not (is_permissions or is_groupowner or is_owner):
182
        return
183
184
    loaded_file = read_file(path)
185
    sections = get_sections(loaded_file)
186
    if not 'ocil_clause' in sections:
187
        ocil_lines = find_section_lines(loaded_file, 'ocil')
188
        assert(len(ocil_lines) == 1)
189
        ocil_lines = ocil_lines[0]
190
191
        ocil = parse_from_yaml(loaded_file, ocil_lines)['ocil']
192
        if '{{{' not in ocil:
193
            print(path)
194
195
        ocil_clause_str = ocil.replace('ocil_', 'ocil_clause_')
196
        new_line = "ocil_clause: '%s'" % ocil_clause_str
197
        new_file = loaded_file[:ocil_lines[0]]
198
        new_file.extend([new_line, ''])
199
        new_file.extend(loaded_file[ocil_lines[0]:])
200
        write_file(path, new_file)
201
202
203
def parse_from_yaml(file_contents, lines):