You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2008/02/26 12:43:55 UTC

svn commit: r631183 - in /spamassassin/trunk: build/mkrules masses/rule-qa/automc/ruleqa.cgi

Author: jm
Date: Tue Feb 26 03:43:44 2008
New Revision: 631183

URL: http://svn.apache.org/viewvc?rev=631183&view=rev
Log:
add metadata about all rules, not just rulesrc sandbox ones, to rulemetadata.xml files for ruleQA system; little bit of UI cleanup in ruleqa.cgi

Modified:
    spamassassin/trunk/build/mkrules
    spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi

Modified: spamassassin/trunk/build/mkrules
URL: http://svn.apache.org/viewvc/spamassassin/trunk/build/mkrules?rev=631183&r1=631182&r2=631183&view=diff
==============================================================================
--- spamassassin/trunk/build/mkrules (original)
+++ spamassassin/trunk/build/mkrules Tue Feb 26 03:43:44 2008
@@ -452,7 +452,6 @@
       $rules->{$name}->{origname} = $origname;
       $rules->{$name}->{cond} ||= $current_conditional;
       $rules->{$name}->{text} .= $current_comments . $orig;
-      $rules->{$name}->{srcfile} = $f;
 
       # note if the conditional is a plugin reference, as we need to
       # ensure that "loadplugin" lines stay in the same place
@@ -465,6 +464,7 @@
       # have its descriptions/scores/etc. published in "active".
       if ($type =~ /^${RULE_DEFINE_KEYWORDS_RE}$/x) {
         $rules->{$name}->{found_definition} = 1;
+        $rules->{$name}->{srcfile} = $f;
         $rules->{$name}->{code} = $orig;
       }
       elsif ($type eq 'tflags') {
@@ -686,15 +686,27 @@
       $lang = $1;
     }
 
-    # right now, we only read tflags from output files
-    if (/^tflags\s+(\S+)\s+(.*)$/) {
-      my $name = $1;
-      my $val = $2;
-      $val =~ s/\s+/ /gs;
-      if ($rules->{$name}->{tflags}) {
-        $rules->{$name}->{tflags} .= ' '.$val;
-      } else {
-        $rules->{$name}->{tflags} = $val;
+    if (/^(${RULE_KEYWORDS_RE})\s+(\S+)\s+(.*)$/) {
+      # rule definitions
+      my $type = $1;
+      my $name = $2;
+      my $val = $3;
+
+      # note: we only want to do this if --rulemetadata is in use!
+      if (!$rules->{$name}) { $rules->{$name} = rule_entry_create(); }
+
+      if ($type eq 'tflags') {
+        $val =~ s/\s+/ /gs;
+        if ($rules->{$name}->{tflags}) {
+          $rules->{$name}->{tflags} .= ' '.$val;
+        } else {
+          $rules->{$name}->{tflags} = $val;
+        }
+      }
+
+      if ($type =~ /^${RULE_DEFINE_KEYWORDS_RE}$/x) {
+        $rules->{$name}->{srcfile} = $file;
+        $rules->{$name}->{code} = $orig;
       }
     }
   }
@@ -884,13 +896,13 @@
 
   # output the known rules that are not meta subrules.
   foreach my $rule (@rulenames) {
-    next if ($rule =~ /^__/);
+    $rulemd .= get_rulemetadata_string($rule);      # all metadata strings
 
+    next if ($rule =~ /^__/);
     my $pubfile = $rules->{$rule}->{output_file};
     my $text    = $rules->{$rule}->{output_text};
     next unless defined ($text);
 
-    $rulemd .= get_rulemetadata_string($rule);
     $output_file_text->{$pubfile} .= "##{ $rule\n".
                             $text.
                             "##} ".$rule."\n\n";
@@ -902,7 +914,6 @@
     my $pubfile = $rules->{$rule}->{output_file};
     my $text    = $rules->{$rule}->{output_text};
     next unless defined ($text);
-    $rulemd .= get_rulemetadata_string($rule);
     $output_file_text->{$pubfile} .= $text;
   }
 
@@ -928,20 +939,27 @@
   my $mod = 0;
   my $srcfile = '';
   my $code = '';
+  my $name = $rule;
 
-  if ($rules->{$rule}->{found_definition}) {
-    $srcfile = $rules->{$rule}->{srcfile} || '';
+  # if we found a rule definition with a T_ prefix, use that data
+  if (!$rules->{$name}->{srcfile} && $rules->{"T_".$name}->{srcfile}) {
+    $name = "T_".$name;
+  }
+
+  if ($rules->{$name}->{srcfile}) {
+    $srcfile = $rules->{$name}->{srcfile};
     if ($srcfile) {
       my @s = stat $srcfile;
-      if (@s) {
-        $mod = $s[9];
-      }
+      if (@s) { $mod = $s[9]; }
     }
-    $code = $rules->{$rule}->{code} || '';
+  }
+
+  if ($rules->{$name}->{code}) {
+    $code = $rules->{$name}->{code};
     $code =~ s/\]\]>/\](defanged by mkrules)\]>/gs;     # ensure it's CDATA-safe
   }
 
-  my $tf = $rules->{$rule}->{tflags} || '';
+  my $tf = $rules->{$name}->{tflags} || '';
 
   return "<rulemetadata>".
             "<name>$rule</name>".

Modified: spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi
URL: http://svn.apache.org/viewvc/spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi?rev=631183&r1=631182&r2=631183&view=diff
==============================================================================
--- spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi (original)
+++ spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi Tue Feb 26 03:43:44 2008
@@ -974,8 +974,7 @@
       <th>RANK</th>
       <th>SCORE</th>
       <th>NAME</th>
-      <th>WHO</th>
-      <th>AGE</th>
+      <th>WHO/AGE</th>
     </tr>
 
   };
@@ -1054,7 +1053,7 @@
     else {
       $comment .= $self->rule_anchor($key,$rule);
       $comment .= "
-      <tr><td colspan=9>
+      <tr><td colspan=8>
         (no data found)
       </td></tr>
       ";
@@ -1094,8 +1093,7 @@
     <td>[% RANK %]</td>
     <td>[% SCORE %]</td>
     <td style='text-align: left'><a href="[% NAMEREF %]">[% NAME %]</a></td>
-    <td>[% USERNAME %]</td>
-    <td>[% AGE %]</td>
+    <td>[% USERNAME %][% AGE %]</td>
     <!--
       <rule><test>[% NAME %]</test><promo>[% PROMO %]</promo> <spc>[% SPAMPC %]</spc><hpc>[% HAMPC %]</hpc><so>[% SO %]</so> <detailhref esc='1'>[% NAMEREFENCD %]</detailhref></rule>
     -->
@@ -1106,7 +1104,7 @@
   $FREQS_LINE_TEXT_TEMPLATE =
        qq{[% MSECS %]  [% SPAMPC %]  [% HAMPC %]  }.
        qq{[% SO %]  [% RANK %]  [% SCORE %]  }.
-       qq{[% NAME %] [% USERNAME %] [% AGE %] }.
+       qq{[% NAME %] [% USERNAME %][% AGE %] }.
        "\n";
 
   $FREQS_EXTRA_TEMPLATE = qq{