From bc2e49a3ea1857b9644edfbb965e36808aa0723b Mon Sep 17 00:00:00 2001 From: Michael Rodin Date: Wed, 18 Jan 2023 09:17:23 +0100 Subject: [PATCH] added stats function --- README.md | 1 + image-index | 47 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 32af77e..f7017a4 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ This project was written and tested on an Arch Linux-based distribution and pyth * open - open one or more files from the index in the default application (only Linux and Windows) * replace - replaces a file in the index with another file while keeping the entry * show - search through the index and show the matches +* stats - shows statistics about the index like number of entries, tags and categories * update - change a value of an entry in the index or move a file to another category ## Dependencies diff --git a/image-index b/image-index index 37a8486..7468a4b 100755 --- a/image-index +++ b/image-index @@ -101,14 +101,8 @@ class database(): n=0 res=[] for i in tres: - m=0 - for j in tres: - if i in j and n!=m: - continue - else: - res.append(i) - m+=1 - n+=1 + if not i in res: + res.append(i) # if the table is empty, return "". if not res: return [""] @@ -843,6 +837,9 @@ def help(args): print("replaces a file of an entry based on a search query;\n\tInstant: image-index replace ") print("\tPrompt: image-index replace") print("EXAMPLE:\nimage-index replace ~/Pictures/example_new.jpg -f .jpg\n") + elif re.match('[sS][tT].*',arg) or re.match('[sS].*[aA].*',arg): + print("stats:\tshows some statistics about the index;\n\tSyntax: image-index stats [-v]") + print("EXAMPLE:\nimage-index stats -v (also shows all tags and categories)\n") elif re.match('[sS].*',arg): print("show:\tsearches through the index and shows the matches;\n\tInstant: image-index show ") print("\tPrompt: image-index show") @@ -869,6 +866,7 @@ def help(args): print("\topen:\topens a file based on a search query in the standard app;\n\t\tSyntax: image-index open ") print("\treplace:replaces a file of an entry based on a search query;\n\t\tSyntax: image-index replace ") print("\tshow:\tsearches through the index and shows the matches;\n\t\tSyntax: image-index show ") + print("\tstats:\tshows some stats about the index;\n\t\tSyntax: image-index stats [-v]") print("\tupdate:\tchanges specific column based on a search query;\n\t\tSyntax: image-index update ") def imports(args): @@ -1086,6 +1084,37 @@ def show(args): print("\tTags:\t ",",".join(tags_list)) print("\tContent: ",res[6]) +def stats(args): + verbose=False + for arg in args: + if re.match('[-]+[vV].*', arg): + verbose=True + entrynum=len(tb.get_col("HASH")) + encnum=len(etb.get_col("NAME")) + print(f"Entry count: {entrynum} ({encnum} encrypted)") + tags=ttb.get_col("NAME") + tagnum=len(tags) + print(f"Tags count: {tagnum}") + if verbose: + for item in tags: + name=item[0] + taguse=tb.get_item("TAGS", name) + if taguse[0] == "": + taguse=0 + else: + taguse=len(taguse) + print(f"\t{ttb.get_alias(name)} ({name}): Used by {taguse} entr%s"% ("y" if taguse == 1 else "ies")) + cats=ctb.get_col("NAME") + catnum=len(cats) + print(f"Categories count: {catnum}") + if verbose: + for item in cats: + name=item[0] + catuse=len(tb.get_item("CATEGORY", name)) + print(f"\t{ctb.get_alias(name)} ({name}): Used by {catuse} entr%s"% "y" if taguse == 1 else "ies") + + return True + def main(): if len(sys.argv) <= 1 or re.match('[hH].*',sys.argv[1]): help(sys.argv[2:]) @@ -1116,6 +1145,8 @@ def main(): opens(args) elif re.match('[rR].*',command): replace(args) + elif re.match('[sS][tT].*',command) or re.match('[sS].*[aA].*',command): + stats(args) elif re.match('[sS].*',command): show(args) elif re.match('[uU].*',command):