Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit c16d441

Browse files
authored
Release 1.0.0
1 parent 8d6b665 commit c16d441

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

build.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import json
2+
import os
3+
import subprocess
4+
import time
5+
from subprocess import Popen
6+
7+
try:
8+
manifestfile = open('manifest.json')
9+
manifest = json.load(manifestfile)
10+
exist=1
11+
except FileNotFoundError as e:
12+
print("Pyletron cannot find 'manifest.json' is missing! Please find it or make one.")
13+
print("Use Pyletron Manifest Generator to create a 'manifest.json'")
14+
print('https://github.com/pyletron/manifest-generator')
15+
exist=0
16+
time.sleep(10)
17+
quit()
18+
19+
20+
if os.path.exists('html')==False:
21+
print("Pyletron cannot find 'html' folder, this folder must contain the web application contents like 'html, css, js' and so on.")
22+
print("Please find or create the 'html' folder and insert all web contents into the folder then recompile/rebuild the application.")
23+
print('Closing in 10 seconds')
24+
time.sleep(10)
25+
quit()
26+
27+
if os.path.exists('html')==True:
28+
if os.path.exists('html/index.html')==False:
29+
print("Pyletron cannot find 'index.html' in the 'html' folder, this file must exist in the root of the 'html' folder.")
30+
print("Please find, rename or move the 'index.html' into the root of the 'html' folder.")
31+
print("'index.html' is the html file the application will first open.")
32+
print('Closing in 10 seconds')
33+
time.sleep(10)
34+
quit()
35+
36+
37+
def createPython():
38+
try:
39+
pyFile = open("main.py", "x")
40+
except FileExistsError as e:
41+
os.remove('main.py')
42+
pyFile = open("main.py", "x")
43+
print("File from previous build exists, deleted 'main.py'")
44+
pyLine = "webview.create_window('{}', 'html/index.html')\n".format(manifest['name'])
45+
pyContents = ["import webview\n",pyLine,"webview.start()\n\n","# GENERATED BY PYLETRON\n","# https://github.com/pyletron/builder"]
46+
pyFile.writelines(pyContents)
47+
pyFile.close()
48+
49+
if exist==1:
50+
print(manifest['name'])
51+
print(manifest['console'])
52+
print(manifest['onedir'])
53+
print(manifest['icon'])
54+
print(manifest['version'])
55+
print("Note: Files and Folder will be left behind, the 'dist' folder will be your output")
56+
if manifest['icon']=="":
57+
if manifest['onedir']==True:
58+
if manifest['console']==False:
59+
createPython()
60+
subprocess.Popen('pyinstaller --noconfirm --onedir --windowed --icon "pyletronIcon.ico" --add-data "html;html/" main.py ')
61+
if manifest['console']==True:
62+
createPython()
63+
subprocess.Popen('pyinstaller --noconfirm --onedir --console --icon "pyletronIcon.ico" --add-data "html;html/" main.py')
64+
if manifest['onedir']==False:
65+
if manifest['console']==False:
66+
createPython()
67+
subprocess.Popen('pyinstaller --noconfirm --onefile --windowed --icon "pyletronIcon.ico" --add-data "html;html/" main.py ')
68+
if manifest['console']==True:
69+
createPython()
70+
subprocess.Popen('pyinstaller --noconfirm --onefile --console --icon "pyletronIcon.ico" --add-data "html;html/" main.py')
71+
else:
72+
if manifest['onedir']==True:
73+
if manifest['console']==False:
74+
createPython()
75+
subprocess.Popen('pyinstaller --noconfirm --onedir --windowed --icon "{}" --add-data "html;html/" main.py '.format(manifest['icon']))
76+
if manifest['console']==True:
77+
createPython()
78+
subprocess.Popen('pyinstaller --noconfirm --onedir --console --icon "{}" --add-data "html;html/" main.py'.format(manifest['icon']))
79+
if manifest['onedir']==False:
80+
if manifest['console']==False:
81+
createPython()
82+
subprocess.Popen('pyinstaller --noconfirm --onefile --windowed --icon "{}" --add-data "html;html/" main.py '.format(manifest['icon']))
83+
if manifest['console']==True:
84+
createPython()
85+
subprocess.Popen('pyinstaller --noconfirm --onefile --console --icon "{}" --add-data "html;html/" main.py'.format(manifest['icon']))

0 commit comments

Comments
 (0)