import os
import json
import shutil

with open("entry.tp") as entry:
    entry = json.loads(entry.read())

startcmd = entry['plugin_start_cmd'].split("%TP_PLUGIN_FOLDER%")[1].split("\\")
filedirectory = startcmd[0]
fileName = startcmd[1]
    
if os.path.exists(filedirectory):
    os.remove(os.path.join(os.getcwd(), "WinTools"))
else:
    os.makedirs("temp/"+filedirectory)


for file in os.listdir("."):
    if file not in ["compile.py", "utils", "requirements.txt", "build", "dist", "main.py", "main.spec", "__pycache__", "temp"]:
        print("copying", file)
        shutil.copy(os.path.join(os.getcwd(), file), os.path.join("temp", filedirectory))
        
os.rename("dist\Main.exe", "dist\WinTools.exe")
shutil.copy(os.path.join(os.getcwd(), r"dist\WinTools.exe"), "temp/"+filedirectory)

shutil.make_archive(base_name="WinTools", format='zip', root_dir="temp", base_dir="WinTools") 
os.rename("WinTools.zip", "WinTools.tpp")

[(12, 'os.path.exists', 'os.path.exists', False, 'import os\n'), (18, 'os.listdir', 'os.listdir', False, 'import os\n'), (23, 'os.rename', 'os.rename', False, 'import os\n'), (26, 'shutil.make_archive', 'shutil.make_archive', False, 'import shutil\n'), (27, 'os.rename', 'os.rename', False, 'import os\n'), (15, 'os.makedirs', 'os.makedirs', False, 'import os\n'), (24, 'os.getcwd', 'os.getcwd', False, 'import os\n'), (13, 'os.getcwd', 'os.getcwd', False, 'import os\n'), (21, 'os.path.join', 'os.path.join', False, 'import os\n'), (21, 'os.getcwd', 'os.getcwd', False, 'import os\n')]