From 47f9fdb0bbb39b2cd41dc17d2fa30c17688b7dd5 Mon Sep 17 00:00:00 2001 From: Michael Rodin Date: Thu, 17 Nov 2022 10:40:38 +0100 Subject: [PATCH] made search case-insensitive; renamed command search to show --- README.md | 16 +++++++-------- func.py | 12 +++++++---- main.py | 60 +++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index b4f1874..2733200 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,14 @@ # image-index This project is a collection of scripts which can index and sort files on your pc. You can give every file a title, category, source, tags and content for easier finding later on. +## Functions +* add - Add a file and entry to the index +* check - check if all files saved in the index exist and aren't faulty +* delete - delete a file and remove the entry +* open - open one or more files from the index in the default application (only Linux and Windows) +* show - search through the index and show the matches +* update - change a value of an entry in the index or move a file to another category + ## Installation ```sh git clone https://gitlab.com/rodin_schule/image-index-py.git @@ -8,14 +16,6 @@ cd ./image-index-py cp config-def.py config.py ``` -## Functions -* add - Add a file and entry to the index -* check - check if all files saved in the index exist and aren't faulty -* delete - delete a file and remove the entry -* open - open one or more files from the index in the default application (only Linux and Windows) -* search - search through the index -* update - change a value of an entry in the index or move a file to another category - ## Configuration The file `config.py` holds some very important variables which you need to look at before using the index: * ROOT_DIR: The absolute path of where you want to save your files (the directories for the categories will be created there) diff --git a/func.py b/func.py index 0bfa27f..04a7e82 100644 --- a/func.py +++ b/func.py @@ -37,7 +37,9 @@ class database(): ); """ self.crsr.execute(sqlcommand) '''sqlcommand = """CREATE TABLE META( - TAGS TEXT PRIMARY KEY NOT NULL + CATEGORY TEXT PRIMARY KEY NOT NULL, + ALIAS TEXT, + DESC TEXT ); """ self.crsr.execute(sqlcommand)''' @@ -100,9 +102,10 @@ class database(): class metatable(database): def __init__(self,filepath = CONFIG_DIR + "/index.db"): self.name="META" - self.collist=["TAGS"] + self.collist=["CATEGORY","ALIAS","DESCRIPTION"] super().__init__(filepath) - def add_index(self): + + def add_index(self,alias,dirname,desc=""): super().add_index(vallist) class filestable(database): @@ -181,7 +184,7 @@ class filestable(database): success=0 for j in firstlist: #print(j) - if j in str(i): + if j in str(i).lower(): #print("Yay") if not success == -1: success=1 @@ -242,6 +245,7 @@ class filestable(database): title=[] tags=[] for arg in args: + arg=arg.lower() if re.match('^[-]\w{1}$', arg): if arg == "-h": snext="hash" diff --git a/main.py b/main.py index 4f3e4d8..a3dfa7f 100755 --- a/main.py +++ b/main.py @@ -16,24 +16,46 @@ def add(): args.append(eingabe) tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5]) -def check(args): # TODO: Option to see all faulty/missing files. +def check(args): success=0 - if not args: - hash_list,path_list=tb.check_index() + hash_list,temp_list=tb.check_index() + path_list=[] + hashcheck=pathcheck=True + verbose=False + for arg in args: + if arg == "-v": + verbose=True + elif arg == "-f": + hashcheck=False + elif arg == "-h": + pathcheck=False if hash_list: print("{} file{} faulty!".format(len(hash_list),"s are" if len(hash_list) > 1 else " is")) success=-1 + if verbose: + for tup in hash_list: + print("Title: ",tup[2]) + print("\tCategory:",tup[4]) + print("\tFilename:",tup[0]) + for i in temp_list: + if not i in path_list: + path_list.append(i) if path_list: - print("{} file{} missing!".format(int(len(path_list)/2),"s are" if int(len(path_list)/2) > 1 else " is")) + print("{} file{} missing!".format(len(path_list),"s are" if len(path_list) > 1 else " is")) success=-1 + if verbose: + for tup in path_list: + print("Title: ",tup[2]) + print("\tCategory:",tup[4]) + print("\tFilename:",tup[0]) if success >= 0: print("Everything is good!") - if hash_list: + if hash_list and hashcheck: eingabe=input("Do you want to remove the faulty files? [y/N]: ") if re.match('[yY]',eingabe): print("Removing faulty files...") repair(hash_list) - if path_list: + if path_list and pathcheck: eingabe=input("Do you want to remove the orphaned entries? [Y/n]: ") if not re.match('[nN]',eingabe): print("Removing orphaned entries...") @@ -59,13 +81,16 @@ def help(): #print("\tmeta:\tdisplays help for the metadata thing") print("\tadd:\tadds a new entry;\n\t\tInstant: image-index add <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") + print("\tcheck:\tchecks the existence and correctness of all files in the index;\n\t\tSyntax: image-index check [options]") + print("\t\tOptions: -v: show every faulty/orphaned entry") + print("\t\t\t -f: check only if files exist (disables the other check)") + print("\t\t\t -h: check only if hashes are correct (disables the other check)") print("\tdelete:\tdeletes a file and entry based on a search query;\n\t\tInstant: image-index delete <words/filters>") print("\t\tPrompt: image-index delete") print("\topen:\topens a file based on a search query in the standard app;\n\t\tInstant: image-index open <words/filters>") print("\t\tPrompt: image-index open") - 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("\tshow:\tsearches through the index and shows the matches (use prompt for list of filters);\n\t\tInstant: image-index show <words/filters>") + print("\t\tPrompt: image-index show") 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") @@ -141,7 +166,11 @@ def search(args,quiet=False): return ["."] else: tres=tb.search_index(args,quiet) - if not quiet and tres[0] != ".": + return tres + +def show(args): + tres=search(args,False) + if not tres[0] == ".": for res in tres: print("Title: ",res[2]) print("\tSource:\t ",res[3]) @@ -150,7 +179,6 @@ def search(args,quiet=False): 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]): @@ -177,19 +205,17 @@ def main(): elif re.match('[oO].*',command): open(args) elif re.match('[sS].*',command): - search(args) + show(args) elif re.match('[uU].*',command): update(args) else: print("No such option!") - tb.connection.close() - mtb.connection.close() - #for i in sys.argv: - # print("Arg:" + i) + tb.connection.close() + mtb.connection.close() #input("Press return...") if __name__ == "__main__": filepath=CONFIG_DIR + '/index.db' tb = filestable() mtb = metatable() - main() + main() \ No newline at end of file