From 35a58d49521e3374e92c3e830464071885485d69 Mon Sep 17 00:00:00 2001 From: Michael Rodin Date: Mon, 5 Dec 2022 19:52:07 +0100 Subject: [PATCH] added import function --- README.md | 1 + image-index | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 04d8f58..895aaba 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ All information is stored inside of an SQLite-database. Two separate tables are * 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 +* import - lets you add every file to the index in a chosen directory * meta - a command to change aliases of categorties and tags * 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 diff --git a/image-index b/image-index index 3e5b6be..808d36c 100755 --- a/image-index +++ b/image-index @@ -538,13 +538,17 @@ def add(args): eingabe="default" args.append(eingabe) if i in ["Filepath"]: + filehash=tb.get_hash(args[n]) + if filehash in str(tb.get_col("HASH")): + print("This file already exists!") + return False if not args[n]: print("{} must not be empty!".format(i)) - return 1 + return False else: if not Path(args[n]).is_file(): print(" The file '{}' doesn't exist or is not a file!".format(args[n])) - return 1 + return False n+=1 success=tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5]) if success: @@ -633,6 +637,9 @@ def help(args): print("delete:\tdeletes a file and entry based on a search query;\n\tInstant: image-index delete ") print("\tPrompt: image-index delete") print("EXAMPLE:\nimage-index delete -t Example -g Tag Example -a .mp4 add\n") + elif re.match('[iI].*',arg): + print("\timport:\tshows an add prompt for every file in a directory;\n\t\tSyntax: image-index import ") + print("EXAMPLE:\nimage-index import ~/Pictures/Vacation\n") elif re.match('[oO].*',arg): print("open:\topens a file based on a search query in the standard app;\n\tInstant: image-index open ") print("\tPrompt: image-index open") @@ -659,10 +666,24 @@ def help(args): print("\tadd:\tadds a new entry;\n\t\tSyntax: image-index add <source> <tags> <content>") print("\tcheck:\tchecks the existence and correctness of all files in the index;\n\t\tSyntax: image-index check [options]") print("\tdelete:\tdeletes a file and entry based on a search query;\n\t\tSyntax: image-index delete <words/filters>") + print("\timport:\tshows an add prompt for every file in a directory;\n\t\tSyntax: image-index import <directory path>") print("\topen:\topens a file based on a search query in the standard app;\n\t\tSyntax: image-index open <words/filters>") print("\tshow:\tsearches through the index and shows the matches;\n\t\tSyntax: image-index show <words/filters>") print("\tupdate:\tchanges specific column based on a search query;\n\t\tSyntax: image-index update <column> <updated_value> <words/filters>") +def imports(args): + for arg in args: + if os.path.exists(arg): + if not Path(arg).is_file(): + for sfile in os.listdir(arg): + if Path(arg,sfile).is_file(): + #print("{}{}".format(arg,sfile)) + add(["{}{}".format(arg,sfile)]) + else: + print("Path '{}' is a file!".format(arg)) + else: + print("Path '{}' doesn't exist!".format(arg)) + def meta(args): if len(args) == 0 or re.match('[hH].*',args[0]): meta_help() @@ -737,7 +758,7 @@ def meta_help(): print('\t\tExamples: image-index meta update tags Example "New alias"') print('\t\t\t image-index meta update category "A Category" "Example Category"\n') -def sopen(args): +def opens(args): plat=sys.platform selection=search(args,True) for sel in selection: @@ -850,8 +871,10 @@ def main(): check(args) elif re.match('[dD].*',command): delete(args) + elif re.match('[iI].*',command): + imports(args) elif re.match('[oO].*',command): - sopen(args) + opens(args) elif re.match('[sS].*',command): show(args) elif re.match('[uU].*',command):