]> git.ozlabs.org Git - hiprofile/commitdiff
Use jinja2 instead of django
authorJeremy Kerr <jk@ozlabs.org>
Fri, 17 Apr 2009 05:43:53 +0000 (15:43 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 17 Apr 2009 05:43:53 +0000 (15:43 +1000)
We only need a template engine, not the whole web application framework.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
hiprofile.py
scripts/hiprofile
setup.py
share/hiprofile/binary.html
share/hiprofile/report.html
share/hiprofile/symbol.html

index 212fbf13e76a32e8dd26fdbb650fd387df5edb12..c1d1052e2f7513f3f153963c7857f9bff398c343 100644 (file)
@@ -6,7 +6,7 @@ import shutil
 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
@@ -306,24 +306,27 @@ def write_report(report, resourcedir, outdir):
 
     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)
index aa1e361bb48f521e994657e5a100480c35e20464..f663cce8a11626750c075afe6400c4e927fbe819 100755 (executable)
@@ -2,8 +2,6 @@
 
 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__),
@@ -31,11 +29,6 @@ def main(args):
 
     (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)
index bf414147b43bb44d964c9331c5173e0dea01f7d0..f3bd3ff5e4a5e7cc0e30becbc1b9eb855eeb63f7 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,7 @@ setup(name = 'hiprofile',
         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/',
index 6e71cf77f45d0d02236961257b24e2e087592f0f..f94a7587112ad98ee674f90db11838a78701a701 100644 (file)
@@ -1,7 +1,7 @@
 {% extends "base.html" %}
 
 {% block heading %}
-Binary: {{ binary.shortname }}
+Binary: {{ binary.shortname() }}
 {% endblock %}
 
 {% block content %}
@@ -24,12 +24,12 @@ Binary: {{ binary.shortname }}
  </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>
index 0cd07c10e09ae292b73e1a41a2adfb18e58ceeab..c2fe2c33d1a4bac0f33380138dbde69f6131554d 100644 (file)
@@ -32,13 +32,13 @@ Oprofile report
  </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>
index e7765683fd3fed9431dc517d07c7fe643449578d..17b8cd96c859f20ea57b8abc2c07cacf2d4f51f4 100644 (file)
@@ -28,8 +28,8 @@
 {% 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 %}
@@ -37,7 +37,7 @@
 {% 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 %}