[Reports] Get rid of Mako in reports, finally
This transforms the last Mako template into Jinja2 markup and completely removes Mako support. This is the final step of switching to usage of Jinja2. Change-Id: I8b0ebe291e92f566d947d0e3e56614270e56c113
This commit is contained in:
parent
70901577ab
commit
f985fc2201
@ -1,9 +1,8 @@
|
||||
## -*- coding: utf-8 -*-
|
||||
<%inherit file="/base.mako"/>
|
||||
{% extends "/base.html" %}
|
||||
|
||||
<%block name="title_text">Performance job results</%block>
|
||||
{% block title_text %}Performance job results{% endblock %}
|
||||
|
||||
<%block name="js_after">
|
||||
{% block js_after %}
|
||||
function checkLink (elem) {
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('GET', elem.href, true);
|
||||
@ -22,29 +21,27 @@
|
||||
for(var i=0; i<elems.length; i++){
|
||||
checkLink(elems[i]);
|
||||
}
|
||||
</%block>
|
||||
{% endblock %}
|
||||
|
||||
<%block name="css">
|
||||
{% block css %}
|
||||
li { margin:2px 0 }
|
||||
a, a:visited { color:#039 }
|
||||
code { padding:0 5px; color:#888 }
|
||||
.columns li { position:relative }
|
||||
.columns li > :first-child { display:block }
|
||||
.columns li > :nth-child(2) { display:block; position:static; left:165px; top:0; white-space:nowrap }
|
||||
</%block>
|
||||
{% endblock %}
|
||||
|
||||
<%block name="css_content_wrap">margin:0 auto; padding:0 5px</%block>
|
||||
|
||||
<%block name="media_queries">
|
||||
{% block media_queries %}
|
||||
@media only screen and (min-width: 320px) { .content-wrap { width:400px } }
|
||||
@media only screen and (min-width: 520px) { .content-wrap { width:500px } }
|
||||
@media only screen and (min-width: 620px) { .content-wrap { width:90% } .columns li > :nth-child(2) { position:absolute } }
|
||||
@media only screen and (min-width: 720px) { .content-wrap { width:70% } }
|
||||
</%block>
|
||||
{% endblock %}
|
||||
|
||||
<%block name="header_text">performance job results</%block>
|
||||
{% block header_text %}performance job results{% endblock %}
|
||||
|
||||
<%block name="content">
|
||||
{% block content %}
|
||||
<h2>Logs and files</h2>
|
||||
<ul class="columns">
|
||||
<li><a href="console.html" class="rich check-gz">Benchmarking logs</a> <code>console.html</code>
|
||||
@ -79,4 +76,4 @@
|
||||
<li>Unzip plugins and put to <code>.rally/plugins/</code> directory</li>
|
||||
<li>Run rally task: <code>$ rally task start task.txt</code></li>
|
||||
</ol>
|
||||
</%block>
|
||||
{% endblock %}
|
@ -13,18 +13,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os.path
|
||||
import jinja2
|
||||
|
||||
|
||||
def get_mako_template(template):
|
||||
import mako.lookup
|
||||
dirs = os.path.join(os.path.dirname(__file__), "templates")
|
||||
lookup = mako.lookup.TemplateLookup(directories=[dirs])
|
||||
return lookup.get_template(template)
|
||||
|
||||
|
||||
def get_jinja_template(template):
|
||||
import jinja2
|
||||
def get_template(template):
|
||||
|
||||
def include_raw_file(file_name):
|
||||
try:
|
||||
@ -38,9 +30,3 @@ def get_jinja_template(template):
|
||||
env.globals["include_raw_file"] = include_raw_file
|
||||
|
||||
return env.get_template(template)
|
||||
|
||||
|
||||
def get_template(template):
|
||||
if template.endswith(".mako"):
|
||||
return get_mako_template(template)
|
||||
return get_jinja_template(template)
|
||||
|
@ -109,7 +109,7 @@ python $BASE/new/rally/tests/ci/osresources.py\
|
||||
rally -v --rally-debug task start --task $TASK $TASK_ARGS
|
||||
|
||||
mkdir -p rally-plot/extra
|
||||
python $BASE/new/rally/tests/ci/render.py ci/index.mako > rally-plot/extra/index.html
|
||||
python $BASE/new/rally/tests/ci/render.py ci/index.html > rally-plot/extra/index.html
|
||||
cp $TASK rally-plot/task.txt
|
||||
tar -czf rally-plot/plugins.tar.gz -C $RALLY_PLUGINS_DIR .
|
||||
rally task results | python -m json.tool > rally-plot/results.json
|
||||
|
@ -22,7 +22,7 @@ from rally.ui import utils
|
||||
|
||||
HELP_MESSAGE = (
|
||||
"Usage:\n\t"
|
||||
"render.py ci/template.mako"
|
||||
"render.py ci/template.html"
|
||||
"[<key-1>=<value-1> <key-2>=<value-2> ...]\n\n\t"
|
||||
"Where key-1,value-1 and key-2,value-2 are key pairs of template.")
|
||||
|
||||
|
@ -180,7 +180,7 @@ def main():
|
||||
else:
|
||||
print("Ignoring file %s" % fname)
|
||||
print("Exit statuses: %r" % statuses)
|
||||
template = utils.get_template("ci/index.mako")
|
||||
template = utils.get_template("ci/index.html")
|
||||
with open("rally-plot/extra/index.html", "w") as output:
|
||||
output.write(template.render())
|
||||
return any(statuses)
|
||||
|
@ -14,7 +14,6 @@
|
||||
# under the License.
|
||||
|
||||
import jinja2
|
||||
import mock
|
||||
|
||||
from rally.ui import utils
|
||||
from tests.unit import test
|
||||
@ -22,35 +21,13 @@ from tests.unit import test
|
||||
|
||||
class ModuleTestCase(test.TestCase):
|
||||
|
||||
def test_get_mako_template(self):
|
||||
try:
|
||||
import mako
|
||||
except ImportError:
|
||||
self.skip("No mako module. Skipping test.")
|
||||
template = utils.get_mako_template("ci/index.mako")
|
||||
self.assertIsInstance(template, mako.template.Template)
|
||||
|
||||
def test_get_jinja_template(self):
|
||||
template = utils.get_jinja_template("base.html")
|
||||
def test_get_template(self):
|
||||
template = utils.get_template("base.html")
|
||||
self.assertIsInstance(template,
|
||||
jinja2.environment.Template)
|
||||
self.assertEqual("base.html", template.name)
|
||||
self.assertIn("include_raw_file", template.globals)
|
||||
|
||||
def test_get_jinja_template_raises(self):
|
||||
def test_get_template_raises(self):
|
||||
self.assertRaises(jinja2.exceptions.TemplateNotFound,
|
||||
utils.get_jinja_template, "nonexistent")
|
||||
|
||||
@mock.patch("rally.ui.utils.get_mako_template")
|
||||
def test_get_template_mako(self, mock_get_mako_template):
|
||||
mock_get_mako_template.return_value = "fake_template"
|
||||
template = utils.get_template("template.mako")
|
||||
self.assertEqual("fake_template", template)
|
||||
mock_get_mako_template.assert_called_once_with("template.mako")
|
||||
|
||||
@mock.patch("rally.ui.utils.get_jinja_template")
|
||||
def test_get_template_jinja(self, mock_get_jinja_template):
|
||||
mock_get_jinja_template.return_value = "fake_template"
|
||||
template = utils.get_template("template.html")
|
||||
self.assertEqual("fake_template", template)
|
||||
mock_get_jinja_template.assert_called_once_with("template.html")
|
||||
utils.get_template, "nonexistent")
|
||||
|
Loading…
x
Reference in New Issue
Block a user