shethjenil
commited on
Upload pyimageserverrun.py
Browse files- pyimageserverrun.py +11 -1
pyimageserverrun.py
CHANGED
@@ -1,7 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from argparse import ArgumentParser
|
2 |
from zipfile import ZipFile
|
3 |
from subprocess import Popen, PIPE
|
4 |
from shutil import rmtree
|
|
|
5 |
|
6 |
argparser = ArgumentParser()
|
7 |
argparser.add_argument("-i", "--image", type=str, help="app image", required=True)
|
@@ -11,6 +19,8 @@ argparser.add_argument("-a", "--address", type=str, default="0.0.0.0", help="add
|
|
11 |
args = argparser.parse_args()
|
12 |
folder = args.folder
|
13 |
rmtree(folder, ignore_errors=True)
|
|
|
|
|
14 |
ZipFile(args.image).extractall(folder)
|
15 |
try:
|
16 |
process = Popen([folder + "\\main", "-p", str(args.port), "-a", str(args.address)], stdout=PIPE, stderr=PIPE, shell=True)
|
@@ -25,4 +35,4 @@ try:
|
|
25 |
except Exception as e:
|
26 |
print(f"An error occurred: {e}")
|
27 |
finally:
|
28 |
-
rmtree(folder)
|
|
|
1 |
+
# import sys
|
2 |
+
# import ctypes
|
3 |
+
# if not ctypes.windll.shell32.IsUserAnAdmin():
|
4 |
+
# ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
|
5 |
+
# sys.exit()
|
6 |
+
|
7 |
+
|
8 |
from argparse import ArgumentParser
|
9 |
from zipfile import ZipFile
|
10 |
from subprocess import Popen, PIPE
|
11 |
from shutil import rmtree
|
12 |
+
import atexit
|
13 |
|
14 |
argparser = ArgumentParser()
|
15 |
argparser.add_argument("-i", "--image", type=str, help="app image", required=True)
|
|
|
19 |
args = argparser.parse_args()
|
20 |
folder = args.folder
|
21 |
rmtree(folder, ignore_errors=True)
|
22 |
+
atexit.register(lambda: rmtree(folder, ignore_errors=True))
|
23 |
+
|
24 |
ZipFile(args.image).extractall(folder)
|
25 |
try:
|
26 |
process = Popen([folder + "\\main", "-p", str(args.port), "-a", str(args.address)], stdout=PIPE, stderr=PIPE, shell=True)
|
|
|
35 |
except Exception as e:
|
36 |
print(f"An error occurred: {e}")
|
37 |
finally:
|
38 |
+
rmtree(folder)
|