From c8d306dc6131b62025514dd2a0811157fc1373ee Mon Sep 17 00:00:00 2001 From: Michael Rodin Date: Tue, 29 Nov 2022 10:54:21 +0100 Subject: [PATCH] added function to add and remove specific tags from an entry --- image-index | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/image-index b/image-index index fac9754..49db85d 100755 --- a/image-index +++ b/image-index @@ -246,7 +246,7 @@ class metatable(database): self.collist=["NAME","ALIAS","DESCRIPTION"] super().__init__(filepath) - def add_index(self,val,alias,randhex= ""): + def add_index(self,val,alias,randhex=""): super().add_index([val.lower() + "-" + randhex,alias,'']) def check_index(self,typ): @@ -384,14 +384,38 @@ class filestable(database): shutil.move("{}/{}/{}".format(ROOT_DIR,category,filename), "{}/{}/{}".format(ROOT_DIR,update,filename)) if typ in ["TAGS"]: tags_list=[] - for tag in tags.split(","): - randhex=get_randhex() - name=ttb.get_name(tag) - if name != ".": + if update[0][0] == "+": + for tag in sel_list[5].split(","): + tags_list.append(tag) + for tag in update[1:].split(","): + randhex=get_randhex() + name=ttb.get_name(tag) + if name == ".": + ttb.add_index(tag.lower(), tag, randhex) + name=ttb.get_name(tag) tags_list.append(name) - else: - ttb.add_index(tag.lower(), tag, randhex) - tags_list.append(ttb.get_name(tag)) + elif update[0][0] == "-": + for tag in sel_list[5].split(","): + success=0 + for i in update[1:].split(","): + name=ttb.get_name(i) + if name == ".": + randhex=get_randhex() + ttb.add_index(tag.lower(), tag) + name=ttb.get_name(tag) + if name == tag: + success = -1 + if success >= 0: + tags_list.append(tag) + else: + for tag in update.split(","): + randhex=get_randhex() + name=ttb.get_name(tag) + if name != ".": + tags_list.append(name) + else: + ttb.add_index(tag.lower(), tag, randhex) + tags_list.append(ttb.get_name(tag)) update=",".join(tags_list) super().update_index(typ, update, "HASH", filehash) @@ -614,8 +638,11 @@ def help(args): print("\tPrompt: image-index update") print('EXAMPLES:\nimage-index update category "New Category" -t example') print('image-index update Tags "Tag,Example,Test" -s https:// -a example') - print('image-index update title "Some new title" -g "some thing" -a an example\n') + print('image-index update title "Some new title" -g "some thing" -a an example') + print('SPECIAL EXAMPLES TAGS:\nimage-index update tags +New_tag,hello -g "some thing" (adds the tags "New_tag" and "hello")') + print('image-index update tags -Tag -t Example (removes the tag "Tag")\n') if not args: + print("SYNTAX: image-index