#!/bin/python3 import sys,os,re,subprocess from func import * from config import * def add(): args=[] for i in ["Filepath","Category","Title","Source","Tags","Content"]: eingabe = input("Enter {}: ".format(i)) if i in ["Filepath"] and not eingabe: print("{} has to not be empty!".format(i)) return 1 if i in ["Category"] and not eingabe: print("{} set to 'default'".format(i)) eingabe="default" args.append(eingabe) tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5]) def check(args): success=0 hash_list,temp_list=tb.check_index() path_list=[] hashcheck=pathcheck=True verbose=False for arg in args: if arg == "-v": verbose=True elif arg == "-f": hashcheck=False elif arg == "-h": pathcheck=False if hash_list: print("{} file{} faulty!".format(len(hash_list),"s are" if len(hash_list) > 1 else " is")) success=-1 if verbose: for tup in hash_list: print("Title: ",tup[2]) print("\tCategory:",tup[4]) print("\tFilename:",tup[0]) for i in temp_list: if not i in path_list: path_list.append(i) if path_list: print("{} file{} missing!".format(len(path_list),"s are" if len(path_list) > 1 else " is")) success=-1 if verbose: for tup in path_list: print("Title: ",tup[2]) print("\tCategory:",tup[4]) print("\tFilename:",tup[0]) if success >= 0: print("Everything is good!") if hash_list and hashcheck: eingabe=input("Do you want to remove the faulty files? [y/N]: ") if re.match('[yY]',eingabe): print("Removing faulty files...") repair(hash_list) if path_list and pathcheck: eingabe=input("Do you want to remove the orphaned entries? [Y/n]: ") if not re.match('[nN]',eingabe): print("Removing orphaned entries...") repair(path_list) def delete(args): selection=search(args,True) for sel in selection: if sel[0] != ".": try: category=sel[4] filename=sel[0] os.remove("{}/{}/{}".format(ROOT_DIR,category,filename)) except Exception as e: print(e) print("Couldn't delete a file!") return 1 tb.delete_index(sel) def help(): print("SYNTAX:\n\t'image-index