Did lots of stuff
This commit is contained in:
parent
75fa3e05e4
commit
4218eb3c55
77
Backend.py
77
Backend.py
@ -7,6 +7,10 @@ import time
|
||||
import os
|
||||
import datetime
|
||||
import zipfile
|
||||
from customtkinter import *
|
||||
import time
|
||||
import math
|
||||
|
||||
|
||||
|
||||
def perform_installation(instance_name, prism_command, prism_instance_path, pack):
|
||||
@ -39,7 +43,7 @@ def perform_installation(instance_name, prism_command, prism_instance_path, pack
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
modpack_file_path = os.path.join(temp_dir, instance_name + ".mrpack")
|
||||
with open(modpack_file_path, 'wb') as modpack:
|
||||
ftp.retrbinary("RETR " + versions[-1]["File"], modpack.write)
|
||||
ftpDownload(ftp, versions[-1]["File"], modpack)
|
||||
|
||||
# Running PrismLauncher with modpack
|
||||
subprocess.Popen([prism_command, '-I', modpack_file_path])
|
||||
@ -52,7 +56,8 @@ def perform_installation(instance_name, prism_command, prism_instance_path, pack
|
||||
version = fp.readline().rstrip()
|
||||
if version == versions[-1]["Version"]:
|
||||
break
|
||||
except:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("Unable to check for updates. Modpack may be out of date")
|
||||
finally:
|
||||
# Launching PrismLauncher with the instance
|
||||
@ -132,6 +137,74 @@ def createModpack(id, name, username, password):
|
||||
ftp.mkd("Versions")
|
||||
ftp.close()
|
||||
|
||||
def deleteModpack(username, password, id):
|
||||
ftp = FTP("gitea.piwalker.net", username, password)
|
||||
ftp.prot_p()
|
||||
modpacks = getModpacks()
|
||||
for pack in modpacks:
|
||||
if pack["id"] == id:
|
||||
modpacks.remove(pack)
|
||||
break
|
||||
uploadModpacks(modpacks, ftp)
|
||||
deleteFolder(ftp, id)
|
||||
|
||||
def deleteFolder(ftp, path):
|
||||
print("Deleting folder: "+path)
|
||||
ftp.cwd(path)
|
||||
for item in ftp.nlst():
|
||||
try:
|
||||
print("deleting file: "+path)
|
||||
ftp.delete(item)
|
||||
except:
|
||||
deleteFolder(ftp, item)
|
||||
ftp.cwd("..")
|
||||
ftp.rmd(path)
|
||||
|
||||
def ftpDownload(ftp, file, stream):
|
||||
#create tkinter window
|
||||
print("downloading file: "+file)
|
||||
dialog = CTk()
|
||||
dialog.attributes('-type', 'dialog')
|
||||
dialog.title("Downloading Modpack")
|
||||
set_appearance_mode("dark")
|
||||
set_default_color_theme("blue")
|
||||
|
||||
global pbar
|
||||
pbar = CTkProgressBar(master=dialog)
|
||||
pbar.pack(padx=20, pady=20)
|
||||
global progress
|
||||
global ETA
|
||||
progress = StringVar()
|
||||
ETA = StringVar()
|
||||
progress_label = CTkLabel(master=dialog, textvariable=progress)
|
||||
progress_label.pack()
|
||||
eta_label = CTkLabel(master=dialog, textvariable=ETA)
|
||||
eta_label.pack()
|
||||
size = ftp.size(file)
|
||||
global total
|
||||
total = 0
|
||||
global start
|
||||
global timer
|
||||
timer = 0
|
||||
start = time.time()
|
||||
dialog.update()
|
||||
|
||||
def downloadCallback(data):
|
||||
global total
|
||||
global pbar
|
||||
global start
|
||||
global progress
|
||||
global ETA
|
||||
global timer
|
||||
stream.write(data)
|
||||
total += len(data)
|
||||
if time.time() - timer >= 1:
|
||||
progress.set(str(round(total/1048576, 1))+" MB / "+str(round(size/1048576, 1))+" MB @ " + str(round((total/1048576)/(time.time()-start), 3))+" MB/s")
|
||||
time_left = (size-total)/(total/(time.time()-start))
|
||||
ETA.set("ETA: " + str(datetime.timedelta(seconds=math.ceil(time_left))))
|
||||
pbar.set(total/size)
|
||||
dialog.update()
|
||||
timer = time.time()
|
||||
ftp.retrbinary("RETR " + file, downloadCallback)
|
||||
dialog.quit()
|
||||
|
||||
|
30
Upload.py
30
Upload.py
@ -38,7 +38,7 @@ def update_pack():
|
||||
if pack["name"] == modpack.get():
|
||||
pack_id = pack["id"]
|
||||
Backend.upload_pack(username, password, version.get(), fileName, pack_id)
|
||||
messagebox.Message(title="complete", message="Modpack updated successfuly")
|
||||
messagebox.Message(title="complete", message="Modpack updated successfuly").show()
|
||||
|
||||
def create_pack():
|
||||
global username
|
||||
@ -60,6 +60,19 @@ def create_pack():
|
||||
Backend.upload_pack(username, password, version.get(), fileName, modpack_id.get())
|
||||
messagebox.Message(title="complete", message="Modpack created successfully").show()
|
||||
|
||||
def delete_pack():
|
||||
global username
|
||||
global password
|
||||
global modpacks
|
||||
global modpack_delete
|
||||
get_credentials()
|
||||
pack_id = None
|
||||
for pack in modpacks:
|
||||
if pack["name"] == modpack_delete.get():
|
||||
pack_id = pack["id"]
|
||||
|
||||
Backend.deleteModpack(username, password, pack_id)
|
||||
|
||||
def main():
|
||||
global fileName
|
||||
global modpacks
|
||||
@ -67,6 +80,7 @@ def main():
|
||||
global version
|
||||
global modpack
|
||||
global modpack_name
|
||||
global modpack_delete
|
||||
fileName = "modpack.mrpack"
|
||||
|
||||
app = CTk()
|
||||
@ -80,6 +94,7 @@ def main():
|
||||
modpack = StringVar()
|
||||
modpack_name = StringVar()
|
||||
modpack_id = StringVar()
|
||||
modpack_delete = StringVar()
|
||||
|
||||
|
||||
|
||||
@ -102,6 +117,7 @@ def main():
|
||||
guitabs.pack(expand=True, fill='x', side="bottom", padx=0, pady=(10,0))
|
||||
guitabs.add("Update Pack")
|
||||
guitabs.add("Create Pack")
|
||||
guitabs.add("Delete Pack")
|
||||
|
||||
modpacks = Backend.getModpacks()
|
||||
options = []
|
||||
@ -127,6 +143,18 @@ def main():
|
||||
create_button = CTkButton(master=guitabs.tab("Create Pack"), text="Create", command=create_pack)
|
||||
create_button.pack(pady=5)
|
||||
|
||||
modpack_selector_delete = CTkOptionMenu(master=guitabs.tab("Delete Pack"), values=options, variable=modpack_delete)
|
||||
modpack_selector_delete.set(options[0])
|
||||
modpack_selector_delete.pack()
|
||||
|
||||
delete_button = CTkButton(master=guitabs.tab("Delete Pack"), text="Delete", command=delete_pack)
|
||||
delete_button.pack(pady=5)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#username = input("Username: ")
|
||||
#password = getpass()
|
||||
|
Loading…
Reference in New Issue
Block a user