From a463e5451b92d99e12ff6ab5f9f3169942f4c056 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 17 Oct 2020 19:12:22 -0700 Subject: [PATCH] Move tag_breplace_argparse to alphabetical order. --- frontends/etiquette_cli.py | 76 +++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/frontends/etiquette_cli.py b/frontends/etiquette_cli.py index 25e7050..6030e57 100644 --- a/frontends/etiquette_cli.py +++ b/frontends/etiquette_cli.py @@ -30,44 +30,6 @@ def find_photodb(): #################################################################################################### -def tag_breplace_argparse(args): - photodb = find_photodb() - renames = [] - tag_names = photodb.get_all_tag_names() - all_names = tag_names.union(photodb.get_all_synonyms()) - for tag_name in tag_names: - if args.regex: - new_name = re.sub(args.replace_from, args.replace_to, tag_name) - else: - new_name = tag_name.replace(args.replace_from, args.replace_to) - new_name = photodb.normalize_tagname(new_name) - if new_name == tag_name: - continue - - if new_name in all_names: - raise etiquette.exceptions.TagExists(new_name) - - if args.set_synonym: - printline = f'{tag_name} -> {new_name}+{tag_name}' - else: - printline = f'{tag_name} -> {new_name}' - - renames.append((tag_name, new_name, printline)) - - if not args.autoyes: - for (tag_name, new_name, printline) in renames: - print(printline) - if not getpermission.getpermission('Ok?', must_pick=True): - return - - for (tag_name, new_name, printline) in renames: - print(printline) - tag = photodb.get_tag(tag_name) - tag.rename(new_name) - if args.set_synonym: - tag.add_synonym(tag_name) - photodb.commit() - def digest_directory_argparse(args): directory = pathclass.Path(args.directory) photodb = find_photodb() @@ -137,6 +99,44 @@ def search_argparse(args): for photo in photos: print(photo.real_path.absolute_path) +def tag_breplace_argparse(args): + photodb = find_photodb() + renames = [] + tag_names = photodb.get_all_tag_names() + all_names = tag_names.union(photodb.get_all_synonyms()) + for tag_name in tag_names: + if args.regex: + new_name = re.sub(args.replace_from, args.replace_to, tag_name) + else: + new_name = tag_name.replace(args.replace_from, args.replace_to) + new_name = photodb.normalize_tagname(new_name) + if new_name == tag_name: + continue + + if new_name in all_names: + raise etiquette.exceptions.TagExists(new_name) + + if args.set_synonym: + printline = f'{tag_name} -> {new_name}+{tag_name}' + else: + printline = f'{tag_name} -> {new_name}' + + renames.append((tag_name, new_name, printline)) + + if not args.autoyes: + for (tag_name, new_name, printline) in renames: + print(printline) + if not getpermission.getpermission('Ok?', must_pick=True): + return + + for (tag_name, new_name, printline) in renames: + print(printline) + tag = photodb.get_tag(tag_name) + tag.rename(new_name) + if args.set_synonym: + tag.add_synonym(tag_name) + photodb.commit() + def main(argv): parser = argparse.ArgumentParser(description=__doc__) subparsers = parser.add_subparsers()