Update GUI building script
This commit is contained in:
parent
6598f0e2c3
commit
e9b2653ad0
@ -1 +1,4 @@
|
|||||||
* [Ubuntu](https://assets.ubuntu.com/v1/0cef8205-ubuntu-font-family-0.83.zip) font family.
|
## 🧰 Завиисимости для сборки:
|
||||||
|
|
||||||
|
* webui 2.4.2
|
||||||
|
* Семейство шрифтов [Ubuntu](https://assets.ubuntu.com/v1/0cef8205-ubuntu-font-family-0.83.zip)
|
||||||
|
95
build_gui.py
95
build_gui.py
@ -6,99 +6,114 @@ from bs4 import BeautifulSoup, Tag
|
|||||||
from jsmin import jsmin
|
from jsmin import jsmin
|
||||||
from csscompressor import compress
|
from csscompressor import compress
|
||||||
|
|
||||||
# html param
|
if __name__ == '__main__':
|
||||||
|
# html input param
|
||||||
html = sys.argv[1]
|
html = sys.argv[1]
|
||||||
# target param
|
# target output param
|
||||||
target = sys.argv[2]
|
target = sys.argv[2]
|
||||||
|
|
||||||
# path from html param
|
# path from html param
|
||||||
path = re.sub(r"[^\/]*$", "", html)
|
path = re.sub(r'[^\/]*$', '', html)
|
||||||
|
|
||||||
# open html file
|
# open html file
|
||||||
|
print('📂 Open HTML file...', end=' ')
|
||||||
soup = BeautifulSoup(open(html), 'html.parser')
|
soup = BeautifulSoup(open(html), 'html.parser')
|
||||||
|
print('OK!')
|
||||||
|
|
||||||
# find last script as anchorpoint
|
# find last script as anchorpoint
|
||||||
lastScript = soup.findAll("script", attrs = {"src" : True})[-1]
|
lastScript = soup.findAll('script', attrs={'src': True})[-1]
|
||||||
# get all scripts containing src attribute (= external scripts)
|
# get all scripts containing src attribute (= external scripts)
|
||||||
scripts = soup.findAll("script", attrs = {"src" : True})
|
scripts = soup.findAll('script', attrs={'src': True})
|
||||||
|
|
||||||
# find last style link as anchorpoint
|
# find last style link as anchorpoint
|
||||||
lastStylesheet = soup.findAll("link", attrs = {"rel" : "stylesheet"})[-1]
|
lastStylesheet = soup.findAll('link', attrs={'rel': 'stylesheet'})[-1]
|
||||||
# get all links to css stylesheets
|
# get all links to css stylesheets
|
||||||
stylesheets = soup.findAll("link", attrs = {"rel" : "stylesheet"})
|
stylesheets = soup.findAll('link', attrs={'rel': 'stylesheet'})
|
||||||
|
|
||||||
# create list of script srcs
|
# create list of script srcs
|
||||||
print("\nRead Scripts:")
|
print('🔎 Create list of scripts...', end=' ')
|
||||||
scriptsSrc = deque()
|
scriptsSrc = deque()
|
||||||
for script in scripts:
|
for script in scripts:
|
||||||
scriptsSrc.append(path + script.attrs["src"])
|
scriptsSrc.append(path + script.attrs['src'])
|
||||||
print("\t" + path + script.attrs["src"])
|
print('Complete!')
|
||||||
|
|
||||||
# create list of stylesheets srcs
|
# create list of stylesheets srcs
|
||||||
print("\nRead Stylesheets:")
|
print('🔎 Create list of stylesheets...', end=' ')
|
||||||
stylesheetsSrc = deque()
|
stylesheetsSrc = deque()
|
||||||
for stylesheet in stylesheets:
|
for stylesheet in stylesheets:
|
||||||
stylesheetsSrc.append(path + stylesheet.attrs["href"])
|
stylesheetsSrc.append(path + stylesheet.attrs['href'])
|
||||||
print("\t" + path + stylesheet.attrs["href"])
|
print('Complete!')
|
||||||
|
|
||||||
# merge scripts to temp.js
|
# merge scripts to .temp.js
|
||||||
print("\nMerge Scripts:")
|
print('📥 Merge scripts...', end=' ')
|
||||||
print("\t", end="")
|
with open('.temp.js', 'w') as outfileScript:
|
||||||
with open("temp.js", "w") as outfileScript:
|
|
||||||
for fname in scriptsSrc:
|
for fname in scriptsSrc:
|
||||||
# add space every script
|
# add space every script
|
||||||
if fname != 'gui//webui.js':
|
if fname != 'gui//webui.js':
|
||||||
outfileScript.write("\n")
|
outfileScript.write('\n')
|
||||||
print("~", end="")
|
|
||||||
with open(fname) as infile:
|
with open(fname) as infile:
|
||||||
for line in infile:
|
for line in infile:
|
||||||
outfileScript.write(line)
|
outfileScript.write(line)
|
||||||
print("\n");
|
print('Complete!')
|
||||||
|
|
||||||
|
print('📥 Merge stylsheets...', end=' ')
|
||||||
# merge stylsheets to temp.css
|
# merge stylsheets to temp.css
|
||||||
print("Merge Stylesheets:")
|
with open('.temp.css', 'w') as outfileCSS:
|
||||||
print("\t", end="")
|
|
||||||
with open("temp.css", "w") as outfileCSS:
|
|
||||||
for fname in stylesheetsSrc:
|
for fname in stylesheetsSrc:
|
||||||
# add space every script
|
# add space every script
|
||||||
outfileCSS.write("\n")
|
outfileCSS.write('\n')
|
||||||
print("~", end="")
|
|
||||||
with open(fname) as infile:
|
with open(fname) as infile:
|
||||||
for line in infile:
|
for line in infile:
|
||||||
outfileCSS.write(line)
|
outfileCSS.write(line)
|
||||||
print("\n");
|
print('Complete!')
|
||||||
|
|
||||||
# minify javascript
|
# minify javascript
|
||||||
print("Minify temp.js\n\t~")
|
print('🗃️ Minify scripts...', end=' ')
|
||||||
with open("temp.js") as js:
|
with open('.temp.js') as js:
|
||||||
minified_js = jsmin(js.read())
|
minified_js = jsmin(js.read())
|
||||||
|
print('Complete!')
|
||||||
|
|
||||||
# minify css
|
# minify css
|
||||||
print("\nMinify temp.css\n\t~")
|
print('🗃️ Minify stylsheets...', end=' ')
|
||||||
with open("temp.css") as css:
|
with open('.temp.css') as css:
|
||||||
minified_css = compress(css.read())
|
minified_css = compress(css.read())
|
||||||
|
print('Complete!')
|
||||||
|
|
||||||
# replace scripts with merged and min embed script / css
|
# replace scripts with merged and min embed script / css
|
||||||
print("\nReplacing and deleting\n\t~")
|
print('🔄 Embedding script and stylsheets...', end=' ')
|
||||||
tag = soup.new_tag("script")
|
tag = soup.new_tag('script')
|
||||||
tag["type"] = "text/javascript"
|
tag['type'] = 'text/javascript'
|
||||||
tag.append(minified_js)
|
tag.append(minified_js)
|
||||||
lastScript.replace_with(tag)
|
lastScript.replace_with(tag)
|
||||||
|
|
||||||
tag = soup.new_tag("style")
|
webui_tag = soup.new_tag('script')
|
||||||
tag["type"] = "text/css"
|
webui_tag['type'] = 'text/javascript'
|
||||||
|
webui_tag['src'] = '/webui.js'
|
||||||
|
tag.insert_before(webui_tag)
|
||||||
|
|
||||||
|
tag = soup.new_tag('style')
|
||||||
|
tag['type'] = 'text/css'
|
||||||
tag.append(minified_css)
|
tag.append(minified_css)
|
||||||
lastStylesheet.replace_with(tag)
|
lastStylesheet.replace_with(tag)
|
||||||
|
print('Complete!')
|
||||||
|
|
||||||
# remove script and style tags
|
# remove script and style tags
|
||||||
|
print('🧹 Cleaning...', end=' ')
|
||||||
for script in scripts:
|
for script in scripts:
|
||||||
script.decompose()
|
script.decompose()
|
||||||
for stylesheet in stylesheets:
|
for stylesheet in stylesheets:
|
||||||
stylesheet.decompose()
|
stylesheet.decompose()
|
||||||
|
|
||||||
#remove temp
|
# remove temp files
|
||||||
os.remove("temp.js")
|
os.remove('.temp.js')
|
||||||
os.remove("temp.css")
|
os.remove('.temp.css')
|
||||||
|
print('Complete!')
|
||||||
|
|
||||||
# save html as target
|
# save html as target
|
||||||
file = open(target,"w")
|
print('💾 Save builded document...', end=' ')
|
||||||
|
file = open(target, 'w')
|
||||||
file.write(soup.prettify())
|
file.write(soup.prettify())
|
||||||
file.close()
|
file.close()
|
||||||
|
print('Complete!', end='\n\n')
|
||||||
|
|
||||||
print("\nFIN\n")
|
print('🏁 Complete')
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="bootstrap-v5.3.1.min.css" />
|
<link rel="stylesheet" type="text/css" href="bootstrap-v5.3.1.min.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="ubuntu-font.css" />
|
<link rel="stylesheet" type="text/css" href="ubuntu-font.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="styles.css" />
|
<link rel="stylesheet" type="text/css" href="styles.css" />
|
||||||
<script src="app.js"></script>
|
|
||||||
<script src="/webui.js"></script>
|
<script src="/webui.js"></script>
|
||||||
|
<script src="/app.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="d-flex h-100 text-bg-dark">
|
<body class="d-flex h-100 text-bg-dark">
|
||||||
<div class="d-flex h-100 mx-auto p-3">
|
<div class="d-flex h-100 mx-auto p-3">
|
||||||
|
4
pyproject.toml
Normal file
4
pyproject.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[tool.black]
|
||||||
|
skip-string-normalization = true
|
||||||
|
pycodestyle = true
|
||||||
|
line-length = 100
|
Loading…
Reference in New Issue
Block a user