shethjenil
commited on
Update RUNAPP.py
Browse files
RUNAPP.py
CHANGED
@@ -1,46 +1,46 @@
|
|
1 |
-
from zipfile import ZipFile
|
2 |
-
from subprocess import Popen
|
3 |
-
from os import path , getenv , kill
|
4 |
-
from shutil import rmtree
|
5 |
-
import argparse
|
6 |
-
from tkinter.filedialog import askopenfilename
|
7 |
-
import socket
|
8 |
-
import atexit
|
9 |
-
def check_port(port:int,host:str) -> bool:
|
10 |
-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
11 |
-
try:
|
12 |
-
s.settimeout(1) # Adjust timeout as needed
|
13 |
-
s.connect((host, port))
|
14 |
-
s.close()
|
15 |
-
return True
|
16 |
-
except (socket.timeout, ConnectionRefusedError):
|
17 |
-
return False
|
18 |
-
argparser = argparse.ArgumentParser()
|
19 |
-
argparser.add_argument("-p","--port",type=int,default=12345,help="port number")
|
20 |
-
argparser.add_argument("-a","--host",type=str,default="localhost",help="host address")
|
21 |
-
argparser.add_argument("-i","--image",type=str,help="app image")
|
22 |
-
args = argparser.parse_args()
|
23 |
-
folder = getenv("LOCALAPPDATA")+"\\"+f"JenilSoftware_{args.host}_{args.port}"
|
24 |
-
process = None
|
25 |
-
def kill_process():
|
26 |
-
if process:
|
27 |
-
kill(process.pid)
|
28 |
-
rmtree(folder)
|
29 |
-
atexit.register(kill_process)
|
30 |
-
try:
|
31 |
-
if path.exists(folder):
|
32 |
-
rmtree(folder)
|
33 |
-
image = None
|
34 |
-
if not check_port(args.port,args.host):
|
35 |
-
if args.image:
|
36 |
-
image = args.image
|
37 |
-
else:
|
38 |
-
image = askopenfilename(filetypes=[("Application Image",["*.png"])],defaultextension=".png")
|
39 |
-
ZipFile(image).extractall(folder)
|
40 |
-
process = Popen([folder+r"\main
|
41 |
-
process.wait()
|
42 |
-
else:
|
43 |
-
raise Exception("port is not available for app")
|
44 |
-
except Exception as e:
|
45 |
-
print(e)
|
46 |
-
rmtree(folder)
|
|
|
1 |
+
from zipfile import ZipFile
|
2 |
+
from subprocess import Popen
|
3 |
+
from os import path , getenv , kill
|
4 |
+
from shutil import rmtree
|
5 |
+
import argparse
|
6 |
+
from tkinter.filedialog import askopenfilename
|
7 |
+
import socket
|
8 |
+
import atexit
|
9 |
+
def check_port(port:int,host:str) -> bool:
|
10 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
11 |
+
try:
|
12 |
+
s.settimeout(1) # Adjust timeout as needed
|
13 |
+
s.connect((host, port))
|
14 |
+
s.close()
|
15 |
+
return True
|
16 |
+
except (socket.timeout, ConnectionRefusedError):
|
17 |
+
return False
|
18 |
+
argparser = argparse.ArgumentParser()
|
19 |
+
argparser.add_argument("-p","--port",type=int,default=12345,help="port number")
|
20 |
+
argparser.add_argument("-a","--host",type=str,default="localhost",help="host address")
|
21 |
+
argparser.add_argument("-i","--image",type=str,help="app image")
|
22 |
+
args = argparser.parse_args()
|
23 |
+
folder = getenv("LOCALAPPDATA")+"\\"+f"JenilSoftware_{args.host}_{args.port}"
|
24 |
+
process = None
|
25 |
+
def kill_process():
|
26 |
+
if process:
|
27 |
+
kill(process.pid)
|
28 |
+
rmtree(folder)
|
29 |
+
atexit.register(kill_process)
|
30 |
+
try:
|
31 |
+
if path.exists(folder):
|
32 |
+
rmtree(folder)
|
33 |
+
image = None
|
34 |
+
if not check_port(args.port,args.host):
|
35 |
+
if args.image:
|
36 |
+
image = args.image
|
37 |
+
else:
|
38 |
+
image = askopenfilename(filetypes=[("Application Image",["*.png"])],defaultextension=".png")
|
39 |
+
ZipFile(image).extractall(folder)
|
40 |
+
process = Popen([folder+r"\main","-p",str(args.port),"-a",str(args.host),"-m","2"],shell=True)
|
41 |
+
process.wait()
|
42 |
+
else:
|
43 |
+
raise Exception("port is not available for app")
|
44 |
+
except Exception as e:
|
45 |
+
print(e)
|
46 |
+
rmtree(folder)
|