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
+try:
+ __version__ = __import__('pkg_resources') \
+ .get_distribution('hiprofile').version
+except Exception:
+ __version__ = 'unknown'
+
def _get_count(node):
""" Utility function: return the number in a 'count' element contained in
the current node"""
lambda r: r.count, thresholds['symbol'])
self.reference_dict = dict([ (r.name, r) for r in self.references ])
- def annotate(self, report, conn):
+ def annotate(self, report, conn, options):
fn_re = re.compile('^[0-9a-f]+\s+<[^>]+>: /\* (\S+) total:')
symbols = [ s for s in self.references if s.name != '(no symbols)' ]
if not symbols:
return
- command = ['opannotate', '--source', '--assembly',
+ command = [options.opannotate, '--source', '--assembly',
'--include-file=' + self.name,
'-i', ','.join([ s.name for s in symbols ])]
for binary in self.binaries:
binary.threshold(thresholds)
- def annotate(self, conn):
+ def annotate(self, conn, options):
for binary in self.binaries:
- binary.annotate(self, conn)
+ binary.annotate(self, conn, options)
@staticmethod
def parse(doc, hostname):
return report
@staticmethod
- def extract(connection):
- fd = connection.execute(['opreport', '--xml'])
+ def extract(connection, options):
+ fd = connection.execute([options.opreport, '--xml'])
doc = parseXML(fd)
if connection.host:
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(version = __version__,
+ 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(version = __version__,
+ report = report,
+ binary = binary) \
+ .dump(binaryfile)
+
+ for symbol in binary.references:
+ symbolfile = os.path.join(outdir, symbol.filename())
+ templates['symbol'].stream(version = __version__,
+ report = report, binary = binary,
+ symbol = symbol).dump(symbolfile)