[bugzilla-gnome-org-extensions] Parse traces on comment display and format them prettily.



commit 1982722eb568ceb184912eeb798f6706b2fcfcf4
Author: Max Kanat-Alexander <mkanat everythingsolved com>
Date:   Tue Aug 4 01:50:59 2009 -0500

    Parse traces on comment display and format them prettily.

 code/bug-linkify_comment.pl                        |   30 +++++++++
 lib/TraceParser/Hooks.pm                           |   46 +++++++++++++
 lib/TraceParser/Trace.pm                           |   11 +++-
 template/en/default/trace/format.html.tmpl         |   67 ++++++++++++++++++++
 ...ror-errors.html => code-error-errors.html.tmpl} |    0
 .../en/global/header-additional_header.html.tmpl   |   23 +++++++
 web/style.css                                      |   35 ++++++++++
 7 files changed, 210 insertions(+), 2 deletions(-)
---
diff --git a/code/bug-linkify_comment.pl b/code/bug-linkify_comment.pl
new file mode 100644
index 0000000..1344659
--- /dev/null
+++ b/code/bug-linkify_comment.pl
@@ -0,0 +1,30 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Traceparser Plugin.
+#
+# The Initial Developer of the Original Code is Canonical Ltd.
+# Portions created by Canonical Ltd. are Copyright (C) 2009
+# Canonical Ltd. All Rights Reserved.
+#
+# Contributor(s):
+#   Max Kanat-Alexander <mkanat bugzilla org>
+
+
+use strict;
+use warnings;
+use Bugzilla;
+use Bugzilla::Error;
+use TraceParser::Trace;
+use TraceParser::Hooks;
+
+linkify_comment(%{ Bugzilla->hook_args });
diff --git a/lib/TraceParser/Hooks.pm b/lib/TraceParser/Hooks.pm
new file mode 100644
index 0000000..60e1e22
--- /dev/null
+++ b/lib/TraceParser/Hooks.pm
@@ -0,0 +1,46 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Canonical Ltd.
+# Portions created by the Initial Developer are Copyright (C) 2009
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s): 
+#   Max Kanat-Alexander <mkanat bugzilla org>
+
+package TraceParser::Hooks;
+use strict;
+use base qw(Exporter);
+use TraceParser::Trace;
+
+our @EXPORT = qw(
+    linkify_comment
+);
+
+sub linkify_comment {
+    my %params = @_;
+    my ($text, $bug_id, $match, $replace) = @params{qw(text bug_id match replace)};
+    my $trace = TraceParser::Trace->new_from_text($$text, $bug_id);
+    return if !$trace;
+    my $template = Bugzilla->template_inner;
+    my $match_text = quotemeta($trace->text);
+    push(@$match, qr/$match_text/s);
+    my $replacement;
+    $template->process('trace/format.html.tmpl', { trace => $trace },
+                       \$replacement)
+      || ThrowTemplateError($template->error);
+    push(@$replace, $replacement);
+}
+
+1;
diff --git a/lib/TraceParser/Trace.pm b/lib/TraceParser/Trace.pm
index 1652503..ae24244 100644
--- a/lib/TraceParser/Trace.pm
+++ b/lib/TraceParser/Trace.pm
@@ -48,6 +48,8 @@ use constant DB_COLUMNS => qw(
 
 use constant DB_TABLE => 'trace';
 
+use constant LIST_ORDER => 'bug_id';
+
 use constant VALIDATORS => {
     stack_hash  => \&_check_hash,
     short_hash  => \&_check_hash,
@@ -130,7 +132,12 @@ sub new_from_text {
     return undef if !$parsed;
     my $hash = md5_base64($parsed->text);
     my $traces = $class->match({ trace_hash => $hash, bug_id => $bug_id });
-    return $traces->[0];
+    if (@$traces) {
+        $traces->[0]->{stacktrace_object} = $parsed;
+        return $traces->[0];
+    }
+    warn "No trace found on bug $bug_id with hash $hash";
+    return undef;
 }
 
 ###############################
@@ -148,7 +155,7 @@ sub quality     { return $_[0]->{quality};     }
 sub stacktrace_object {
     my $self = shift;
     my $type = $self->type;
-    eval("use $type") || die $@;
+    eval("use $type; 1;") or die $@;
     $self->{stacktrace_object} ||= $type->parse({ text => $self->trace_text });
     return $self->{stacktrace_object};
 }
diff --git a/template/en/default/trace/format.html.tmpl b/template/en/default/trace/format.html.tmpl
new file mode 100644
index 0000000..ff1bcca
--- /dev/null
+++ b/template/en/default/trace/format.html.tmpl
@@ -0,0 +1,67 @@
+[%#
+  # The contents of this file are subject to the Mozilla Public
+  # License Version 1.1 (the "License"); you may not use this file
+  # except in compliance with the License. You may obtain a copy of
+  # the License at http://www.mozilla.org/MPL/
+  #
+  # Software distributed under the License is distributed on an "AS
+  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  # implied. See the License for the specific language governing
+  # rights and limitations under the License.
+  #
+  # The Original Code is the Bugzilla TraceParser Plugin.
+  #
+  # The Initial Developer of the Original Code is Canonical Ltd.
+  # Portions created by Canonical Ltd. are Copyright (C) 2009
+  # Canonical Ltd. All Rights Reserved.
+  #
+  # Contributor(s):
+  #   Max Kanat-Alexander <mkanat bugzilla org>
+  #%]
+
+</pre>
+<p class="trace_link" title="See Full Trace">
+  <a href="page.cgi?id=trace.html&id=[% trace.id FILTER url_quote %]">Trace 
+    [% trace.id FILTER html %]</a></p>
+<table border="0" cellpadding="0" cellspacing="0"><tr><td>
+<div class="trace">
+  [% IF trace.type.match('Python') %]
+    PYTHON TRACE
+  [% ELSE %]
+    [% SET st = trace.stacktrace_object %]
+    [% IF st.thread_with_crash %]
+      [% threads = [st.thread_with_crash] %]
+    [% ELSE %]
+      [% threads = st.threads %]
+    [% END %]
+    
+    [% FOREACH thread = threads %]
+      [% IF thread.number || thread.description %]
+        <p class="thread_start">Thread [% thread.number FILTER html %] 
+          ([% thread.description FILTER html %])</p>
+      [% END %]
+
+      <ul class="frames">
+        [% FOREACH frame = thread.frames %]
+          <li class="frame [% ' crash' IF frame.is_crash %]">
+            [% IF frame.number.defined %]
+              <span class="frame_number">#[% frame.number FILTER html %]</span>
+            [% END %]
+            <span class="frame_function">[% frame.function FILTER html %]</span>
+            [% IF frame.file %]
+              <div class="frame_file_container">
+                at <span class="frame_file">[% frame.file FILTER html %]</span>
+                [% IF frame.line %]
+                  line 
+                  <span class="frame_line">[% frame.line FILTER html %]</span>
+                [% END %]
+              </div>
+            [% END %]
+          </li>
+        [% END %]
+      </ul>
+    [% END %]
+  [% END %]
+</div>
+</td></tr></table>
+<pre>
diff --git a/template/en/global/code-error-errors.html b/template/en/global/code-error-errors.html.tmpl
similarity index 100%
rename from template/en/global/code-error-errors.html
rename to template/en/global/code-error-errors.html.tmpl
diff --git a/template/en/global/header-additional_header.html.tmpl 
b/template/en/global/header-additional_header.html.tmpl
new file mode 100644
index 0000000..124bc97
--- /dev/null
+++ b/template/en/global/header-additional_header.html.tmpl
@@ -0,0 +1,23 @@
+[%#
+  # The contents of this file are subject to the Mozilla Public
+  # License Version 1.1 (the "License"); you may not use this file
+  # except in compliance with the License. You may obtain a copy of
+  # the License at http://www.mozilla.org/MPL/
+  #
+  # Software distributed under the License is distributed on an "AS
+  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  # implied. See the License for the specific language governing
+  # rights and limitations under the License.
+  #
+  # The Original Code is the Bugzilla TraceParser Plugin.
+  #
+  # The Initial Developer of the Original Code is Canonical Ltd.
+  # Portions created by Canonical Ltd. are Copyright (C) 2009
+  # Canonical Ltd. All Rights Reserved.
+  #
+  # Contributor(s):
+  #   Max Kanat-Alexander <mkanat bugzilla org>
+  #%]
+
+<link rel="stylesheet" type="text/css" 
+      href="extensions/traceparser/web/style.css">
diff --git a/web/style.css b/web/style.css
new file mode 100644
index 0000000..dfe5620
--- /dev/null
+++ b/web/style.css
@@ -0,0 +1,35 @@
+.trace_link {
+    margin-bottom: .5em;
+    margin-top: -.5em;
+}
+
+.frames {
+  list-style-type: none;
+  margin: 0;
+  padding: 0;
+}
+
+.trace {
+  border: 1px dashed gray;
+  padding: .5em;
+}
+
+.frame {
+  margin-bottom: .25em;
+}
+
+.frame_function {
+  color: #c00;
+}
+
+.frame_file_container {
+  margin-left: 3em;
+}
+
+.frame_file {
+  font-style: italic;
+}
+
+.frame_line {
+  font-weight: bold;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]