software / CLOUDSOFTWARE.py
shethjenil's picture
Upload 2 files
a541fec verified
raw
history blame
3.87 kB
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:
#import module's all sub modules
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")
)
# from argparse import ArgumentParser
# arg = ArgumentParser(description="Make a software using python")
# arg.add_argument("-n","--name",type=str,help="Name of the software")
# arg.add_argument("-l","--link",type=str,help="Link of the code")
# arg.add_argument("-m","--modules",type=str,nargs="+",help="Modules to import")
# arg.add_argument("-s","--submodules",type=str,nargs="+",help="Submodules to import")
# arg.add_argument("-g","--gui",action="store_true",help="Run the software in GUI mode")
# arg.add_argument("-i","--importsubmodules",action="store_true",help="Import all submodules of the modules")
# arg.add_argument("-o","--output",type=str,help="Output file name")
# args = arg.parse_args()
# makesof(args.name,args.link,args.modules,args.submodules,args.gui,args.importsubmodules,args.output)