From 6a00869ffd1aceec975aa1353e81ef780dc5a99c Mon Sep 17 00:00:00 2001 From: Michael Rodin Date: Wed, 16 Nov 2022 21:01:29 +0100 Subject: [PATCH] added open function --- README.md | 5 +++-- config-def.py | 3 ++- main.py | 25 ++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index aba7c81..b4f1874 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,12 @@ cp config-def.py config.py ## Functions * add - Add a file and entry to the index -* search - search through 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 -* check - check if all files in the index exist and have the correct hash ## 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/config-def.py b/config-def.py index 54b3cbd..e176cdc 100644 --- a/config-def.py +++ b/config-def.py @@ -1,4 +1,5 @@ import os ROOT_DIR=os.getcwd() # The directory where all directories and files of the index are located -CONFIG_DIR=ROOT_DIR # The directory where the file 'index.db' is located \ No newline at end of file +CONFIG_DIR=ROOT_DIR # The directory where the file 'index.db' is located +LINUX_APP_STARTER="xdg-open" # The command which opens the files in the default applications \ No newline at end of file diff --git a/main.py b/main.py index 0ad9bff..4f3e4d8 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ #!/bin/python3 -import sys,os,re +import sys,os,re,subprocess from func import * from config import * @@ -16,7 +16,7 @@ def add(): args.append(eingabe) tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5]) -def check(args): +def check(args): # TODO: Option to see all faulty/missing files. success=0 if not args: hash_list,path_list=tb.check_index() @@ -62,6 +62,8 @@ def help(): print("\tcheck:\tchecks the existence and correctness of all files in the index;\n\t\tSyntax: image-index check") print("\tdelete:\tdeletes a file and entry based on a search query;\n\t\tInstant: image-index delete ") 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 ") + print("\t\tPrompt: image-index open") print("\tsearch:\tsearches through the index (use prompt for list of filters);\n\t\tInstant: 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 ") @@ -71,6 +73,21 @@ def meta(args): command=args[0] args=args[1:] +def open(args): + plat=sys.platform + selection=search(args,True) + for sel in selection: + if not sel[0] == ".": + filename=sel[0] + category=sel[4] + filepath="{}/{}/{}".format(ROOT_DIR,category,filename) + else: + continue + if plat.startswith('linux'): + subprocess.Popen([LINUX_APP_STARTER, filepath]) + else: + os.startfile(filepath) + def update(args): if len(args) > 2: typ=args[0] @@ -157,6 +174,8 @@ def main(): check(args) elif re.match('[dD].*',command): delete(args) + elif re.match('[oO].*',command): + open(args) elif re.match('[sS].*',command): search(args) elif re.match('[uU].*',command): @@ -167,7 +186,7 @@ def main(): mtb.connection.close() #for i in sys.argv: # print("Arg:" + i) - input("Press return...") + #input("Press return...") if __name__ == "__main__": filepath=CONFIG_DIR + '/index.db'