|
from subprocess import Popen,PIPE ,DEVNULL
|
|
from sys import exit as sys_exit
|
|
from os import remove
|
|
from shutil import rmtree , move
|
|
from tkinter.messagebox import showwarning , askokcancel
|
|
from tkinter.simpledialog import askstring
|
|
from tkinter.filedialog import askopenfilename , asksaveasfilename
|
|
from PyInstaller.utils.hooks import collect_submodules
|
|
if Popen("pyinstaller",stderr=PIPE).communicate()[0]:
|
|
if not Popen("python -m pip",stderr=PIPE).communicate()[0]:
|
|
Popen("python -m pip install pyinstaller",stderr=DEVNULL,stdout=DEVNULL).communicate()
|
|
else:
|
|
showwarning("Python is required to run this program")
|
|
sys_exit()
|
|
def add_modules()->list:
|
|
while True:
|
|
items = []
|
|
item = askstring("module","Enter the modules")
|
|
if item:
|
|
items.append(item)
|
|
else:
|
|
return items
|
|
def add_submodules()->list:
|
|
while True:
|
|
items = []
|
|
item = askstring("submodule","Enter the submodules")
|
|
if item:
|
|
items.append(item)
|
|
else:
|
|
return items
|
|
def makesof(name:str,linkofcode:str,modules:list,submodules:list,gui:bool=False,importsubmodules:bool=True,saveas:str=None):
|
|
if importsubmodules:
|
|
|
|
allsubmodules = []
|
|
for i in modules:
|
|
allsubmodules.extend(collect_submodules(i))
|
|
submodules = list(set(allsubmodules + submodules))
|
|
|
|
command = ["pyinstaller","--noconfirm","--clean","--onefile","--icon",askopenfilename(filetypes=[("Image","*.jpg *.jpeg *.png")],title="ICON"),"--name",name]
|
|
if gui:
|
|
command.append("--windowed")
|
|
for mudule in modules:
|
|
command.extend(["--hidden-import",mudule])
|
|
for module in submodules:
|
|
command.extend(["--collect-submodules",module])
|
|
command.append(f"{name}.py")
|
|
open(f"{name}.py","w").write(f"""
|
|
from sys import _MEIPASS as cdir , exit as sys_exit
|
|
from tkinter.messagebox import showerror
|
|
from os import chdir
|
|
from requests import get
|
|
chdir(cdir)
|
|
pytext = str()
|
|
try:
|
|
pytext = get("{linkofcode}",timeout=5).text
|
|
except Exception:
|
|
showerror("Connection Error","Could not connect to the internet")
|
|
sys_exit()
|
|
try:
|
|
exec(pytext)
|
|
except Exception as e:
|
|
showerror("Error",e)
|
|
""")
|
|
Popen(command,shell=True,stdout=DEVNULL,stderr=DEVNULL).communicate()
|
|
move(f"dist/{name}.exe",saveas)
|
|
remove(f"{name}.py")
|
|
rmtree("build")
|
|
remove(f"{name}.spec")
|
|
rmtree("dist")
|
|
makesof(name = askstring("Name","Enter the name of the software"),
|
|
linkofcode = askstring("Link","Enter the link of the code"),
|
|
modules = add_modules(),
|
|
submodules = add_submodules(),
|
|
gui=askokcancel("GUI mode","Do you want to run this program in GUI mode?"),
|
|
importsubmodules=askokcancel("Import submodules","Do you want to import all submodules of the modules?"),
|
|
saveas=asksaveasfilename(filetypes=[("Executable","*.exe")],title="Executable",initialfile="software.exe")
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|