From cb1f3d8bfcd657d45768ce6c0507aa1d9e20f3b6 Mon Sep 17 00:00:00 2001 From: Gra Date: Thu, 28 May 2009 14:41:10 +0200 Subject: [PATCH] Added the auto-fix feature. --- pl.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/pl.py b/pl.py index bc99cc4..718f610 100755 --- a/pl.py +++ b/pl.py @@ -79,6 +79,9 @@ def main(): "SCORE must be between 0 and 1, 1 is the perfect match (useless):\n" + \ "" parser.usage = parser.usage[:-1] # remove the final \n + parser.add_option('-a', '--auto-fix', default=False, + action='store_true', dest='auto_fix', + help="check - change a missing entry to the first suggestion") parser.add_option('-d', '--delete', default=False, action='store_true', dest='delete', help="check - delete entries that were not found") @@ -121,9 +124,11 @@ def main(): parser.error("You must provide at least one playlist.") if not 0 < options.score <= 1: parser.error("SCORE must be between 0 and 1.") - # default auto-fix score - if options.fix and options.score == 1: + # default min score for fixing + if (options.fix or options.auto_fix) and options.score == 1: options.score = 0.8 + if options.auto_fix: + options.fix = True if options.delete: user_in = raw_input("Type 'delete' to confirm.\n") if user_in.strip().lower() != 'delete': @@ -240,19 +245,29 @@ def playlist_is_ok(playlist, options): entry=missing_item[len(options.target):], new=missing_item[len(options.target):]) else: - print "could be" - max_suggs = 5 - nbr_suggs = min(max_suggs, len(suggs)) - for sugg_idx in range(nbr_suggs): - if options.fix: - print sugg_idx + 1, - print format_item(suggs[sugg_idx], + if options.auto_fix: + nbr_suggs = 1 + print "automaticly replaced by", + print format_item(suggs[0], options=options, indent=4) + else: + print "could be" + max_suggs = 5 + nbr_suggs = min(max_suggs, len(suggs)) + for sugg_idx in range(nbr_suggs): + if options.fix: + print sugg_idx + 1, + print format_item(suggs[sugg_idx], + options=options, + indent=4) if options.fix: - message = 'Which one to use? [%s, nothing to ignore] ' - seq = ''.join([str(num + 1) for num in range(nbr_suggs)]) - replace = raw_input(message % seq) + if options.auto_fix: + replace = '1' + else: + message = 'Which one to use? [%s, nothing to ignore] ' + seq = ''.join([str(num + 1) for num in range(nbr_suggs)]) + replace = raw_input(message % seq) if replace.strip(): try: number = int(replace) - 1 -- 2.45.1