File size: 3,870 Bytes
a541fec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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)