On Sun, 2008-11-30 at 11:29 +0000, Adam D. Barratt wrote: > Ideally, the description formatting should probably be in the output > modules themselves. The main reason I didn't do that is that having > tried several times I was unable to call > Read_taginfo::format_tag_description from Output/LetterQualifier.pm.
Attached is a much updated patch, for your demol^H^H^H^H^Hcomments. The formatting work is now performed directly in the output class, so each module can format the description as it wishes (or doesn't, as the case may be). > I'm probably missing something obvious but after use()ing or > require()ing Read_taginfo from the output module, attempting to call it > always results in an "undefined subroutine > &Read_taginfo::format_tag_description" error. Apparently I was missing something obvious *sigh*. Adam
diff --git a/debian/changelog b/debian/changelog index 3e8df01..ea0c872 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,19 +12,37 @@ lintian (2.1.1) unstable; urgency=low better match executions of the command rather than the use of its name in pattern matching expressions. (Closes: #499847) + * frontend/lintian: + + [ADB] Don't call lintian-info when --info is specified. Set a new + flag on the Lintian::Output module instead. + * frontend/lintian-info: + + [ADB] Add missing "use Text_Utils". It used to be indirectly pulled + in via Read_taginfo. + + * lib/Lintian/Output{.pm,/*.pm}: + + [ADB] Flag a tag as issued when printing it. * lib/Lintian/Output.pm: + [ADB] Make sure the default list of colours is initialised before attempting to use it. Thanks, gregor herrmann. (Closes: #507241) + + [ADB] Maintain a list of tags which have been issued. + + [ADB] Optionally include the description of a tag when displaying it. * lib/Lintian/Output/ColonSeparated.pm: + [ADB] Fix uninitialized value warnings by displaying the type code rather than the (no longer present in description files) Type field and handling non-overriden tags. + * lib/Lintian/Output/LetterQualifier.pm: + + [ADB] Optionally include the description of a tag when displaying it. * lib/Lintian/Output/XML.pm: + [ADB] Add a missing angle bracket to the closing "tag" tag, so that the XML is well-formed. * lib/Lab.pm: + [FL] Fix breakage of populate_with_dist() I introduced in 2.1.0. + * lib/Read_taginfo.pm: + + [ADB] Move the work of formatting a tag's description to a separate + function so that it can be called from multiple locations. + + [ADB] Properly export those functions which are called from other + modules. * lib/Spelling.pm: + [RA] Don't add unnecessary backslashes in the list of spelling corrections. They're copied into the output. Thanks, Micah @@ -32,6 +50,13 @@ lintian (2.1.1) unstable; urgency=low * lib/Tags.pm: + [ADB] Don't output a "Processing binary package foo.changes" message. Thanks Sandro Tosi for pointing the issue out. + * lib/Text_utils.pm: + + [ADB] Properly export those functions which are called from other + modules. + + * reporting/html_reports: + + [ADB] Add missing "use Text_Utils". It used to be indirectly pulled + in via Read_taginfo. -- Adam D. Barratt <[EMAIL PROTECTED]> Fri, 28 Nov 2008 21:47:33 +0000 diff --git a/frontend/lintian b/frontend/lintian index fe9a823..529ca27 100755 --- a/frontend/lintian +++ b/frontend/lintian @@ -29,7 +29,6 @@ use FileHandle; # }}} # {{{ Global Variables -my $lintian_info_cmd = 'lintian-info'; #Command to run for ? my $LINTIAN_VERSION = "<VERSION>"; #External Version number my $BANNER = "Lintian v$LINTIAN_VERSION"; #Version Banner - text form my $LAB_FORMAT = 8; #Lab format Version Number @@ -473,10 +472,6 @@ if (defined $LINTIAN_ROOT) { unless ($LINTIAN_ROOT =~ m,^/,) { $LINTIAN_ROOT = "$cwd/$LINTIAN_ROOT"; } - # see if it has a frontend directory - if (-d "$LINTIAN_ROOT/frontend") { - $lintian_info_cmd = "$LINTIAN_ROOT/frontend/lintian-info"; - } } else { $LINTIAN_ROOT = '/usr/share/lintian'; } @@ -663,6 +658,7 @@ $Lintian::Output::GLOBAL->verbose($verbose); $Lintian::Output::GLOBAL->debug($debug); $Lintian::Output::GLOBAL->quiet($quiet); $Lintian::Output::GLOBAL->color($color); +$Lintian::Output::GLOBAL->showdescription($lintian_info); # Print Debug banner, now that we're finished determining # the values and have Lintian::Output available @@ -747,29 +743,6 @@ $LINTIAN_LAB = $LAB->{dir}; # }}} -# {{{ Setup the lintian-info pipe - -# pipe output through lintian-info? -# note: if any E:/W: lines are added above this point, this block needs to -# be moved up -if ($lintian_info) { - open(OUTPUT_PIPE, '|-', $lintian_info_cmd) or fail("cannot open output pipe to $lintian_info_cmd: $!"); - $Lintian::Output::GLOBAL->stdout(\*OUTPUT_PIPE); -} - -# Close the OUTPUT_PIPE in an END block so that we can ensure that -# lintian-info exits before we do. Otherwise, we may get output from -# lintian-info after lintian exits, which can confuse the shell output. -END { - if ($lintian_info) { - my $status = $?; - close OUTPUT_PIPE; - $Lintian::Output::GLOBAL->stdout(\*STDOUT); - $? = $status; - } -} -# }}} - # {{{ Compile list of files to process $schedule = new Lintian::Schedule(verbose => $verbose); diff --git a/frontend/lintian-info b/frontend/lintian-info index 7d6cb8d..80d6ae9 100755 --- a/frontend/lintian-info +++ b/frontend/lintian-info @@ -37,6 +37,7 @@ BEGIN { # import perl libraries use lib "$ENV{'LINTIAN_ROOT'}/lib"; use Read_taginfo; +use Text_utils; my %already_displayed = (); diff --git a/lib/Lintian/Output.pm b/lib/Lintian/Output.pm index 02beb03..c80fbd7 100644 --- a/lib/Lintian/Output.pm +++ b/lib/Lintian/Output.pm @@ -62,6 +62,7 @@ $Lintian::Output::GLOBAL unless their first argument C<isa('Lintian::Output')>. # support for ANSI color output via colored() use Term::ANSIColor (); use Tags (); +use Read_taginfo qw(format_tag_description); =head1 ACCESSORS @@ -103,7 +104,8 @@ I/O handle to use for warnings. Defaults to C<\*STDERR>. =cut use base qw(Class::Accessor Exporter); -Lintian::Output->mk_accessors(qw(verbose debug quiet color colors stdout stderr)); +Lintian::Output->mk_accessors(qw(verbose debug quiet color colors stdout + stderr showdescription issuedtags)); our @EXPORT = (); our %EXPORT_TAGS = ( messages => [qw(msg v_msg warning debug_msg delimiter)], @@ -126,6 +128,7 @@ sub new { $self->stdout(\*STDOUT); $self->stderr(\*STDERR); $self->colors({%default_colors}); + $self->issuedtags({}); return $self; } @@ -209,6 +212,19 @@ sub delimiter { return $self->_delimiter; } +=item C<issued_tag($tag_name)> + +Indicate that the named tag has been issued. Returns a boolean value +indicating whether the tag had previously been issued by the object. + +=cut + +sub issued_tag { + my ($self, $tag_name) = _global_or_object(@_); + + return $self->issuedtags->{$tag_name}++ ? 1 : 0; +} + =item C<string($lead, @args)> TODO: Is this part of the public interface? @@ -269,6 +285,11 @@ sub print_tag { } $self->_print('', "$code: $pkg_info->{pkg}$type", "$tag$extra"); + if (!$self->issued_tag($tag_info->{tag}) and $self->showdescription) { + $self->_print('', 'N', ''); + $self->_print('', 'N', split("\n", format_tag_description($tag_info, 3))); + $self->_print('', 'N', ''); + } } =item C<print_start_pkg($pkg_info)> diff --git a/lib/Lintian/Output/ColonSeparated.pm b/lib/Lintian/Output/ColonSeparated.pm index 8bce0a6..2d58ca2 100644 --- a/lib/Lintian/Output/ColonSeparated.pm +++ b/lib/Lintian/Output/ColonSeparated.pm @@ -31,6 +31,7 @@ sub print_tag { my $extra = "@$information"; + $self->issued_tag($tag_info->{tag}); $self->_print( 'tag', Tags::get_tag_code($tag_info), diff --git a/lib/Lintian/Output/LetterQualifier.pm b/lib/Lintian/Output/LetterQualifier.pm index eaffc42..563e0b3 100644 --- a/lib/Lintian/Output/LetterQualifier.pm +++ b/lib/Lintian/Output/LetterQualifier.pm @@ -21,6 +21,7 @@ package Lintian::Output::LetterQualifier; use strict; use warnings; +use Read_taginfo qw(format_tag_description); use Term::ANSIColor qw(colored); use Tags (); @@ -118,6 +119,11 @@ sub print_tag { } $self->_print('', "$code\[$lq\]: $pkg$type", "$tag$extra"); + if (!$self->issued_tag($tag_info->{tag}) and $self->showdescription) { + $self->_print('', 'N', ''); + $self->_print('', 'N', split("\n", format_tag_description($tag_info, 3))); + $self->_print('', 'N', ''); + } } 1; diff --git a/lib/Lintian/Output/XML.pm b/lib/Lintian/Output/XML.pm index e86f81d..0041e53 100644 --- a/lib/Lintian/Output/XML.pm +++ b/lib/Lintian/Output/XML.pm @@ -28,6 +28,7 @@ use base qw(Lintian::Output); sub print_tag { my ($self, $pkg_info, $tag_info, $information) = @_; + $self->issued_tag($tag_info->{tag}); $self->_print_xml('', qq{<tag severity="$tag_info->{severity}" certainty="$tag_info->{certainty}"}, 'flags="'.(exists($tag_info->{experimental}) ? 'experimental' : ''), diff --git a/lib/Read_taginfo.pm b/lib/Read_taginfo.pm index dbcd464..0aaa6c7 100644 --- a/lib/Read_taginfo.pm +++ b/lib/Read_taginfo.pm @@ -19,6 +19,12 @@ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301, USA. +package Read_taginfo; + +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(read_tag_info format_tag_description); + my $LINTIAN_ROOT = $ENV{'LINTIAN_ROOT'} || '/usr/share/lintian'; my $debug = $ENV{'LINTIAN_DEBUG'} || 0; @@ -41,48 +47,62 @@ sub read_tag_info { my %tag_info; if (defined $type && $type eq 'html') { $dtml_convert = \&dtml_to_html; - } else { - $dtml_convert = \&dtml_to_text; } # $debug = 2; for my $f (<$LINTIAN_ROOT/checks/*.desc>) { print "N: Reading checker description file $f ...\n" if $debug >= 2; - my @secs = read_dpkg_control($f); + my @secs = Util::read_dpkg_control($f); $secs[0]->{'check-script'} or fail("error in description file $f: `Check-Script:' not defined"); for (my $i=1; $i<=$#secs; $i++) { (my $tag = $secs[$i]->{'tag'}) or fail("error in description file $f: section $i does not have a `Tag:'"); - - my @foo = split_paragraphs($secs[$i]->{'info'}); - if ($secs[$i]->{'ref'}) { - push(@foo,""); - push(@foo,format_ref($secs[$i]->{'ref'})); - } - - if ($secs[$i]->{'severity'} and $secs[$i]->{'certainty'}) { - push(@foo, ""); - push(@foo, "Severity: $secs[$i]->{'severity'}; " . - "Certainty: $secs[$i]->{'certainty'}"); - } - - if ($secs[$i]->{'experimental'}) { - push(@foo,""); - push(@foo,"Please note that this tag is marked Experimental, which " - . "means that the code that generates it is not as well tested " - . "as the rest of Lintian, and might still give surprising " - . "results. Feel free to ignore Experimental tags that do not " - . "seem to make sense, though of course bug reports are always " - . "welcomed."); - } - - $tag_info{$tag} = join("\n",&$dtml_convert(@foo)); + $tag_info{$tag} = format_tag_description($secs[$i], 0, $dtml_convert); } } + return \%tag_info; } +sub format_tag_description { + my $tag=shift; + my $indent=shift; + my $dtml_convert=shift; + + if (not defined $dtml_convert) { + $dtml_convert = \&dtml_to_text; + } + + my @foo = split_paragraphs($tag->{'info'}); + if ($tag->{'ref'}) { + push(@foo,""); + push(@foo,format_ref($tag->{'ref'})); + } + + if ($tag->{'severity'} and $tag->{'certainty'}) { + push(@foo, ""); + push(@foo, "Severity: $tag->{'severity'}; " . + "Certainty: $tag->{'certainty'}"); + } + + if ($tag->{'experimental'}) { + push(@foo,""); + push(@foo,"Please note that this tag is marked Experimental, which " + . "means that the code that generates it is not as well tested " + . "as the rest of Lintian, and might still give surprising " + . "results. Feel free to ignore Experimental tags that do not " + . "seem to make sense, though of course bug reports are always " + . "welcomed."); + } + + if ($indent) { + return wrap_paragraphs(" " x $indent, join("\n",&$dtml_convert(@foo))); + } else { + return join("\n",&$dtml_convert(@foo)); + } +} + sub manual_ref { my ($man, $sub) = @_; my $numbered = ($sub =~ /[A-Z\d\.]+/) ? 1 : 0; diff --git a/lib/Text_utils.pm b/lib/Text_utils.pm index 56ea7b4..e869b50 100644 --- a/lib/Text_utils.pm +++ b/lib/Text_utils.pm @@ -19,6 +19,12 @@ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301, USA. +package Text_utils; + +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(split_paragraphs wrap_paragraphs dtml_to_html dtml_to_text); + use strict; # requires wrap() function diff --git a/reporting/html_reports b/reporting/html_reports index 04fe654..f3f3f0e 100755 --- a/reporting/html_reports +++ b/reporting/html_reports @@ -54,6 +54,7 @@ $ENV{'LINTIAN_ROOT'} = $LINTIAN_ROOT; use lib "$ENV{LINTIAN_ROOT}/lib"; use Read_pkglists; use Read_taginfo; +use Text_utils; use Util; # Global variables from Read_pkglists. Ugh.