def __interactive_deletion(repetitions): """Asks the user if wants to delete some repetitions""" saved_space = 0 if any(repetitions): for key in repetitions: print(colored('Found this repetitions:', 'green')) print(colored(repetitions[key], 'green')) for repetition in repetitions[key]: print(colored('Do you want to delete the file ' + repetition + ' ?', 'yellow')) var = input(colored('[y/n]', 'yellow')) if var == 'y': saved_space += crf_api.__get_size(repetition) os.remove(repetition) if len(repetitions[key]) <= 1: repetitions.pop(key, None) print(colored('Saved: ' + str(saved_space/1024) + ' Kb', 'blue'))
if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() parser.add_argument('directory', help='Directory to look for repetitions.') parser.add_argument('-a', '--approximate', help='It uses an approximate version of the' \ ' algorithm, it is faster but less reliable.', action='store_true') parser.add_argument('-i', '--interactive', help='If there is a repeated file, this option' \ ' lets you choose to delete one.', action='store_true') parser.add_argument('-f', '--fast', help='Delete the first repetition found without asking', action='store_true') args = parser.parse_args() print('Calculating repeated files') repetitions = crf_api.check_repeated_files(args.directory, args.approximate) print('Saving results in crf_log.txt') __save_repetitions(repetitions, args.directory) if args.interactive: __interactive_deletion(repetitions) elif args.fast: print(colored('Deleting files...', 'red')) saved_space = 0 for k in repetitions: repetitions[k].pop() for file in repetitions[k]: saved_space += crf_api.__get_size(file) print(colored('Deleted: ' + str(file), 'red')) os.remove(file)