166 lines
6.5 KiB
Python
166 lines
6.5 KiB
Python
import os
|
|
import ast
|
|
import tkinter as tk
|
|
from tqdm import tqdm
|
|
from tkinter import messagebox
|
|
import easygui
|
|
try:
|
|
container = tk.Tk("filesystem")
|
|
print("loading plugins")
|
|
plugins = {}
|
|
for i in os.listdir("plugins"):
|
|
print("ID of plugin: {}".format(i))
|
|
temp = open("plugins/{}".format(i), 'r')
|
|
temp = temp.read()
|
|
temp = ast.literal_eval(temp)
|
|
print("name of plugin: {}".format(temp["name"]))
|
|
print("author of plugin: {}".format(temp["author"]))
|
|
print("the plugin is designed for the extension: {}".format(temp["extension"]))
|
|
plugins[temp["name"]] = temp
|
|
print("initializing")
|
|
currentpath = ""
|
|
buttons = []
|
|
def showfile(target):
|
|
global currentpath
|
|
temp = open("files/"+currentpath+"/"+target, 'r')
|
|
temp = temp.read()
|
|
if temp.isnumeric() or temp == "":
|
|
filename, file_extension = os.path.splitext("files/"+currentpath+"/"+target)
|
|
print("showfile, extension: {}".format(file_extension))
|
|
found = []
|
|
for i in plugins:
|
|
if plugins[i]["extension"] == file_extension or plugins[i]["extension"] == ".*":
|
|
found.append(plugins[i]["name"])
|
|
if len(found) == 0:
|
|
messagebox.showerror("fehler!", "es wurde kein plugin gefunden dass für diese datei gemacht wurde.")
|
|
elif len(found) == 1:
|
|
exec(plugins[found[0]]["main"], {"path": "files/"+currentpath+"/"+target})
|
|
else:
|
|
choice = easygui.choicebox("bitte plugin zum öffnen auswählen", "datei öffnen", found)
|
|
if choice:
|
|
exec(plugins[choice]["main"], {"path": "files/"+currentpath+"/"+target})
|
|
else:
|
|
messagebox.showerror("fehler!", "datei ist beschädigt. pfad: {}".format("files/"+currentpath+"/"+target))
|
|
|
|
def switchtodir(target):
|
|
global currentpath
|
|
currentpath = currentpath+"/"+target
|
|
|
|
def showobject(target):
|
|
global currentpath
|
|
container2 = tk.Tk("datei")
|
|
def delete():
|
|
if os.path.isdir("files/"+currentpath+"/"+target):
|
|
def scandir(target):
|
|
for i in os.listdir(target):
|
|
if os.path.isdir(target+"/"+i):
|
|
scandir(target+"/"+i)
|
|
os.rmdir(target)
|
|
else:
|
|
print("removed target")
|
|
os.remove(target+"/"+i)
|
|
scandir("files/"+currentpath+"/"+target)
|
|
os.rmdir("files/"+currentpath+"/"+target)
|
|
update()
|
|
container2.destroy()
|
|
else:
|
|
os.remove("files/"+currentpath+"/"+target)
|
|
update()
|
|
container2.destroy()
|
|
def show():
|
|
if os.path.isdir("files/"+currentpath+"/"+target):
|
|
switchtodir(target)
|
|
update()
|
|
container2.destroy()
|
|
else:
|
|
showfile(target)
|
|
update()
|
|
container2.destroy()
|
|
name = tk.Label(container2, text="name: {}".format(os.path.basename(target)))
|
|
name.grid()
|
|
showbutton = tk.Button(container2, text="anzeigen", command=show)
|
|
showbutton.grid()
|
|
deletebutton = tk.Button(container2, text="löschen", command=delete)
|
|
deletebutton.grid()
|
|
container2.mainloop()
|
|
|
|
def goback():
|
|
global currentpath
|
|
currentpath = currentpath.split("/")
|
|
currentpath = currentpath[:-1]
|
|
temp = ""
|
|
for i in currentpath:
|
|
temp = temp + i + "/"
|
|
temp = temp[:-1]
|
|
currentpath = temp
|
|
update()
|
|
|
|
def createfile():
|
|
name = easygui.enterbox("bitte namen der datei eingeben", "datei erstellen")
|
|
if name:
|
|
if not os.path.exists("files/"+currentpath+"/"+name):
|
|
open("files/"+currentpath+"/"+name, 'x')
|
|
update()
|
|
else:
|
|
messagebox.showerror("fehler beim erstellen!", "kann datei nicht erstellen, datei existiert bereits!")
|
|
|
|
def createdir():
|
|
name = easygui.enterbox("bitte namen des ordners eingeben", "ordner erstellen")
|
|
if name:
|
|
if not os.path.exists("files/"+currentpath+"/"+name):
|
|
os.mkdir("files/"+currentpath+"/"+name)
|
|
update()
|
|
else:
|
|
messagebox.showerror("fehler beim erstellen!", "kann ordner nicht erstellen, ordner existiert bereits!")
|
|
|
|
def update():
|
|
global currentpath
|
|
global container
|
|
for i in tqdm(buttons.copy()):
|
|
i.grid_forget()
|
|
buttons.remove(i)
|
|
temp = os.listdir("files/{}".format(currentpath))
|
|
if currentpath != "" and currentpath != "/":
|
|
temp2 = tk.Button(container, text="...", command=goback)
|
|
temp2.grid()
|
|
buttons.append(temp2)
|
|
elif currentpath == "/":
|
|
currentpath = ""
|
|
temp2 = tk.Button(container, text="dateien und ordner aktualisieren", command=update)
|
|
temp2.grid()
|
|
buttons.append(temp2)
|
|
temp2 = tk.Button(container, text="neue datei erstellen", command=createfile)
|
|
temp2.grid()
|
|
buttons.append(temp2)
|
|
temp2 = tk.Button(container, text="neuen ordner erstellen", command=createdir)
|
|
temp2.grid()
|
|
buttons.append(temp2)
|
|
for i in tqdm(temp):
|
|
temp2 = tk.Button(container, text=i, command=lambda i=i: showobject(i))
|
|
temp2.grid()
|
|
buttons.append(temp2)
|
|
|
|
print("initializing done.")
|
|
print("checking files")
|
|
def scandir(target):
|
|
for i in os.listdir(target):
|
|
if os.path.isdir(target+"/"+i):
|
|
scandir(target+"/"+i)
|
|
else:
|
|
temp = open(target+"/"+i, 'r')
|
|
temp = temp.read()
|
|
if temp.isnumeric() or temp == "":
|
|
print("checked {}. all good".format(target+"/"+i))
|
|
else:
|
|
if messagebox.askyesno("fehler!", "fehler beim laden der datei! soll sie gelöscht werden?"):
|
|
os.remove(target+"/"+i)
|
|
else:
|
|
messagebox.showinfo("ok", "ok. filesystem wird einen fehler geben falls die datei versucht wird zu öffnen. path zur datei: {}".format(target+"/"+i))
|
|
scandir("files")
|
|
print("starting")
|
|
update()
|
|
container.mainloop()
|
|
|
|
except Exception as e:
|
|
messagebox.showerror("kritischer fehler!", "ein kritischer fehler ist aufgetaucht! fehler: {}".format(e))
|