We only need a template engine, not the whole web application framework.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
import os
import socket
from xml.dom.minidom import parse as parseXML
-from django.template.loader import render_to_string
+from jinja2 import Environment, FileSystemLoader
b_id = 0
s_id = 0
os.mkdir(outdir)
+ # set up template engine
+ env = Environment(loader = FileSystemLoader(resourcedir),
+ autoescape = True)
+ templates = {}
+ for name in ['report', 'binary', 'symbol']:
+ templates[name] = env.get_template('%s.html' % name)
+
# copy required files over
files = ['style.css', 'hiprofile.js', 'bar.png', 'jquery-1.3.1.min.js']
for file in files:
shutil.copy(os.path.join(resourcedir, file), outdir)
- f = open(os.path.join(outdir, 'index.html'), 'w')
- f.write(render_to_string('report.html', { 'report': report }))
- f.close()
+ reportfile = os.path.join(outdir, 'index.html')
+ templates['report'].stream(report = report).dump(reportfile)
for binary in report.binaries:
- f = open(os.path.join(outdir, binary.filename()), 'w')
- f.write(render_to_string('binary.html',
- { 'report': report, 'binary': binary }))
- f.close()
-
- for ref in binary.references:
- f = open(os.path.join(outdir, ref.filename()), 'w')
- f.write(render_to_string('symbol.html',
- { 'report': report, 'binary': binary, 'symbol': ref }))
- f.close()
-
+ binaryfile = os.path.join(outdir, binary.filename())
+ templates['binary'].stream(report = report, binary = binary). \
+ dump(binaryfile)
+
+ for symbol in binary.references:
+ symbolfile = os.path.join(outdir, symbol.filename())
+ templates['symbol'].stream(report = report, binary = binary,
+ symbol = symbol).dump(symbolfile)
import sys, os
from optparse import OptionParser
-from django.conf import settings
-
from hiprofile import Report, Connection, write_report
resourcedir = os.path.join(os.path.dirname(__file__),
(options, args) = parser.parse_args()
- # set up django template engine
- settings.configure(TEMPLATE_LOADERS =
- ('django.template.loaders.filesystem.load_template_source',),
- TEMPLATE_DIRS = (resourcedir,))
-
conn = Connection(options.host)
report = Report.extract(conn, options)
url = 'http://ozlabs.org/~jk/projects/hiprofile/',
author = 'Jeremy Kerr',
author_email = 'jk@ozlabs.org',
- requires = ['django'],
+ requires = ['jinja2'],
py_modules = ['hiprofile'],
scripts = ['scripts/hiprofile'],
data_files = [('share/hiprofile/',
{% extends "base.html" %}
{% block heading %}
-Binary: {{ binary.shortname }}
+Binary: {{ binary.shortname() }}
{% endblock %}
{% block content %}
</tr>
{% for symbol in binary.references %}
<tr>
- <td><a href="{{ symbol.filename }}">{{ symbol.name }}</a></td>
+ <td><a href="{{ symbol.filename() }}">{{ symbol.name }}</a></td>
<td>{{ symbol.count }}</td>
- <td>{{ symbol.percentage|floatformat:2 }}</td>
+ <td>{{ "%.2f"|format(symbol.percentage) }}</td>
<td><img src="bar.png" height="10"
- width="{% widthratio symbol.percentage 100 100 %}"
- alt="{{ symbol.percentage|floatformat:1 }}%"/></td>
+ width="{{ "%d"|format(symbol.percentage) }}"
+ alt="{{ "%.1f"|format(symbol.percentage) }}%"/></td>
</tr>
{% endfor %}
</table>
</tr>
{% for binary in report.binaries %}
<tr>
- <td><a href="{{binary.filename}}" title="{{ binary.name }}"
- >{{binary.shortname}}</a></td>
+ <td><a href="{{binary.filename()}}" title="{{ binary.name }}"
+ >{{binary.shortname()}}</a></td>
<td>{{ binary.count }}</td>
- <td>{{ binary.percentage|floatformat:2 }}</td>
+ <td>{{ "%.2f"|format(binary.percentage) }}</td>
<td><img src="bar.png" height="10"
- width="{% widthratio binary.percentage 100 100 %}"
- alt="{{ binary.percentage|floatformat:1 }}%"/></td>
+ width="{{ "%d"|format(binary.percentage) }}"
+ alt="{{ "%.1f"|format(binary.percentage) }}%"/></td>
</tr>
{% endfor %}
</table>
{% for insn in symbol.insns %}
<tr>
<td><span class="address">0x{{ insn.addr }}</span></td>
- <td style="color: {{insn.colour}}">{{ insn.samples }}</td>
- <td style="color: {{insn.colour}}">{{ insn.percentage|floatformat:2 }}</td>
+ <td style="color: {{insn.colour()}}">{{ insn.samples }}</td>
+ <td style="color: {{insn.colour()}}">{{ "%.2f"|format(insn.percentage) }}</td>
{% if insn.source %}
<td class="source-expander" onclick="expand_source(this);">+</td>
{% else %}
{% endif %}
<td>
<pre class="source">{{insn.source}}</pre>
- <pre class="assembly" style="color: {{insn.colour}}">{{ insn.asm }}</pre>
+ <pre class="assembly" style="color: {{insn.colour()}}">{{ insn.asm }}</pre>
</td>
</tr>
{% endfor %}