diff --git a/.gitignore b/.gitignore index 5cfae61..065786b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ /** !/.gitignore +!/config-def.py #!/default !/func.py #!/index.db #!/Animals !/main.py -!/vars.py \ No newline at end of file +!/README.md \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..cfa0c6f --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# image-index +This project is a collection of scripts which can index and sort files on your pc. You can give every file a title, category, source, tags and content for easier finding later on. + +## Installation +```sh +$ git clone https://gitlab.com/rodin_schule/image-index-py.git +$ cd ./image-index-py +$ cp config-def.py config.py +``` +## 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) +* CONFIG_DIR: The absolute path of where you want to store your `index.db`-file. \ No newline at end of file diff --git a/vars.py b/config-def.py similarity index 100% rename from vars.py rename to config-def.py diff --git a/func.py b/func.py index 8f1d759..32b9429 100644 --- a/func.py +++ b/func.py @@ -1,7 +1,7 @@ import os,shutil,hashlib,re from uuid import uuid4 import sqlite3 as sql -from vars import * +from config import * class database(): def __init__(self,filepath): @@ -39,6 +39,12 @@ class database(): TAGS TEXT PRIMARY KEY NOT NULL ); """ self.crsr.execute(sqlcommand)''' + + def delete_index(self,typ,item): + self.crsr.execute("DELETE FROM {} WHERE {}='{}'".format(self.name,typ,item)) + self.connection.commit() + return + def get_col(self,column = "*"): # get the column of some table. If no options given, return all columns self.crsr.execute("SELECT {} FROM {}".format(column,self.name)) @@ -51,7 +57,7 @@ class database(): if not res: res="." return res - def get_item(self,column,where = "."): + def get_item(self,column,where): if column == "*": for col in self.collist: self.crsr.execute("SELECT * FROM {} WHERE {} GLOB '*{}*'".format(self.name,col,where)) @@ -109,6 +115,11 @@ class filestable(database): print("Executing") vallist=[filename,filehash,title,source,category,tags,content] super().add_index(vallist) + + def delete_index(self,sel_list): + self.get_item("HASH",sel_list[1]) + super().delete_index("HASH",sel_list[1]) + def sql_compare_list(self,typ,firstlist,secondlist): # TODO: Fix (fixed?) if firstlist: n=0 @@ -129,13 +140,14 @@ class filestable(database): if success > 0: #print("Hey",i[0]) if typ == "*": - temp_list.append(self.get_item("FILE",i[0])[0]) + temp_list.append(self.get_item("FILE",j[0])[0]) else: #print("TE",n,self.get_item(typ,i[0])[1]) - for j in self.get_item(typ,i[0]): - temp_list.append(i) + for k in self.get_item(typ,j[0]): + if not k in temp_list: + temp_list.append(k) #print("Self: ",self.get_item(typ,i[0])[n]) - print(temp_list) + #print(temp_list) n+=1 else: @@ -149,7 +161,7 @@ class filestable(database): else: #print("secondlist") return secondlist - print("Temp_list: ",temp_list) + #print("Temp_list: ",temp_list) if not temp_list: return ["."] return temp_list @@ -164,8 +176,8 @@ class filestable(database): f.close() return str(md5_hash.hexdigest()) - def search_index(self,arglist): - #print(arglist) + def search_index(self,args): + #print(args) #### ## WARNING!!!!!! UGLY CODE INCOMING!!!!!! #### @@ -178,7 +190,7 @@ class filestable(database): source=[] title=[] tags=[] - for arg in arglist: + for arg in args: if re.match('^[-]\w{1}$', arg): if arg == "-h": snext="hash" @@ -234,10 +246,12 @@ class filestable(database): if len(selection) > 1: n=0 #print(selection) + print("Found several matches:") for tup in selection: temp_list=[] for j in tup: temp_list.append(j) + #print("sdf",temp_list) print("Match [{}]".format(n)) print("\tTitle:\t ",temp_list[2]) print("\tCategory:",temp_list[4]) diff --git a/main.py b/main.py index 105ab3c..fcd6929 100755 --- a/main.py +++ b/main.py @@ -1,8 +1,8 @@ #!/bin/python3 import sys,os,re -os.chdir("ii-py") from func import * -from vars import * +from config import * + def add(): args=[] for i in ["Filepath","Category","Title","Source","Tags","Content"]: @@ -17,9 +17,18 @@ def add(): print(args) tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5]) +def delete(args): + selection=search(args) + if selection[0] != ".": + try: + category=selection[4] + filename=selection[0] + os.remove("{}/{}".format(category,filename)) + except Exception: + print("Couldn't delete file!") + return 1 + tb.delete_index(selection) -def delete(): - df="Hi" def help(): print("SYNTAX:\n\t'image-index' displays this text") print("\t'image-index