From 527f006e6b11159c98dc59308ea90e21f1640bd6 Mon Sep 17 00:00:00 2001 From: Michael Rodin Date: Fri, 2 Dec 2022 11:58:11 +0100 Subject: [PATCH] Simpler and safer get_randhex() integration --- image-index | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/image-index b/image-index index 302d906..a1ea25f 100755 --- a/image-index +++ b/image-index @@ -43,14 +43,12 @@ class database(): self.crsr.execute(sqlcommand) sqlcommand = """CREATE TABLE CATEGORY( NAME TEXT PRIMARY KEY NOT NULL, - ALIAS TEXT, - DESCRIPTION TEXT + ALIAS TEXT ); """ self.crsr.execute(sqlcommand) sqlcommand = """CREATE TABLE TAGS( NAME TEXT PRIMARY KEY NOT NULL, - ALIAS TEXT, - DESCRIPTION TEXT + ALIAS TEXT ); """ self.crsr.execute(sqlcommand) @@ -243,11 +241,13 @@ class database(): class metatable(database): def __init__(self,typ,filepath = CONFIG_DIR + "/index.db"): self.name=typ.upper() - self.collist=["NAME","ALIAS","DESCRIPTION"] + self.collist=["NAME","ALIAS"] super().__init__(filepath) - def add_index(self,val,alias,randhex=""): - super().add_index([val.lower() + "-" + randhex,alias,'']) + def add_index(self,val,alias): + randhex=get_randhex() + val=re.sub('[ ?!/\\:!*"<>|]', '', val) + super().add_index([val[:8] + "-" + randhex,alias]) def check_index(self,typ): res=[] @@ -306,7 +306,6 @@ class filestable(database): print("This file already exists!") return False n=0 - randhex=get_randhex() # get the name of the category from the meta table if not category: category="default" @@ -314,18 +313,17 @@ class filestable(database): if name != ".": category=name else: - ctb.add_index(category.lower(),category,randhex) + ctb.add_index(category.lower(),category) category=ctb.get_name(category) # get the name of the tags from the meta table tags_list=[] for tag in tags.split(','): - randhex=get_randhex() name=ttb.get_name(tag) if name != ".": tag=name else: - ttb.add_index(tag.lower(),tag,randhex) + ttb.add_index(tag.lower(),tag) tags_list.append(ttb.get_name(tag)) tags=",".join(tags_list) @@ -376,14 +374,13 @@ class filestable(database): category=sel_list[4] filehash=sel_list[1] filename=sel_list[0] - randhex=get_randhex() if typ in ["CATEGORY"]: # get alias of category name=ctb.get_name(update) if name != ".": update=name else: - ctb.add_index(update.lower(),update,randhex) + ctb.add_index(update.lower(),update) update=ctb.get_name(update) if not os.path.exists("{}/{}".format(ROOT_DIR,update)): os.makedirs("{}/{}".format(ROOT_DIR,update)) @@ -394,10 +391,9 @@ class filestable(database): 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) + ttb.add_index(tag.lower(), tag) name=ttb.get_name(tag) tags_list.append(name) elif update[0][0] == "-": @@ -406,7 +402,6 @@ class filestable(database): 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: @@ -415,12 +410,11 @@ class filestable(database): 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) + ttb.add_index(tag.lower(), tag) tags_list.append(ttb.get_name(tag)) update=",".join(tags_list) super().update_index(typ, update, "HASH", filehash) @@ -542,7 +536,7 @@ def add(args): return 1 else: if not Path(args[n]).is_file(): - print(" The file '{}' doesn't exist or is not a file!".format(eingabe)) + print(" The file '{}' doesn't exist or is not a file!".format(args[n])) return 1 n+=1 success=tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5]) @@ -693,16 +687,14 @@ def meta_check(typ,args): yas=False print("yo") for val in tres: - randhex=get_randhex() - if yas: eingabe=input("Enter Alias for {}: ".format(val.upper())) else: eingabe="" if re.match('[cC].*',typ): - ctb.add_index(val,eingabe,randhex) + ctb.add_index(val,eingabe) elif re.match('[tT].*',typ): - ttb.add_index(val,eingabe,randhex) + ttb.add_index(val,eingabe) else: print("Everything is good!")