added open function
This commit is contained in:
		
							parent
							
								
									436db0e977
								
							
						
					
					
						commit
						6a00869ffd
					
				
					 3 changed files with 27 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
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
 | 
			
		||||
							
								
								
									
										25
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										25
									
								
								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 <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("\tupdate:\tchanges specific column based on a search query;\n\t\tInstant: image-index update <column> <updated_value> <words/filters>")
 | 
			
		||||
| 
						 | 
				
			
			@ -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'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue