Code Duplication    Length = 15-21 lines in 2 locations

src/docmanager/action.py 2 locations

@@ 306-326 (lines=21) @@
303
        validfiles, invalidfiles = self.get_files_status(self.__xml)
304
305
        for f in self.__files:
306
            if "error" in self.__xml[f]:
307
                print("[{}] {} -> {}".format(red(" error "), f, red(self.__xml[f]["errorstr"])))
308
            else:
309
                try:
310
                    errors = self.__xml[f]["handler"].del_attr(prop, attrs)
311
                    self.__xml[f]["handler"].write()
312
313
                    if errors:
314
                        print("[{}] These attributes couldn't be deleted for {}: {}".format(
315
                            yellow(" notice "), f, ", ".join(errors)
316
                        ))
317
                    else:
318
                        print("[{}] Deleted attributes for file {}.".format(green(" ok "), f))
319
320
                except DMPropertyNotFound:
321
                    print("[{}] Property {} was not found in {}.".format(red(" error "), yellow(prop), f))
322
323
                    # we must substract 1 of "validfiles" since XML files are valid even
324
                    # if they don't have the given property.
325
                    validfiles -= 1
326
                    invalidfiles += 1
327
328
        # print the statistics output
329
        print("\nWrote {} valid XML file{} and skipped {} XML file{} due to errors.".format(
@@ 262-276 (lines=15) @@
259
                sys.exit(ReturnCodes.E_INVALID_USAGE_KEYVAL)
260
261
        for f in self.__files:
262
            if "error" in self.__xml[f]:
263
                print("[{}] {} -> {}".format(red(" error "), f, red(self.__xml[f]["errorstr"])))
264
            else:
265
                try:
266
                    self.__xml[f]["handler"].set_attr(prop, data)
267
                    self.__xml[f]["handler"].write()
268
269
                    print("[{}] Set attributes for file {}.".format(green(" ok "), f))
270
                except DMPropertyNotFound:
271
                    print("[{}] Property {} was not found in {}.".format(red(" error "), yellow(prop), f))
272
273
                    # we must substract 1 of "validfiles" since XML files are valid even
274
                    # if they don't have the given property.
275
                    validfiles -= 1
276
                    invalidfiles += 1
277
278
        # print the statistics output
279
        print("\nWrote {} valid XML file{} and skipped {} XML file{} due to errors.".format(