shethjenil
commited on
Commit
•
a2b9707
1
Parent(s):
e20d978
Upload 2 files
Browse files- .gitattributes +1 -0
- PYTOIMAGE.exe +3 -0
- PYTOIMAGE.py +103 -0
.gitattributes
CHANGED
@@ -38,3 +38,4 @@ SECRIMG.exe filter=lfs diff=lfs merge=lfs -text
|
|
38 |
SONG_RECOGNIZER.exe filter=lfs diff=lfs merge=lfs -text
|
39 |
HIDEFILE.exe filter=lfs diff=lfs merge=lfs -text
|
40 |
SONGRECOGNIZER.exe filter=lfs diff=lfs merge=lfs -text
|
|
|
|
38 |
SONG_RECOGNIZER.exe filter=lfs diff=lfs merge=lfs -text
|
39 |
HIDEFILE.exe filter=lfs diff=lfs merge=lfs -text
|
40 |
SONGRECOGNIZER.exe filter=lfs diff=lfs merge=lfs -text
|
41 |
+
PYTOIMAGE.exe filter=lfs diff=lfs merge=lfs -text
|
PYTOIMAGE.exe
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0d4f1e251f3539054faad6498747ca5f485cb6bfd1bc84efca8cab2b780f2c8c
|
3 |
+
size 10085360
|
PYTOIMAGE.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from tkinter.messagebox import showwarning
|
2 |
+
from subprocess import Popen , DEVNULL ,PIPE
|
3 |
+
import sys
|
4 |
+
if Popen("pyinstaller",stderr=PIPE).communicate()[0]:
|
5 |
+
if not Popen("pip",stderr=PIPE).communicate()[0]:
|
6 |
+
Popen("pip install pyinstaller",stderr=DEVNULL,stdout=DEVNULL).communicate()
|
7 |
+
else:
|
8 |
+
showwarning("Pip not found","Python and Pip is required to run this program")
|
9 |
+
sys.exit()
|
10 |
+
from subprocess import Popen , DEVNULL
|
11 |
+
from zipfile import ZipFile , ZIP_DEFLATED
|
12 |
+
from os import walk , path , remove , getcwd
|
13 |
+
from shutil import rmtree
|
14 |
+
from io import BytesIO
|
15 |
+
from argparse import ArgumentParser
|
16 |
+
argparse = ArgumentParser()
|
17 |
+
argparse.add_argument("-c","--console",help="Run as console app",action="store_true")
|
18 |
+
argparse.add_argument("-f","--folder",help="Folder to package",type=str)
|
19 |
+
argparse.add_argument("-i","--icon",help="Icon file",type=str)
|
20 |
+
argparse.add_argument("-o","--output",help="Output file",type=str)
|
21 |
+
args = argparse.parse_args()
|
22 |
+
def save_zip(directory1,directory2):
|
23 |
+
bytes = BytesIO()
|
24 |
+
zipf = ZipFile(bytes, 'w', ZIP_DEFLATED)
|
25 |
+
for root, _, files in walk(directory1):
|
26 |
+
for file in files:
|
27 |
+
zipf.write(path.join(root, file), path.relpath(path.join(root, file), path.join(directory1, '.')))
|
28 |
+
for root, _, files in walk(directory2):
|
29 |
+
for file in files:
|
30 |
+
zipf.write(path.join(root, file), path.relpath(path.join(root, file), path.join(directory2, '.')))
|
31 |
+
zipf.close()
|
32 |
+
return bytes.getvalue()
|
33 |
+
|
34 |
+
def package_app(folderpath: str,iconpath: str,saveappimage: str):
|
35 |
+
open(rf"{folderpath}\app.py","w+").write("""
|
36 |
+
import socket
|
37 |
+
import threading
|
38 |
+
from argparse import ArgumentParser
|
39 |
+
from main import *
|
40 |
+
parser = ArgumentParser()
|
41 |
+
parser.add_argument("-p", "--port", dest="port", type=int, default=12345, help="port to listen on")
|
42 |
+
parser.add_argument("-a", "--address", dest="address", type=str, default="127.0.0.1", help="address to listen on")
|
43 |
+
parser.add_argument("-m", "--maximum-connections", dest="max_connections", type=int, default=2, help="maximum number of connections to allow")
|
44 |
+
args = parser.parse_args()
|
45 |
+
|
46 |
+
def run_command(command:str):
|
47 |
+
try:
|
48 |
+
result = eval(command)
|
49 |
+
if result:
|
50 |
+
return str(result)
|
51 |
+
else:
|
52 |
+
return
|
53 |
+
except SyntaxError:
|
54 |
+
try:
|
55 |
+
exec(command)
|
56 |
+
return
|
57 |
+
except Exception as e:
|
58 |
+
return str(e)
|
59 |
+
except Exception as e:
|
60 |
+
return str(e)
|
61 |
+
|
62 |
+
def handle_client(conn, addr):
|
63 |
+
while True:
|
64 |
+
data = conn.recv(1024).decode()
|
65 |
+
if not data:
|
66 |
+
break
|
67 |
+
response = run_command(data)
|
68 |
+
if response:
|
69 |
+
conn.sendall(response.encode())
|
70 |
+
else:
|
71 |
+
conn.sendall("Action performed".encode())
|
72 |
+
|
73 |
+
conn.close()
|
74 |
+
|
75 |
+
def main():
|
76 |
+
host = args.address
|
77 |
+
port = args.port
|
78 |
+
|
79 |
+
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
80 |
+
server_socket.bind((host, port))
|
81 |
+
server_socket.listen(args.max_connections)
|
82 |
+
|
83 |
+
while True:
|
84 |
+
conn, addr = server_socket.accept()
|
85 |
+
if threading.activeCount() <= 3:
|
86 |
+
client_thread = threading.Thread(target=handle_client, args=(conn, addr))
|
87 |
+
client_thread.start()
|
88 |
+
else:
|
89 |
+
pass
|
90 |
+
if __name__ == "__main__":
|
91 |
+
main()
|
92 |
+
""")
|
93 |
+
Popen(["pyinstaller","--noconfirm","--onedir","--console","--name","main","--contents-directory",".","--clean","--disable-windowed-traceback","--runtime-tmpdir",".","--distpath",getcwd(),folderpath+r"\app.py"],stdout=DEVNULL,stderr=DEVNULL).communicate()
|
94 |
+
rmtree("build")
|
95 |
+
remove("main.spec")
|
96 |
+
remove(folderpath+r"\app.py")
|
97 |
+
open(saveappimage,"wb").write(open(iconpath,"rb").read()+save_zip("main",folderpath))
|
98 |
+
rmtree("main")
|
99 |
+
if args.console:
|
100 |
+
package_app(args.folder,args.icon,args.output)
|
101 |
+
else:
|
102 |
+
from tkinter.filedialog import askdirectory , askopenfilename , asksaveasfilename
|
103 |
+
package_app(askdirectory(),askopenfilename(filetypes=[("Image files",["*.png","*.jpg","*.jpeg"])]),asksaveasfilename(defaultextension=".png",initialfile="hidden.png"))
|