diff --git a/image-index b/image-index index b3f497c..aad1ecf 100755 --- a/image-index +++ b/image-index @@ -1,5 +1,5 @@ #!/bin/python3 -import os,sys,shutil,hashlib,re,subprocess +import hashlib,os,random,re,shutil,subprocess,sys from pathlib import Path from uuid import uuid4 import sqlite3 as sql @@ -107,6 +107,12 @@ class database(): return ["."] return res + def get_randhex(self,count=5): + randhex="" + for i in range(count): + randhex+=random.choice("0123456789abcdef") + return randhex + def select_index(self,sel_list,quiet=False): if quiet == "strict": return sel_list @@ -178,7 +184,20 @@ class database(): if not secondlist: n=0 for i in self.get_col(typ): - istr=" ".join(i).lower() + aliases=[] + # get aliases for the checks, but only for unspecific search! + if self.name == "FILES": + if typ == "*": + for tag in i[5].split(","): + aliases.append(ttb.get_alias(tag)) + aliases.append(ctb.get_alias(i[4])) + elif typ == "TAGS": + for tag in i[0].split(","): + aliases.append(ttb.get_alias(tag)) + elif typ == "CATEGORY": + aliases.append(ctb.get_alias(i[0])) + + istr=" ".join(i).lower() + " " + " ".join(aliases).lower() success=0 for j in firstlist: j=j.lower() @@ -230,8 +249,8 @@ class metatable(database): self.collist=["NAME","ALIAS","DESCRIPTION"] super().__init__(filepath) - def add_index(self,val,alias): - super().add_index([val.lower(),alias,'']) + def add_index(self,val,alias,randhex= ""): + super().add_index([val.lower() + "-" + randhex,alias,'']) def check_index(self,typ): res=[] @@ -261,7 +280,7 @@ class metatable(database): def search_index(self,args,quiet=True): selection=[] - selection=self.sql_compare_list("*", args, selection,True) + selection=self.sql_compare_list("*", [args], selection,True) selection=self.select_index(selection,quiet) return selection @@ -277,6 +296,7 @@ class filestable(database): print("This file already exists!") return n=0 + randhex=self.get_randhex() # get the name of the category from the meta table if not category: category="default" @@ -284,18 +304,19 @@ class filestable(database): if name != ".": category=name else: - ctb.add_index(category.lower(), category) - category=category.lower() + ctb.add_index(category.lower(),category,randhex) + category=ctb.get_name(category) # get the name of the tags from the meta table tags_list=[] for tag in tags.split(','): + randhex=self.get_randhex() name=ttb.get_name(tag) if name != ".": tag=name else: - ttb.add_index(tag.lower(), tag) - tags_list.append(tag.lower()) + ttb.add_index(tag.lower(),tag,randhex) + tags_list.append(ttb.get_name(tag)) tags=",".join(tags_list) filetype=os.path.splitext(filepath)[1] @@ -343,18 +364,29 @@ class filestable(database): category=sel_list[4] filehash=sel_list[1] filename=sel_list[0] + randhex=self.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) + update=ctb.get_name(update) if not os.path.exists("{}/{}".format(ROOT_DIR,update)): os.makedirs("{}/{}".format(ROOT_DIR,update)) shutil.move("{}/{}/{}".format(ROOT_DIR,category,filename), "{}/{}/{}".format(ROOT_DIR,update,filename)) if typ in ["TAGS"]: - name=ttb.get_name(update) - if name != ".": - update=name + tags_list=[] + for tag in tags.split(","): + randhex=self.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) def get_hash(self,filepath): @@ -417,7 +449,7 @@ class filestable(database): elif snext == "title": title.append(arg) elif snext == "tags": - if "," in arg: + '''if "," in arg: for tag in arg.split(","): name=ttb.get_name(arg) if name != ".": @@ -425,9 +457,10 @@ class filestable(database): tags.append(arg) else: name=ttb.get_name(arg) + print("name",name) if name != ".": - arg=name - tags.append(arg) + arg=name''' + tags.append(arg) else: alle.append(arg) # search for the right items @@ -532,7 +565,7 @@ def delete(args): return 1 tb.delete_index(sel) -def help(): +def help(typ="",extended=False): # TODO: Implement extended help with examples print("SYNTAX: image-index