Code Duplication    Length = 68-89 lines in 2 locations

utils/move_rules.py 2 locations

@@ 221-309 (lines=89) @@
218
    print()
219
220
221
def move_rule_linux_os(ssg_root, current_product, path, obj_name):
222
    global linux_os
223
224
    base_path = os.path.dirname(path)
225
    new_rule_dir = abs_join(base_path, obj_name)
226
    new_rule_path = abs_join(new_rule_dir, "rule.yml")
227
228
    assert not os.path.exists(new_rule_dir)
229
230
    sub_dirs = ['oval', 'bash', 'ansible', 'anaconda', 'puppet']
231
    new_rule_subdirs = [abs_join(new_rule_dir, j) for j in sub_dirs]
232
233
    product_list = set(['shared']).union(linux_os)
234
235
    move_templates = [
236
        {
237
            'source_dir': "%s/checks/oval",
238
            'source_name': "%s.xml",
239
            'dest_dir': new_rule_subdirs[0],
240
            'dest_name': "%s.xml"
241
        },
242
        {
243
            'source_dir': "%s/fixes/bash",
244
            'source_name': "%s.sh",
245
            'dest_dir': new_rule_subdirs[1],
246
            'dest_name': "%s.sh"
247
        },
248
        {
249
            'source_dir': "%s/fixes/ansible",
250
            'source_name': "%s.yml",
251
            'dest_dir': new_rule_subdirs[2],
252
            'dest_name': "%s.yml"
253
        },
254
        {
255
            'source_dir': "%s/fixes/anaconda",
256
            'source_name': "%s.anaconda",
257
            'dest_dir': new_rule_subdirs[3],
258
            'dest_name': "%s.anaconda"
259
        },
260
        {
261
            'source_dir': "%s/fixes/puppet",
262
            'source_name': "%s.pp",
263
            'dest_dir': new_rule_subdirs[4],
264
            'dest_name': "%s.pp"
265
        },
266
    ]
267
268
    moves = []
269
270
    # Generate possible build artifact paths and add them to the move queue.
271
    # The queue will later be filtered for existance before the move is
272
    # performed.
273
    for move_template in move_templates:
274
        for product in product_list:
275
            source_dir = move_template['source_dir'] % product
276
            source_name = move_template['source_name'] % obj_name
277
            source_file = abs_join(ssg_root, source_dir, source_name)
278
279
            dest_dir = move_template['dest_dir']
280
            dest_name = move_template['dest_name'] % product
281
            dest_file = abs_join(dest_dir, dest_name)
282
283
            moves.append((source_file, dest_file))
284
285
    # Find the test case location
286
    #assert path.startswith(ssg_root + "/")
287
    #without_ssg_root = path[len(ssg_root)+1:]
288
    #assert without_ssg_root.startswith("linux_os/guide/")
289
    #without_linuxos_guide = without_ssg_root[len("linux_os/guide/"):]
290
    #slash_split_paths = without_linuxos_guide.split(os.path.sep)
291
    #group_parts = list(map(lambda x: "group_" + x, slash_split_paths[:-1]))
292
    #rule_part = "rule_" + obj_name
293
    #test_path = abs_join(ssg_root, "tests", "data", *group_parts, rule_part)
294
295
    #if os.path.isdir(test_path):
296
    #    for _file in os.listdir(test_path):
297
    #        start_path = abs_join(test_path, _file)
298
    #        dest_path = abs_join(new_rule_subdirs[5], _file)
299
    #        moves.append((start_path, dest_path))
300
301
    print("mkdir -p '%s'" % new_rule_dir)
302
    for sub_dir in new_rule_subdirs:
303
        print("mkdir -p '%s'" % sub_dir)
304
    print("mv '%s' -v '%s'" % (path, new_rule_path))
305
    for move_tuple in moves:
306
        if os.path.exists(move_tuple[0]):
307
            print("mv '%s' -v '%s'" % move_tuple)
308
309
    print()
310
311
312
def fix_ocil_clause(ssg_root, path, obj_name):
@@ 151-218 (lines=68) @@
148
    return '{{' and '}}' in "\n".join(file_contents[range[0]:range[1]+1])
149
150
151
def move_rule_other(ssg_root, current_product, path, obj_name):
152
    base_path = os.path.dirname(path)
153
    new_rule_dir = abs_join(base_path, obj_name)
154
    new_rule_path = abs_join(new_rule_dir, "rule.yml")
155
156
    assert not os.path.exists(new_rule_dir)
157
158
    sub_dirs = ['oval', 'bash', 'ansible', 'anaconda', 'puppet']
159
    new_rule_subdirs = [abs_join(new_rule_dir, j) for j in sub_dirs]
160
161
    move_templates = [
162
        {
163
            'source_dir': "%s/checks/oval",
164
            'source_name': "%s.xml",
165
            'dest_dir': new_rule_subdirs[0],
166
            'dest_name': "%s.xml"
167
        },
168
        {
169
            'source_dir': "%s/fixes/bash",
170
            'source_name': "%s.sh",
171
            'dest_dir': new_rule_subdirs[1],
172
            'dest_name': "%s.sh"
173
        },
174
        {
175
            'source_dir': "%s/fixes/ansible",
176
            'source_name': "%s.yml",
177
            'dest_dir': new_rule_subdirs[2],
178
            'dest_name': "%s.yml"
179
        },
180
        {
181
            'source_dir': "%s/fixes/anaconda",
182
            'source_name': "%s.anaconda",
183
            'dest_dir': new_rule_subdirs[3],
184
            'dest_name': "%s.anaconda"
185
        },
186
        {
187
            'source_dir': "%s/fixes/puppet",
188
            'source_name': "%s.pp",
189
            'dest_dir': new_rule_subdirs[4],
190
            'dest_name': "%s.pp"
191
        },
192
    ]
193
194
    moves = []
195
196
    # Generate possible build artifact paths and add them to the move queue.
197
    # The queue will later be filtered for existance before the move is
198
    # performed.
199
    for move_template in move_templates:
200
        source_dir = move_template['source_dir'] % current_product
201
        source_name = move_template['source_name'] % obj_name
202
        source_file = abs_join(ssg_root, source_dir, source_name)
203
204
        dest_dir = move_template['dest_dir']
205
        dest_name = move_template['dest_name'] % current_product
206
        dest_file = abs_join(dest_dir, dest_name)
207
208
        moves.append((source_file, dest_file))
209
210
    print("mkdir -p '%s'" % new_rule_dir)
211
    for sub_dir in new_rule_subdirs:
212
        print("mkdir -p '%s'" % sub_dir)
213
    print("mv '%s' -v '%s'" % (path, new_rule_path))
214
    for move_tuple in moves:
215
        if os.path.exists(move_tuple[0]):
216
            print("mv '%s' -v '%s'" % move_tuple)
217
218
    print()
219
220
221
def move_rule_linux_os(ssg_root, current_product, path, obj_name):