From 3f62f678bdf2e3fb9cd354863e70e907dd6a0b1b Mon Sep 17 00:00:00 2001 From: Michael Rodin Date: Thu, 1 Dec 2022 18:20:05 +0100 Subject: [PATCH] Added text to indicate successful execution --- image-index | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/image-index b/image-index index 8ab860d..302d906 100755 --- a/image-index +++ b/image-index @@ -254,13 +254,15 @@ class metatable(database): for i in tb.get_col(typ): success=0 for j in self.get_col("NAME"): - if j[0] in i[0].lower(): + if j[0] in i[0]: success=1 if not i[0] in res and success == 0: res.append(i[0]) return res def get_alias(self,arg): + if not arg: + return "." selection=self.search_index(arg,"strict") item=selection[0] if item[0] != ".": @@ -270,6 +272,8 @@ class metatable(database): return alias def get_name(self,arg): + if not arg: + return "." selection=self.search_index(arg,"strict") item=selection[0] name=item[0] @@ -300,7 +304,7 @@ class filestable(database): filehash=self.get_hash(filepath) # make hash of file before copy if filehash in str(self.get_col("HASH")): print("This file already exists!") - return + return False n=0 randhex=get_randhex() # get the name of the category from the meta table @@ -335,9 +339,10 @@ class filestable(database): except Exception as e: print(e) print("COULDN'T COPY FILE TO DESTINATION!") - return + return False vallist=[filename,filehash,title,source,category,tags,content] super().add_index(vallist) + return True def check_index(self): hash_list=[] @@ -361,6 +366,7 @@ class filestable(database): def delete_index(self,sel_list): self.get_item("HASH",sel_list[1]) super().delete_index("HASH",sel_list[1]) + return True def update_index(self,typ,update,sel_list): typ=typ.upper() @@ -539,7 +545,9 @@ def add(args): print(" The file '{}' doesn't exist or is not a file!".format(eingabe)) return 1 n+=1 - tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5]) + success=tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5]) + if success: + print("Added '{}'!".format(args[2])) def check(args): success=0 @@ -600,6 +608,7 @@ def delete(args): print("Couldn't delete a file!") return 1 tb.delete_index(sel) + print("Deleted '{}'!".format(sel[2])) def help(args): syntax=False @@ -675,7 +684,7 @@ def meta_check(typ,args): tres=ttb.check_index("TAGS") else: print("No valid type specified!") - return + return False if tres: yas=True print("Missing items:",','.join(tres)) @@ -694,6 +703,8 @@ def meta_check(typ,args): ctb.add_index(val,eingabe,randhex) elif re.match('[tT].*',typ): ttb.add_index(val,eingabe,randhex) + else: + print("Everything is good!") def meta_update(typ,args): if len(args) == 0: @@ -756,7 +767,24 @@ def update(args): update=args[1] for sel in selection: if sel[0] != ".": + n=0 + for i in tb.collist: + if i.lower() == typ.lower(): + old=sel[n] + else: + n+=1 tb.update_index(typ,update,sel) + if re.match('[tT][aA].*', typ) and re.match('[-+]', update[0]): + tags_list=[] + for tag in update[1:].split(","): + tags_list.append(tag) + tagstr=", ".join(tags_list) + if update[0] == "-": + print("Removed {}!".format(tagstr)) + elif update[0] == "+": + print("Added {}!".format(tagstr)) + else: + print("Updated {} to {}!".format(old,update)) def repair(err_list): sel_list=[] @@ -801,11 +829,9 @@ def show(args): print("\tHash:\t ",res[1]) tags_list=[] for tag in res[5].split(","): - name=ttb.get_alias(tag) - if name != ".": - tags_list.append(name) - else: - tags_list.append(tag) + alias=ttb.get_alias(tag) + if alias != ".": + tags_list.append(alias) print("\tTags:\t ",",".join(tags_list)) print("\tContent: ",res[6])