Add support for dynamic frontend panels
This commit is contained in:
1 parent
35a57e1385
commit
22b4aebeb3
21 files changed
+197
-119
No files matched your search
+11
-26
@@ -2,36 +2,21 @@
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
cd homeassistant/components/frontend/www_static/home-assistant-polymer
|
||||
cd homeassistant/components/frontend/www_static
|
||||
rm -rf core.js* frontend.html* webcomponents-lite.min.js* panels
|
||||
cd home-assistant-polymer
|
||||
npm run clean
|
||||
npm run frontend_prod
|
||||
|
||||
cp bower_components/webcomponentsjs/webcomponents-lite.min.js ..
|
||||
cp build/frontend.html ..
|
||||
gzip build/frontend.html -c -k -9 > ../frontend.html.gz
|
||||
cp build/partial-map.html ..
|
||||
gzip build/partial-map.html -c -k -9 > ../partial-map.html.gz
|
||||
cp build/dev-tools.html ..
|
||||
gzip build/dev-tools.html -c -k -9 > ../dev-tools.html.gz
|
||||
cp build/_core_compiled.js ../core.js
|
||||
gzip build/_core_compiled.js -c -k -9 > ../core.js.gz
|
||||
|
||||
cp -r build/* ..
|
||||
node script/sw-precache.js
|
||||
cp build/service_worker.js ..
|
||||
gzip build/service_worker.js -c -k -9 > ../service_worker.js.gz
|
||||
|
||||
cd ..
|
||||
|
||||
gzip -f -k -9 *.html *.js ./panels/*.html
|
||||
|
||||
# Generate the MD5 hash of the new frontend
|
||||
cd ../..
|
||||
echo '"""DO NOT MODIFY. Auto-generated by build_frontend script."""' > version.py
|
||||
if [ $(command -v md5) ]; then
|
||||
echo 'CORE = "'`md5 -q www_static/core.js`'"' >> version.py
|
||||
echo 'UI = "'`md5 -q www_static/frontend.html`'"' >> version.py
|
||||
echo 'MAP = "'`md5 -q www_static/partial-map.html`'"' >> version.py
|
||||
echo 'DEV = "'`md5 -q www_static/dev-tools.html`'"' >> version.py
|
||||
elif [ $(command -v md5sum) ]; then
|
||||
echo 'CORE = "'`md5sum www_static/core.js | cut -c-32`'"' >> version.py
|
||||
echo 'UI = "'`md5sum www_static/frontend.html | cut -c-32`'"' >> version.py
|
||||
echo 'MAP = "'`md5sum www_static/partial-map.html | cut -c-32`'"' >> version.py
|
||||
echo 'DEV = "'`md5sum www_static/dev-tools.html | cut -c-32`'"' >> version.py
|
||||
else
|
||||
echo 'Could not find an MD5 utility'
|
||||
fi
|
||||
cd ../../../..
|
||||
script/fingerprint_frontend.py
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from collections import OrderedDict
|
||||
import glob
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
fingerprint_file = 'homeassistant/components/frontend/version.py'
|
||||
base_dir = 'homeassistant/components/frontend/www_static/'
|
||||
|
||||
|
||||
def fingerprint():
|
||||
"""Fingerprint the frontend files."""
|
||||
files = (glob.glob(base_dir + '**/*.html') +
|
||||
glob.glob(base_dir + '*.html') +
|
||||
glob.glob(base_dir + 'core.js'))
|
||||
|
||||
md5s = OrderedDict()
|
||||
|
||||
for fil in sorted(files):
|
||||
name = fil[len(base_dir):]
|
||||
with open(fil) as fp:
|
||||
md5 = hashlib.md5(fp.read().encode('utf-8')).hexdigest()
|
||||
md5s[name] = md5
|
||||
|
||||
template = """\"\"\"DO NOT MODIFY. Auto-generated by script/fingerprint_frontend.\"\"\"
|
||||
|
||||
FINGERPRINTS = {}
|
||||
"""
|
||||
|
||||
result = template.format(json.dumps(md5s, indent=4))
|
||||
|
||||
with open(fingerprint_file, 'w') as fp:
|
||||
fp.write(result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
fingerprint()
|
||||
+8
-39
@@ -1,38 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""Download the latest Polymer v1 iconset for materialdesignicons.com."""
|
||||
import hashlib
|
||||
import gzip
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
import sys
|
||||
|
||||
from fingerprint_frontend import fingerprint
|
||||
|
||||
GETTING_STARTED_URL = ('https://raw.githubusercontent.com/Templarian/'
|
||||
'MaterialDesign/master/site/getting-started.savvy')
|
||||
DOWNLOAD_LINK = re.compile(r'(/api/download/polymer/v1/([A-Z0-9-]{36}))')
|
||||
START_ICONSET = '<iron-iconset-svg'
|
||||
|
||||
CUR_VERSION = re.compile(r'VERSION = "([A-Za-z0-9]{32})"')
|
||||
|
||||
OUTPUT_BASE = os.path.join('homeassistant', 'components', 'frontend')
|
||||
VERSION_OUTPUT = os.path.join(OUTPUT_BASE, 'mdi_version.py')
|
||||
ICONSET_OUTPUT = os.path.join(OUTPUT_BASE, 'www_static', 'mdi.html')
|
||||
ICONSET_OUTPUT_GZ = os.path.join(OUTPUT_BASE, 'www_static', 'mdi.html.gz')
|
||||
|
||||
|
||||
def get_local_version():
|
||||
"""Parse the local version."""
|
||||
try:
|
||||
with open(VERSION_OUTPUT) as inp:
|
||||
for line in inp:
|
||||
match = CUR_VERSION.search(line)
|
||||
if match:
|
||||
return match.group(1)
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def get_remote_version():
|
||||
"""Get current version and download link."""
|
||||
gs_page = requests.get(GETTING_STARTED_URL).text
|
||||
@@ -43,10 +29,7 @@ def get_remote_version():
|
||||
print("Unable to find download link")
|
||||
sys.exit()
|
||||
|
||||
url = 'https://materialdesignicons.com' + mdi_download.group(1)
|
||||
version = mdi_download.group(2).replace('-', '')
|
||||
|
||||
return version, url
|
||||
return 'https://materialdesignicons.com' + mdi_download.group(1)
|
||||
|
||||
|
||||
def clean_component(source):
|
||||
@@ -54,7 +37,7 @@ def clean_component(source):
|
||||
return source[source.index(START_ICONSET):]
|
||||
|
||||
|
||||
def write_component(version, source):
|
||||
def write_component(source):
|
||||
"""Write component."""
|
||||
with open(ICONSET_OUTPUT, 'w') as outp:
|
||||
print('Writing icons to', ICONSET_OUTPUT)
|
||||
@@ -64,12 +47,6 @@ def write_component(version, source):
|
||||
print('Writing icons gz to', ICONSET_OUTPUT_GZ)
|
||||
outp.write(source.encode('utf-8'))
|
||||
|
||||
with open(VERSION_OUTPUT, 'w') as outp:
|
||||
print('Generating version file', VERSION_OUTPUT)
|
||||
outp.write(
|
||||
'"""DO NOT MODIFY. Auto-generated by update_mdi script."""\n')
|
||||
outp.write('VERSION = "{}"\n'.format(version))
|
||||
|
||||
|
||||
def main():
|
||||
"""Main section of the script."""
|
||||
@@ -79,19 +56,11 @@ def main():
|
||||
|
||||
print("materialdesignicons.com icon updater")
|
||||
|
||||
local_version = get_local_version()
|
||||
|
||||
# The remote version is not reliable.
|
||||
_, remote_url = get_remote_version()
|
||||
|
||||
remote_url = get_remote_version()
|
||||
source = clean_component(requests.get(remote_url).text)
|
||||
new_version = hashlib.md5(source.encode('utf-8')).hexdigest()
|
||||
write_component(source)
|
||||
fingerprint()
|
||||
|
||||
if local_version == new_version:
|
||||
print('Already on the latest version.')
|
||||
sys.exit()
|
||||
|
||||
write_component(new_version, source)
|
||||
print('Updated to latest version')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in new issue
Block a user