Source

check_os / view.py

Full commit
import os
import tempfile
import webbrowser
from mako.template import Template

HTML = 'osinfo.html'
TEMPLATE = '''<html>
<head><title>OS Check Result</title></head>
<body>

% if res.result == 'OK':
    <b style="font-size:96px; color:green">${res.result}</b>
% elif res.result == 'NG':
    <b style="font-size:96px; color:red">${res.result}</b>
% else:
    <b style="font-size:96px; color:black">${res.result}</b>
% endif
<br>

% if res.msg:
    % for m in res.msg:
        <b>${m}</b><br>
    % endfor
% endif

% if res.po:
    <b>PO:</b> ${res.po}<br>
% endif

<hr>

% if res.os_type_str:
    <b>Installed OS:</b> ${res.os_type_str}
% endif

<br>

% if res.sdr_type_str:
    <b>Required OS:</b> ${res.sdr_type_str}
% endif

<hr>

% if len(res.os_langs_str()) > 1:
    <b>Installed languages:</b>
    <br>
    <ul>
    % for lang in res.os_langs_str():
        <li>${lang}</li>
    % endfor
    </ul>
% else:
    <b>Installed language: </b>${res.os_lang_str()}
    <br>
% endif

% if len(res.sdr_langs_str()) > 1:
    <b>Required languages:</b><br>
    <ul>
    % for lang in res.sdr_langs_str():
        <li>${lang}</li>
    % endfor
    </ul>
% else:
    <b>Required language: </b>${res.sdr_lang_str()}
    <br>
% endif
</body></html>'''

def display(res):
    "Display results in a web browser."
    tmpdir = tempfile.mkdtemp()
    html = os.path.join(tmpdir, HTML)
    templ = Template(TEMPLATE)
    
    with open(html, 'w') as f:
        f.write(templ.render(res=res))
    webbrowser.open(html)