Made possible to select multiple entries in search query

This commit is contained in:
Michael Rodin 2022-11-16 20:18:38 +01:00
parent 952865fc2a
commit 436db0e977
2 changed files with 50 additions and 34 deletions

30
func.py
View file

@ -12,6 +12,7 @@ class database():
else:
self.connection = sql.connect(filepath)
self.crsr = self.connection.cursor()
def add_index(self,vallist):
# compile the options into a command for the SQLite database
colstring=",".join(self.collist)
@ -226,7 +227,7 @@ class filestable(database):
f.close()
return str(md5_hash.hexdigest())
def search_index(self,args):
def search_index(self,args,quiet=False):
#print(args)
####
## WARNING!!!!!! UGLY CODE INCOMING!!!!!!
@ -306,20 +307,29 @@ class filestable(database):
print("\tCategory:",temp_list[4])
print("\tTags:\t ",temp_list[5])
n+=1
eingabe=input("Enter number 0-{}: ".format(n-1))
if int(eingabe) < n:
for i in selection[int(eingabe)]:
res.append(i)
print("\n\nFinal match:")
eingabe=input("Enter number(s) (0-{}; '*' for all entries): ".format(n-1))
if not eingabe:
return ["."]
num_list=[]
if re.match('[*]',eingabe):
for i in range(0,n):
num_list.append(i)
else:
print(type(eingabe))
num_list=eingabe.split(' ')
nminus=0
for i in num_list:
if int(i) >= n:
print("The number {} is too big!".format(i))
nminus+=1
continue
res.append(selection[int(i)])
if not quiet:
print("\n\nFinal match{}:".format("es" if len(num_list)-nminus > 1 else ""))
else:
if selection[0] == ".":
print("No matching entry found!")
return ["."]
tempres=selection[0]
for i in tempres:
res.append(i)
res=selection
print("\nMatch found!")
return res
return 1

50
main.py
View file

@ -40,21 +40,23 @@ def check(args):
repair(path_list)
def delete(args):
selection=search(args)
if selection[0] != ".":
selection=search(args,True)
for sel in selection:
if sel[0] != ".":
try:
category=selection[4]
filename=selection[0]
os.remove("{}/{}".format(category,filename))
except Exception:
print("Couldn't delete file!")
category=sel[4]
filename=sel[0]
os.remove("{}/{}/{}".format(ROOT_DIR,category,filename))
except Exception as e:
print(e)
print("Couldn't delete a file!")
return 1
tb.delete_index(selection)
tb.delete_index(sel)
def help():
print("SYNTAX:\n\t'image-index <option> [args]' executes the command")
print("\nOPTIONS:\n\thelp:\tdisplays this prompt")
print("\tmeta:\tdisplays help for the metadata thing")
#print("\tmeta:\tdisplays help for the metadata thing")
print("\tadd:\tadds a new entry;\n\t\tInstant: image-index add <filepath> <category> <title> <source> <tags> <content>")
print("\t\tPrompt: image-index add")
print("\tcheck:\tchecks the existence and correctness of all files in the index;\n\t\tSyntax: image-index check")
@ -62,6 +64,8 @@ def help():
print("\t\tPrompt: image-index delete")
print("\tsearch:\tsearches through the index (use prompt for list of filters);\n\t\tInstant: image-index search <words/filters>")
print("\t\tPrompt: image-index search")
print("\tupdate:\tchanges specific column based on a search query;\n\t\tInstant: image-index update <column> <updated_value> <words/filters>")
print("\t\tPrompt: image-index update")
def meta(args):
command=args[0]
@ -85,8 +89,9 @@ def update(args):
typ=input("Enter the column: ")
update=input("Enter the update: ")
selection=search([],True)
if selection[0] != ".":
tb.update_index(typ,update,selection)
for sel in selection:
if sel[0] != ".":
tb.update_index(typ,update,sel)
def repair(err_list):
sel_list=[]
@ -113,21 +118,22 @@ def search(args,quiet=False):
print("\t -t: Title")
args=input("Query: ")
if len(args) > 0:
res=tb.search_index(args.split(' '))
res=tb.search_index(args.split(' '),quiet)
else:
print("\nQuery empty!")
return ["."]
else:
res=tb.search_index(args)
if not quiet and res[0] != ".":
print("Title:\t ",res[2])
print("Source:\t ",res[3])
print("Category:",res[4])
print("Filename:",res[0])
print("Hash:\t ",res[1])
print("Tags:\t ",res[5])
print("Content: ",res[6])
return res
tres=tb.search_index(args,quiet)
if not quiet and tres[0] != ".":
for res in tres:
print("Title: ",res[2])
print("\tSource:\t ",res[3])
print("\tCategory:",res[4])
print("\tFilename:",res[0])
print("\tHash:\t ",res[1])
print("\tTags:\t ",res[5])
print("\tContent: ",res[6])
return tres
def main():
if len(sys.argv) <= 1 or re.match('[hH].*',sys.argv[1]):