From 73904fac53fbeb615e535507d0ee3bc710210c22 Mon Sep 17 00:00:00 2001 From: Michael Rodin Date: Tue, 29 Nov 2022 10:17:44 +0100 Subject: [PATCH] added check for duplicates in tables TAGS and CATEGORY --- image-index | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/image-index b/image-index index e193f20..fac9754 100755 --- a/image-index +++ b/image-index @@ -179,6 +179,9 @@ class database(): n=0 for i in self.get_col(typ): aliases=[] + if i == "." and self.name == "FILES": + print("NO ENTRIES IN THE INDEX!") + return "." # get aliases for the checks, but only for unspecific search! if self.name == "FILES": if typ == "*": @@ -278,6 +281,15 @@ class metatable(database): selection=self.select_index(selection,quiet) return selection + def update_index(self, typ, update, where, val): + selection=self.search_index(update,"strict") + if selection[0] != "." and len(selection) >= 1: + print("One entry is already called {}!".format(update)) + return False + else: + super().update_index(typ, update, where, val) + return True + class filestable(database): def __init__(self,filepath = CONFIG_DIR + "/index.db"): self.name="FILES" @@ -470,7 +482,7 @@ class filestable(database): return self.select_index(selection,quiet) -def get_randhex(self,count=5): +def get_randhex(count=5): randhex="" for i in range(count): randhex+=random.choice("0123456789abcdef") @@ -668,16 +680,16 @@ def meta_update(typ,args): sel_list=ctb.search_index(search) for item in sel_list: alias=ctb.get_alias(item[0]) - ctb.update_index("ALIAS", update, "NAME", item[0]) + success=ctb.update_index("ALIAS", update, "NAME", item[0]) elif re.match('[tT].*',typ): sel_list=ttb.search_index(search) for item in sel_list: alias=ttb.get_alias(item[0]) - ttb.update_index("ALIAS", update, "NAME", item[0]) + success=ttb.update_index("ALIAS", update, "NAME", item[0]) else: print("The first argument needs to be either 'Category' or 'Tags'!") return 1 - if item[0] != ".": + if item[0] != "." and success: print("Updated {} to {}".format(alias,update)) def meta_help():