Made possible to select multiple entries in search query
This commit is contained in:
parent
952865fc2a
commit
436db0e977
30
func.py
30
func.py
|
@ -12,6 +12,7 @@ class database():
|
||||||
else:
|
else:
|
||||||
self.connection = sql.connect(filepath)
|
self.connection = sql.connect(filepath)
|
||||||
self.crsr = self.connection.cursor()
|
self.crsr = self.connection.cursor()
|
||||||
|
|
||||||
def add_index(self,vallist):
|
def add_index(self,vallist):
|
||||||
# compile the options into a command for the SQLite database
|
# compile the options into a command for the SQLite database
|
||||||
colstring=",".join(self.collist)
|
colstring=",".join(self.collist)
|
||||||
|
@ -226,7 +227,7 @@ class filestable(database):
|
||||||
f.close()
|
f.close()
|
||||||
return str(md5_hash.hexdigest())
|
return str(md5_hash.hexdigest())
|
||||||
|
|
||||||
def search_index(self,args):
|
def search_index(self,args,quiet=False):
|
||||||
#print(args)
|
#print(args)
|
||||||
####
|
####
|
||||||
## WARNING!!!!!! UGLY CODE INCOMING!!!!!!
|
## WARNING!!!!!! UGLY CODE INCOMING!!!!!!
|
||||||
|
@ -306,20 +307,29 @@ class filestable(database):
|
||||||
print("\tCategory:",temp_list[4])
|
print("\tCategory:",temp_list[4])
|
||||||
print("\tTags:\t ",temp_list[5])
|
print("\tTags:\t ",temp_list[5])
|
||||||
n+=1
|
n+=1
|
||||||
eingabe=input("Enter number 0-{}: ".format(n-1))
|
eingabe=input("Enter number(s) (0-{}; '*' for all entries): ".format(n-1))
|
||||||
if int(eingabe) < n:
|
if not eingabe:
|
||||||
for i in selection[int(eingabe)]:
|
return ["."]
|
||||||
res.append(i)
|
num_list=[]
|
||||||
print("\n\nFinal match:")
|
if re.match('[*]',eingabe):
|
||||||
|
for i in range(0,n):
|
||||||
|
num_list.append(i)
|
||||||
else:
|
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:
|
else:
|
||||||
if selection[0] == ".":
|
if selection[0] == ".":
|
||||||
print("No matching entry found!")
|
print("No matching entry found!")
|
||||||
return ["."]
|
return ["."]
|
||||||
tempres=selection[0]
|
res=selection
|
||||||
for i in tempres:
|
|
||||||
res.append(i)
|
|
||||||
print("\nMatch found!")
|
print("\nMatch found!")
|
||||||
return res
|
return res
|
||||||
return 1
|
return 1
|
50
main.py
50
main.py
|
@ -40,21 +40,23 @@ def check(args):
|
||||||
repair(path_list)
|
repair(path_list)
|
||||||
|
|
||||||
def delete(args):
|
def delete(args):
|
||||||
selection=search(args)
|
selection=search(args,True)
|
||||||
if selection[0] != ".":
|
for sel in selection:
|
||||||
|
if sel[0] != ".":
|
||||||
try:
|
try:
|
||||||
category=selection[4]
|
category=sel[4]
|
||||||
filename=selection[0]
|
filename=sel[0]
|
||||||
os.remove("{}/{}".format(category,filename))
|
os.remove("{}/{}/{}".format(ROOT_DIR,category,filename))
|
||||||
except Exception:
|
except Exception as e:
|
||||||
print("Couldn't delete file!")
|
print(e)
|
||||||
|
print("Couldn't delete a file!")
|
||||||
return 1
|
return 1
|
||||||
tb.delete_index(selection)
|
tb.delete_index(sel)
|
||||||
|
|
||||||
def help():
|
def help():
|
||||||
print("SYNTAX:\n\t'image-index <option> [args]' executes the command")
|
print("SYNTAX:\n\t'image-index <option> [args]' executes the command")
|
||||||
print("\nOPTIONS:\n\thelp:\tdisplays this prompt")
|
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("\tadd:\tadds a new entry;\n\t\tInstant: image-index add <filepath> <category> <title> <source> <tags> <content>")
|
||||||
print("\t\tPrompt: image-index add")
|
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")
|
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("\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("\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("\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):
|
def meta(args):
|
||||||
command=args[0]
|
command=args[0]
|
||||||
|
@ -85,8 +89,9 @@ def update(args):
|
||||||
typ=input("Enter the column: ")
|
typ=input("Enter the column: ")
|
||||||
update=input("Enter the update: ")
|
update=input("Enter the update: ")
|
||||||
selection=search([],True)
|
selection=search([],True)
|
||||||
if selection[0] != ".":
|
for sel in selection:
|
||||||
tb.update_index(typ,update,selection)
|
if sel[0] != ".":
|
||||||
|
tb.update_index(typ,update,sel)
|
||||||
|
|
||||||
def repair(err_list):
|
def repair(err_list):
|
||||||
sel_list=[]
|
sel_list=[]
|
||||||
|
@ -113,21 +118,22 @@ def search(args,quiet=False):
|
||||||
print("\t -t: Title")
|
print("\t -t: Title")
|
||||||
args=input("Query: ")
|
args=input("Query: ")
|
||||||
if len(args) > 0:
|
if len(args) > 0:
|
||||||
res=tb.search_index(args.split(' '))
|
res=tb.search_index(args.split(' '),quiet)
|
||||||
else:
|
else:
|
||||||
print("\nQuery empty!")
|
print("\nQuery empty!")
|
||||||
return ["."]
|
return ["."]
|
||||||
else:
|
else:
|
||||||
res=tb.search_index(args)
|
tres=tb.search_index(args,quiet)
|
||||||
if not quiet and res[0] != ".":
|
if not quiet and tres[0] != ".":
|
||||||
print("Title:\t ",res[2])
|
for res in tres:
|
||||||
print("Source:\t ",res[3])
|
print("Title: ",res[2])
|
||||||
print("Category:",res[4])
|
print("\tSource:\t ",res[3])
|
||||||
print("Filename:",res[0])
|
print("\tCategory:",res[4])
|
||||||
print("Hash:\t ",res[1])
|
print("\tFilename:",res[0])
|
||||||
print("Tags:\t ",res[5])
|
print("\tHash:\t ",res[1])
|
||||||
print("Content: ",res[6])
|
print("\tTags:\t ",res[5])
|
||||||
return res
|
print("\tContent: ",res[6])
|
||||||
|
return tres
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) <= 1 or re.match('[hH].*',sys.argv[1]):
|
if len(sys.argv) <= 1 or re.match('[hH].*',sys.argv[1]):
|
||||||
|
|
Loading…
Reference in a new issue