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")

[((246, 275), 'os.path.exists', 'os.path.exists', (['filedirectory'], {}), '(filedirectory)\n', (260, 275), False, 'import os\n'), ((389, 404), 'os.listdir', 'os.listdir', (['"""."""'], {}), "('.')\n", (399, 404), False, 'import os\n'), ((664, 713), 'os.rename', 'os.rename', (['"""dist\\\\Main.exe"""', '"""dist\\\\WinTools.exe"""'], {}), "('dist\\\\Main.exe', 'dist\\\\WinTools.exe')\n", (673, 713), False, 'import os\n'), ((797, 894), 'shutil.make_archive', 'shutil.make_archive', ([], {'base_name': '"""WinTools"""', 'format': '"""zip"""', 'root_dir': '"""temp"""', 'base_dir': '"""WinTools"""'}), "(base_name='WinTools', format='zip', root_dir='temp',\n    base_dir='WinTools')\n", (816, 894), False, 'import shutil\n'), ((892, 933), 'os.rename', 'os.rename', (['"""WinTools.zip"""', '"""WinTools.tpp"""'], {}), "('WinTools.zip', 'WinTools.tpp')\n", (901, 933), False, 'import os\n'), ((340, 376), 'os.makedirs', 'os.makedirs', (["('temp/' + filedirectory)"], {}), "('temp/' + filedirectory)\n", (351, 376), False, 'import os\n'), ((737, 748), 'os.getcwd', 'os.getcwd', ([], {}), '()\n', (746, 748), False, 'import os\n'), ((304, 315), 'os.getcwd', 'os.getcwd', ([], {}), '()\n', (313, 315), False, 'import os\n'), ((618, 653), 'os.path.join', 'os.path.join', (['"""temp"""', 'filedirectory'], {}), "('temp', filedirectory)\n", (630, 653), False, 'import os\n'), ((598, 609), 'os.getcwd', 'os.getcwd', ([], {}), '()\n', (607, 609), False, 'import os\n')]