Made tags and categories more unique.
This commit is contained in:
parent
584a5b987c
commit
809619eb83
84
image-index
84
image-index
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/python3
|
#!/bin/python3
|
||||||
import os,sys,shutil,hashlib,re,subprocess
|
import hashlib,os,random,re,shutil,subprocess,sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import sqlite3 as sql
|
import sqlite3 as sql
|
||||||
|
@ -107,6 +107,12 @@ class database():
|
||||||
return ["."]
|
return ["."]
|
||||||
return res
|
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):
|
def select_index(self,sel_list,quiet=False):
|
||||||
if quiet == "strict":
|
if quiet == "strict":
|
||||||
return sel_list
|
return sel_list
|
||||||
|
@ -178,7 +184,20 @@ class database():
|
||||||
if not secondlist:
|
if not secondlist:
|
||||||
n=0
|
n=0
|
||||||
for i in self.get_col(typ):
|
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
|
success=0
|
||||||
for j in firstlist:
|
for j in firstlist:
|
||||||
j=j.lower()
|
j=j.lower()
|
||||||
|
@ -230,8 +249,8 @@ class metatable(database):
|
||||||
self.collist=["NAME","ALIAS","DESCRIPTION"]
|
self.collist=["NAME","ALIAS","DESCRIPTION"]
|
||||||
super().__init__(filepath)
|
super().__init__(filepath)
|
||||||
|
|
||||||
def add_index(self,val,alias):
|
def add_index(self,val,alias,randhex= ""):
|
||||||
super().add_index([val.lower(),alias,''])
|
super().add_index([val.lower() + "-" + randhex,alias,''])
|
||||||
|
|
||||||
def check_index(self,typ):
|
def check_index(self,typ):
|
||||||
res=[]
|
res=[]
|
||||||
|
@ -261,7 +280,7 @@ class metatable(database):
|
||||||
|
|
||||||
def search_index(self,args,quiet=True):
|
def search_index(self,args,quiet=True):
|
||||||
selection=[]
|
selection=[]
|
||||||
selection=self.sql_compare_list("*", args, selection,True)
|
selection=self.sql_compare_list("*", [args], selection,True)
|
||||||
selection=self.select_index(selection,quiet)
|
selection=self.select_index(selection,quiet)
|
||||||
return selection
|
return selection
|
||||||
|
|
||||||
|
@ -277,6 +296,7 @@ class filestable(database):
|
||||||
print("This file already exists!")
|
print("This file already exists!")
|
||||||
return
|
return
|
||||||
n=0
|
n=0
|
||||||
|
randhex=self.get_randhex()
|
||||||
# get the name of the category from the meta table
|
# get the name of the category from the meta table
|
||||||
if not category:
|
if not category:
|
||||||
category="default"
|
category="default"
|
||||||
|
@ -284,18 +304,19 @@ class filestable(database):
|
||||||
if name != ".":
|
if name != ".":
|
||||||
category=name
|
category=name
|
||||||
else:
|
else:
|
||||||
ctb.add_index(category.lower(), category)
|
ctb.add_index(category.lower(),category,randhex)
|
||||||
category=category.lower()
|
category=ctb.get_name(category)
|
||||||
|
|
||||||
# get the name of the tags from the meta table
|
# get the name of the tags from the meta table
|
||||||
tags_list=[]
|
tags_list=[]
|
||||||
for tag in tags.split(','):
|
for tag in tags.split(','):
|
||||||
|
randhex=self.get_randhex()
|
||||||
name=ttb.get_name(tag)
|
name=ttb.get_name(tag)
|
||||||
if name != ".":
|
if name != ".":
|
||||||
tag=name
|
tag=name
|
||||||
else:
|
else:
|
||||||
ttb.add_index(tag.lower(), tag)
|
ttb.add_index(tag.lower(),tag,randhex)
|
||||||
tags_list.append(tag.lower())
|
tags_list.append(ttb.get_name(tag))
|
||||||
tags=",".join(tags_list)
|
tags=",".join(tags_list)
|
||||||
|
|
||||||
filetype=os.path.splitext(filepath)[1]
|
filetype=os.path.splitext(filepath)[1]
|
||||||
|
@ -343,18 +364,29 @@ class filestable(database):
|
||||||
category=sel_list[4]
|
category=sel_list[4]
|
||||||
filehash=sel_list[1]
|
filehash=sel_list[1]
|
||||||
filename=sel_list[0]
|
filename=sel_list[0]
|
||||||
|
randhex=self.get_randhex()
|
||||||
if typ in ["CATEGORY"]:
|
if typ in ["CATEGORY"]:
|
||||||
# get alias of category
|
# get alias of category
|
||||||
name=ctb.get_name(update)
|
name=ctb.get_name(update)
|
||||||
if name != ".":
|
if name != ".":
|
||||||
update=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)):
|
if not os.path.exists("{}/{}".format(ROOT_DIR,update)):
|
||||||
os.makedirs("{}/{}".format(ROOT_DIR,update))
|
os.makedirs("{}/{}".format(ROOT_DIR,update))
|
||||||
shutil.move("{}/{}/{}".format(ROOT_DIR,category,filename), "{}/{}/{}".format(ROOT_DIR,update,filename))
|
shutil.move("{}/{}/{}".format(ROOT_DIR,category,filename), "{}/{}/{}".format(ROOT_DIR,update,filename))
|
||||||
if typ in ["TAGS"]:
|
if typ in ["TAGS"]:
|
||||||
name=ttb.get_name(update)
|
tags_list=[]
|
||||||
|
for tag in tags.split(","):
|
||||||
|
randhex=self.get_randhex()
|
||||||
|
name=ttb.get_name(tag)
|
||||||
if name != ".":
|
if name != ".":
|
||||||
update=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)
|
super().update_index(typ, update, "HASH", filehash)
|
||||||
|
|
||||||
def get_hash(self,filepath):
|
def get_hash(self,filepath):
|
||||||
|
@ -417,7 +449,7 @@ class filestable(database):
|
||||||
elif snext == "title":
|
elif snext == "title":
|
||||||
title.append(arg)
|
title.append(arg)
|
||||||
elif snext == "tags":
|
elif snext == "tags":
|
||||||
if "," in arg:
|
'''if "," in arg:
|
||||||
for tag in arg.split(","):
|
for tag in arg.split(","):
|
||||||
name=ttb.get_name(arg)
|
name=ttb.get_name(arg)
|
||||||
if name != ".":
|
if name != ".":
|
||||||
|
@ -425,8 +457,9 @@ class filestable(database):
|
||||||
tags.append(arg)
|
tags.append(arg)
|
||||||
else:
|
else:
|
||||||
name=ttb.get_name(arg)
|
name=ttb.get_name(arg)
|
||||||
|
print("name",name)
|
||||||
if name != ".":
|
if name != ".":
|
||||||
arg=name
|
arg=name'''
|
||||||
tags.append(arg)
|
tags.append(arg)
|
||||||
else:
|
else:
|
||||||
alle.append(arg)
|
alle.append(arg)
|
||||||
|
@ -532,7 +565,7 @@ def delete(args):
|
||||||
return 1
|
return 1
|
||||||
tb.delete_index(sel)
|
tb.delete_index(sel)
|
||||||
|
|
||||||
def help():
|
def help(typ="",extended=False): # TODO: Implement extended help with examples
|
||||||
print("SYNTAX: image-index <option> [args]")
|
print("SYNTAX: image-index <option> [args]")
|
||||||
print("OPTIONS:\n\thelp:\tdisplays this text")
|
print("OPTIONS:\n\thelp:\tdisplays this text")
|
||||||
print("\tmeta:\tdisplays help for the metadata tables")
|
print("\tmeta:\tdisplays help for the metadata tables")
|
||||||
|
@ -560,9 +593,6 @@ def meta(args):
|
||||||
args.append(input("Input one type to check from the list above: "))
|
args.append(input("Input one type to check from the list above: "))
|
||||||
command=args[0]
|
command=args[0]
|
||||||
typ=args[1]
|
typ=args[1]
|
||||||
if not re.match('([cC]|[tT]).*', command):
|
|
||||||
print("The type has to be either 'Category' or 'Tags'!")
|
|
||||||
return 1
|
|
||||||
args=args[2:]
|
args=args[2:]
|
||||||
if re.match('[cC].*',command):
|
if re.match('[cC].*',command):
|
||||||
meta_check(typ,args)
|
meta_check(typ,args)
|
||||||
|
@ -585,14 +615,16 @@ def meta_check(typ,args):
|
||||||
yas=False
|
yas=False
|
||||||
print("yo")
|
print("yo")
|
||||||
for val in tres:
|
for val in tres:
|
||||||
|
randhex=tb.get_randhex()
|
||||||
|
|
||||||
if yas:
|
if yas:
|
||||||
eingabe=input("Enter Alias for {}: ".format(val.upper()))
|
eingabe=input("Enter Alias for {}: ".format(val.upper()))
|
||||||
else:
|
else:
|
||||||
eingabe=""
|
eingabe=""
|
||||||
if re.match('[cC].*',typ):
|
if re.match('[cC].*',typ):
|
||||||
ctb.add_index(val,eingabe)
|
ctb.add_index(val,eingabe,randhex)
|
||||||
elif re.match('[tT].*',typ):
|
elif re.match('[tT].*',typ):
|
||||||
ttb.add_index(val,eingabe)
|
ttb.add_index(val,eingabe,randhex)
|
||||||
|
|
||||||
def meta_update(typ,args):
|
def meta_update(typ,args):
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
|
@ -605,16 +637,18 @@ def meta_update(typ,args):
|
||||||
if re.match('[cC].*',typ):
|
if re.match('[cC].*',typ):
|
||||||
sel_list=ctb.search_index(search)
|
sel_list=ctb.search_index(search)
|
||||||
for item in sel_list:
|
for item in sel_list:
|
||||||
|
alias=ctb.get_alias(item[0])
|
||||||
ctb.update_index("ALIAS", update, "NAME", item[0])
|
ctb.update_index("ALIAS", update, "NAME", item[0])
|
||||||
elif re.match('[tT].*',typ):
|
elif re.match('[tT].*',typ):
|
||||||
sel_list=ttb.search_index(search)
|
sel_list=ttb.search_index(search)
|
||||||
for item in sel_list:
|
for item in sel_list:
|
||||||
|
alias=ttb.get_alias(item[0])
|
||||||
ttb.update_index("ALIAS", update, "NAME", item[0])
|
ttb.update_index("ALIAS", update, "NAME", item[0])
|
||||||
else:
|
else:
|
||||||
print("The first argument need to be either 'Category' or 'Tags'!")
|
print("The first argument needs to be either 'Category' or 'Tags'!")
|
||||||
return 1
|
return 1
|
||||||
if item[0] != ".":
|
if item[0] != ".":
|
||||||
print("Updated {} to {}".format(item[0],update))
|
print("Updated {} to {}".format(alias,update))
|
||||||
|
|
||||||
def meta_help():
|
def meta_help():
|
||||||
print("SYNTAX: image-index meta <option> [args]")
|
print("SYNTAX: image-index meta <option> [args]")
|
||||||
|
@ -641,7 +675,7 @@ def update(args):
|
||||||
n=0
|
n=0
|
||||||
for i in ["column","updated string"]:
|
for i in ["column","updated string"]:
|
||||||
try:
|
try:
|
||||||
print(args[n])
|
trash=args[n]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
eingabe=input("Enter {}: ".format(i))
|
eingabe=input("Enter {}: ".format(i))
|
||||||
args.append(eingabe)
|
args.append(eingabe)
|
||||||
|
@ -693,9 +727,9 @@ def show(args):
|
||||||
for res in tres:
|
for res in tres:
|
||||||
print("Title: ",res[2])
|
print("Title: ",res[2])
|
||||||
print("\tSource:\t ",res[3])
|
print("\tSource:\t ",res[3])
|
||||||
name=ctb.get_alias(res[4])
|
alias=ctb.get_alias(res[4])
|
||||||
if name != ".":
|
if alias != ".":
|
||||||
print("\tCategory:",name)
|
print("\tCategory: {} ({})".format(alias,res[4]))
|
||||||
else:
|
else:
|
||||||
print("\tCategory:",res[4])
|
print("\tCategory:",res[4])
|
||||||
print("\tFilename:",res[0])
|
print("\tFilename:",res[0])
|
||||||
|
|
Loading…
Reference in a new issue