Frontend: Add materialdesignicons
This commit is contained in:
parent
72b4212b19
commit
77f4fc8c22
5 changed files with 98 additions and 2 deletions
|
@ -8,7 +8,7 @@ import re
|
|||
import os
|
||||
import logging
|
||||
|
||||
from . import version
|
||||
from . import version, mdi_version
|
||||
import homeassistant.util as util
|
||||
from homeassistant.const import URL_ROOT, HTTP_OK
|
||||
from homeassistant.config import get_default_config_dir
|
||||
|
@ -74,6 +74,7 @@ def _handle_get_root(handler, path_match, data):
|
|||
|
||||
template_html = template_html.replace('{{ app_url }}', app_url)
|
||||
template_html = template_html.replace('{{ auth }}', auth)
|
||||
template_html = template_html.replace('{{ icons }}', mdi_version.VERSION)
|
||||
|
||||
handler.wfile.write(template_html.encode("UTF-8"))
|
||||
|
||||
|
|
|
@ -46,6 +46,6 @@
|
|||
</div>
|
||||
<script src='/static/webcomponents-lite.min.js'></script>
|
||||
<link rel='import' href='/static/{{ app_url }}' />
|
||||
<home-assistant auth='{{ auth }}'></home-assistant>
|
||||
<home-assistant auth='{{ auth }}' icons='{{ icons }}'></home-assistant>
|
||||
</body>
|
||||
</html>
|
||||
|
|
2
homeassistant/components/frontend/mdi_version.py
Normal file
2
homeassistant/components/frontend/mdi_version.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
""" DO NOT MODIFY. Auto-generated by update_mdi script """
|
||||
VERSION = "38EF63D0474411E4B3CF842B2B6CFE1B"
|
1
homeassistant/components/frontend/www_static/mdi.html
Normal file
1
homeassistant/components/frontend/www_static/mdi.html
Normal file
File diff suppressed because one or more lines are too long
92
script/update_mdi.py
Executable file
92
script/update_mdi.py
Executable file
|
@ -0,0 +1,92 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Downloads the latest Polymer v1 iconset version for materialdesignicons.com
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
import sys
|
||||
|
||||
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')
|
||||
|
||||
|
||||
def get_local_version():
|
||||
""" Parse 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
|
||||
|
||||
mdi_download = re.search(DOWNLOAD_LINK, gs_page)
|
||||
|
||||
if not mdi_download:
|
||||
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
|
||||
|
||||
|
||||
def clean_component(source):
|
||||
""" Clean component. """
|
||||
return source[source.index(START_ICONSET):]
|
||||
|
||||
|
||||
def write_component(version, source):
|
||||
""" Write component. """
|
||||
with open(ICONSET_OUTPUT, 'w') as outp:
|
||||
print('Writing icons to', ICONSET_OUTPUT)
|
||||
outp.write(source)
|
||||
|
||||
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():
|
||||
# All scripts should have their current work dir set to project root
|
||||
if os.path.basename(os.getcwd()) == 'script':
|
||||
os.chdir('..')
|
||||
|
||||
print("materialdesignicons.com icon updater")
|
||||
|
||||
local_version = get_local_version()
|
||||
remote_version, remote_url = get_remote_version()
|
||||
|
||||
print('Local version:', local_version)
|
||||
print('Remote version:', remote_version)
|
||||
|
||||
if local_version == remote_version:
|
||||
print('Already on the latest version.')
|
||||
sys.exit()
|
||||
|
||||
write_component(remote_version,
|
||||
clean_component(requests.get(remote_url).text))
|
||||
print('Updated to latest version')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue