[Branch,~linaro-validation/lava-scheduler/trunk] Rev 252: [Milosz Wasilewski] show line numbers in log view

Message ID 20130807084043.29203.18636.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Antonio Terceiro Aug. 7, 2013, 8:40 a.m.
Merge authors:
  Milosz Wasilewski (mwasilew)
Related merge proposals:
  https://code.launchpad.net/~mwasilew/lava-scheduler/log_linenumbers/+merge/177597
  proposed by: Milosz Wasilewski (mwasilew)
  review: Needs Fixing - Antonio Terceiro (terceiro)
------------------------------------------------------------
revno: 252 [merge]
committer: Antonio Terceiro <antonio.terceiro@linaro.org>
branch nick: trunk
timestamp: Wed 2013-08-07 10:38:35 +0200
message:
  [Milosz Wasilewski] show line numbers in log view
added:
  lava_scheduler_app/templatetags/
  lava_scheduler_app/templatetags/__init__.py
  lava_scheduler_app/templatetags/linenumbers.py
modified:
  lava_scheduler_app/static/lava_scheduler_app/css/logfile.css
  lava_scheduler_app/templates/lava_scheduler_app/job_log_file.html


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription

Patch

=== modified file 'lava_scheduler_app/static/lava_scheduler_app/css/logfile.css'
--- lava_scheduler_app/static/lava_scheduler_app/css/logfile.css	2011-12-13 04:22:40 +0000
+++ lava_scheduler_app/static/lava_scheduler_app/css/logfile.css	2013-07-30 10:15:36 +0000
@@ -24,3 +24,13 @@ 
     border-width: medium;
 }
 
+.line 
+{
+    line-height: 18px;
+    white-space: nowrap;
+}
+
+div:target 
+{
+    background-color: rgb(255, 128, 128);
+}

=== modified file 'lava_scheduler_app/templates/lava_scheduler_app/job_log_file.html'
--- lava_scheduler_app/templates/lava_scheduler_app/job_log_file.html	2012-03-19 23:44:40 +0000
+++ lava_scheduler_app/templates/lava_scheduler_app/job_log_file.html	2013-07-30 10:15:36 +0000
@@ -6,6 +6,7 @@ 
 {% endblock %}
 
 {% block content %}
+{% load linenumbers %}
 <h2>Dispatcher log file - {{ job.id }} </h1>
 <a href="{% url lava.scheduler.job.log_file.plain job.pk %}">Download as text file</a>
 
@@ -15,7 +16,7 @@ 
 {% if section.0 == 'console' and section.1 > 20 and not forloop.last %}
 <a href="#entry{{ forloop.counter }}">skip {{ section.1 }} lines to next log entry &rarr;</a>
 {% endif %}
-<pre class="log_{{ section.0 }}">{{ section.2 }}</pre>
+{% linenumbers section.2 forloop.counter0 section.0 %}
 {% endfor %}
 {% if job.status == job.RUNNING %}
 <img id="progress" src="{{ STATIC_URL }}lava_scheduler_app/images/ajax-progress.gif"/>

=== added directory 'lava_scheduler_app/templatetags'
=== added file 'lava_scheduler_app/templatetags/__init__.py'
=== added file 'lava_scheduler_app/templatetags/linenumbers.py'
--- lava_scheduler_app/templatetags/linenumbers.py	1970-01-01 00:00:00 +0000
+++ lava_scheduler_app/templatetags/linenumbers.py	2013-07-30 10:15:36 +0000
@@ -0,0 +1,45 @@ 
+from django import template
+from django.db.models import fields
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
+
+register = template.Library()
+
+class LineNumbers(template.Node):
+    def __init__(self, text, prefix, style):
+        self.text = template.Variable(text)
+        self.prefix = template.Variable(prefix)
+        self.style = template.Variable(style)
+
+    def render(self, context):
+        text = self.text.resolve(context)
+        prefix = self.prefix.resolve(context)
+        style = self.style.resolve(context)
+        ret = "<table><tr><td>"
+        for i in range(0, len(text.splitlines())):
+            name = "L_%s_%s" % (prefix, i)
+            display = "Section %s.%s" % (prefix, i)
+            ret += "<div class=\"line\"><a name=\"%s\"></a> \
+                <a href=\"#%s\">%s</a></div>" % (name, name, display)
+
+        ret += "</td><td class=\"code\"><div class=\"containter\"> \
+            <pre class=\"log_%s\">" % (style)
+
+        for index, line in enumerate(text.splitlines()):
+            ret += "<div id=\"L_%s_%s\" class=\"line\"> &nbsp;%s</div>" % \
+                (prefix,
+                 index,
+                 mark_safe(escape(line).encode('ascii', 'xmlcharrefreplace')))
+
+        ret += "</pre></div></td><tr></table>"
+
+        return ret
+
+@register.tag('linenumbers')
+def do_linenumbers(parser, token):
+    try:
+        tag_name, text, prefix, style = token.split_contents()
+    except ValueError:
+        raise template.TemplateSyntaxError("%r tag requires 3 arguments" % \
+            token.contents.split()[0])
+    return LineNumbers(text, prefix, style)