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
|
||||
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)
|
||||
tags_list=[]
|
||||
for tag in tags.split(","):
|
||||
randhex=self.get_randhex()
|
||||
name=ttb.get_name(tag)
|
||||
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)
|
||||
|
||||
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,8 +457,9 @@ class filestable(database):
|
|||
tags.append(arg)
|
||||
else:
|
||||
name=ttb.get_name(arg)
|
||||
print("name",name)
|
||||
if name != ".":
|
||||
arg=name
|
||||
arg=name'''
|
||||
tags.append(arg)
|
||||
else:
|
||||
alle.append(arg)
|
||||
|
@ -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 <option> [args]")
|
||||
print("OPTIONS:\n\thelp:\tdisplays this text")
|
||||
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: "))
|
||||
command=args[0]
|
||||
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:]
|
||||
if re.match('[cC].*',command):
|
||||
meta_check(typ,args)
|
||||
|
@ -585,14 +615,16 @@ def meta_check(typ,args):
|
|||
yas=False
|
||||
print("yo")
|
||||
for val in tres:
|
||||
randhex=tb.get_randhex()
|
||||
|
||||
if yas:
|
||||
eingabe=input("Enter Alias for {}: ".format(val.upper()))
|
||||
else:
|
||||
eingabe=""
|
||||
if re.match('[cC].*',typ):
|
||||
ctb.add_index(val,eingabe)
|
||||
ctb.add_index(val,eingabe,randhex)
|
||||
elif re.match('[tT].*',typ):
|
||||
ttb.add_index(val,eingabe)
|
||||
ttb.add_index(val,eingabe,randhex)
|
||||
|
||||
def meta_update(typ,args):
|
||||
if len(args) == 0:
|
||||
|
@ -605,16 +637,18 @@ def meta_update(typ,args):
|
|||
if re.match('[cC].*',typ):
|
||||
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])
|
||||
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])
|
||||
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
|
||||
if item[0] != ".":
|
||||
print("Updated {} to {}".format(item[0],update))
|
||||
print("Updated {} to {}".format(alias,update))
|
||||
|
||||
def meta_help():
|
||||
print("SYNTAX: image-index meta <option> [args]")
|
||||
|
@ -641,7 +675,7 @@ def update(args):
|
|||
n=0
|
||||
for i in ["column","updated string"]:
|
||||
try:
|
||||
print(args[n])
|
||||
trash=args[n]
|
||||
except Exception as e:
|
||||
eingabe=input("Enter {}: ".format(i))
|
||||
args.append(eingabe)
|
||||
|
@ -693,9 +727,9 @@ def show(args):
|
|||
for res in tres:
|
||||
print("Title: ",res[2])
|
||||
print("\tSource:\t ",res[3])
|
||||
name=ctb.get_alias(res[4])
|
||||
if name != ".":
|
||||
print("\tCategory:",name)
|
||||
alias=ctb.get_alias(res[4])
|
||||
if alias != ".":
|
||||
print("\tCategory: {} ({})".format(alias,res[4]))
|
||||
else:
|
||||
print("\tCategory:",res[4])
|
||||
print("\tFilename:",res[0])
|
||||
|
|
Loading…
Reference in a new issue