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, 3, 12, 32), 'os.path.exists', 'os.path.exists', ({(12, 18, 12, 31): 'filedirectory'}, {}), '(filedirectory)', False, 'import os\n'), ((18, 12, 18, 27), 'os.listdir', 'os.listdir', ({(18, 23, 18, 26): '"""."""'}, {}), "('.')", False, 'import os\n'), ((23, 0, 23, 47), 'os.rename', 'os.rename', ({(23, 10, 23, 25): '"""dist\\\\Main.exe"""', (23, 27, 23, 46): '"""dist\\\\WinTools.exe"""'}, {}), "('dist\\\\Main.exe', 'dist\\\\WinTools.exe')", False, 'import os\n'), ((26, 0, 26, 93), 'shutil.make_archive', 'shutil.make_archive', (), '', False, 'import shutil\n'), ((27, 0, 27, 41), 'os.rename', 'os.rename', ({(27, 10, 27, 24): '"""WinTools.zip"""', (27, 26, 27, 40): '"""WinTools.tpp"""'}, {}), "('WinTools.zip', 'WinTools.tpp')", False, 'import os\n'), ((15, 4, 15, 38), 'os.makedirs', 'os.makedirs', ({(15, 16, 15, 37): "('temp/' + filedirectory)"}, {}), "('temp/' + filedirectory)", False, 'import os\n'), ((24, 25, 24, 36), 'os.getcwd', 'os.getcwd', ({}, {}), '()', False, 'import os\n'), ((13, 27, 13, 38), 'os.getcwd', 'os.getcwd', ({}, {}), '()', False, 'import os\n'), ((21, 53, 21, 88), 'os.path.join', 'os.path.join', ({(21, 66, 21, 72): '"""temp"""', (21, 74, 21, 87): 'filedirectory'}, {}), "('temp', filedirectory)", False, 'import os\n'), ((21, 33, 21, 44), 'os.getcwd', 'os.getcwd', ({}, {}), '()', False, 'import os\n')]