shethjenil
commited on
Commit
•
cbfaee1
1
Parent(s):
01989b5
Update PYTOIMAGE.py
Browse files- PYTOIMAGE.py +18 -13
PYTOIMAGE.py
CHANGED
@@ -36,13 +36,12 @@ def package_app(folderpath: str,iconpath: str,saveappimage: str):
|
|
36 |
import socket
|
37 |
import threading
|
38 |
from argparse import ArgumentParser
|
39 |
-
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,globals())
|
@@ -58,7 +57,6 @@ def run_command(command:str):
|
|
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()
|
@@ -72,15 +70,16 @@ def handle_client(conn, addr):
|
|
72 |
else:
|
73 |
conn.sendall("Action performed".encode())
|
74 |
conn.close()
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
84 |
while True:
|
85 |
conn, addr = server_socket.accept()
|
86 |
if threading.activeCount() <= 3:
|
@@ -88,8 +87,14 @@ def main():
|
|
88 |
client_thread.start()
|
89 |
else:
|
90 |
pass
|
|
|
91 |
if __name__ == "__main__":
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
93 |
""")
|
94 |
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()
|
95 |
rmtree("build")
|
|
|
36 |
import socket
|
37 |
import threading
|
38 |
from argparse import ArgumentParser
|
39 |
+
import flask
|
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 |
def run_command(command:str):
|
46 |
try:
|
47 |
result = eval(command,globals())
|
|
|
57 |
return str(e)
|
58 |
except Exception as e:
|
59 |
return str(e)
|
|
|
60 |
def handle_client(conn, addr):
|
61 |
while True:
|
62 |
data = conn.recv(1024).decode()
|
|
|
70 |
else:
|
71 |
conn.sendall("Action performed".encode())
|
72 |
conn.close()
|
73 |
+
host = args.address
|
74 |
+
port = args.port
|
75 |
+
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
76 |
+
server_socket.bind((host, port))
|
77 |
+
server_socket.listen(args.max_connections)
|
78 |
+
app = flask.Flask(__name__)
|
79 |
+
@app.route("/")
|
80 |
+
def index():
|
81 |
+
return run_command(flask.request.args.get("command"))
|
82 |
+
def socketlistener():
|
83 |
while True:
|
84 |
conn, addr = server_socket.accept()
|
85 |
if threading.activeCount() <= 3:
|
|
|
87 |
client_thread.start()
|
88 |
else:
|
89 |
pass
|
90 |
+
|
91 |
if __name__ == "__main__":
|
92 |
+
T1 = threading.Thread(target=socketlistener)
|
93 |
+
T2 = threading.Thread(target=app.run, kwargs={"host": host, "port": port})
|
94 |
+
T1.start()
|
95 |
+
T2.start()
|
96 |
+
T1.join()
|
97 |
+
T2.join()
|
98 |
""")
|
99 |
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()
|
100 |
rmtree("build")
|