RFC: [PATCH] Make "lintian --info --color=auto" work again
Hi,
The attached patch replaces the pipe from the main lintian script to
lintian-info with an extra flag to Lintian::Output::print_tag()
indicating whether the full output should be displayed. This allows
"lintian --info --color=auto" to produce colourised output when being
output to a terminal.
Comments welcome.
Cheers,
Adam
diff --git a/debian/changelog b/debian/changelog
index be61ffb..de6964a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,11 +12,25 @@ 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)
- * lib/Lab.pm:
- + [FL] Fix breakage of populate_with_dist() I introduced in 2.1.0.
+ * frontend/lintian:
+ + [ADB] Don't pipe output to lintian-info when --info is specified.
+ Instead, simply set a variable which can be used later by the output
+ code.
+
* 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] Optionally display the full description of a tag (i.e. when
+ the frontend was called with --info).
+
+ * lib/Lab.pm:
+ + [FL] Fix breakage of populate_with_dist() I introduced in 2.1.0.
+ * lib/Read_taginfo.pm:
+ + [ADB] Qualify the call to read_dpkg_control in read_tag_info(), so
+ that it can be called from Output::print_tag().
+ * lib/Tags.pm:
+ + [ADB] When displaying a tag, indicate whether its full description
+ should be included.
-- Adam D. Barratt <adam@adam-barratt.org.uk> Fri, 28 Nov 2008 21:47:33 +0000
diff --git a/frontend/lintian b/frontend/lintian
index fe9a823..3b1608a 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';
}
@@ -684,6 +679,7 @@ map { $_->{'script'} = 'lintian'; Tags::add_tag($_) } @l_secs;
$Tags::show_experimental = $display_experimentaltags;
$Tags::show_overrides = $show_overrides;
+$Tags::show_description = $lintian_info;
%Tags::display_level = %display_level;
%Tags::display_source = %display_source;
%Tags::only_issue_tags = map { $_ => 1 } (split(/,/, $check_tags))
@@ -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/lib/Lintian/Output.pm b/lib/Lintian/Output.pm
index 02beb03..aaa904c 100644
--- a/lib/Lintian/Output.pm
+++ b/lib/Lintian/Output.pm
@@ -22,6 +22,9 @@ use strict;
use warnings;
use v5.8.0; # for PerlIO
+use lib "$ENV{'LINTIAN_ROOT'}/lib";
+use Read_taginfo;
+use Text_utils;
=head1 NAME
@@ -240,16 +243,19 @@ can only be called as instance methods.
=over 4
-=item C<print_tag($pkg_info, $tag_info, $extra)>
+=item C<print_tag($pkg_info, $tag_info, $extra, $show_description)>
Print a tag. The first two arguments are hash reference with the information
about the package and the tag, $extra is the extra information for the tag
-(if any) as an array reference. Called from Tags::tag().
+(if any) as an array reference. $show_description indicates whether the
+tag's description should also be displayed. Called from Tags::tag().
=cut
+my %already_displayed;
+my %tag_list;
sub print_tag {
- my ($self, $pkg_info, $tag_info, $information) = @_;
+ my ($self, $pkg_info, $tag_info, $information, $show_description) = @_;
my $extra = '';
$extra = " @$information" if @$information;
@@ -269,6 +275,16 @@ sub print_tag {
}
$self->_print('', "$code: $pkg_info->{pkg}$type", "$tag$extra");
+ if ($show_description) {
+ if (!$already_displayed{$tag_info->{tag}}++) {
+ %tag_list=%{read_tag_info()} unless keys %tag_list;
+ $self->_print('', 'N', '');
+ foreach (split("\n", wrap_paragraphs(" ", $tag_list{$tag_info->{tag}}))) {
+ $self->_print('', 'N', $_);
+ }
+ $self->_print('', 'N', '');
+ }
+ }
}
=item C<print_start_pkg($pkg_info)>
diff --git a/lib/Read_taginfo.pm b/lib/Read_taginfo.pm
index dbcd464..fbf0081 100644
--- a/lib/Read_taginfo.pm
+++ b/lib/Read_taginfo.pm
@@ -49,7 +49,7 @@ sub read_tag_info {
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++) {
diff --git a/lib/Tags.pm b/lib/Tags.pm
index 310a8a1..e47906e 100644
--- a/lib/Tags.pm
+++ b/lib/Tags.pm
@@ -33,6 +33,7 @@ use Lintian::Output;
# configuration variables and defaults
our $show_experimental = 0;
our $show_overrides = 0;
+our $show_description = 0;
our %display_level;
our %display_source;
our %only_issue_tags;
@@ -336,7 +337,7 @@ sub tag {
return 1 if skip_print( $tag_info );
$Lintian::Output::GLOBAL->print_tag( $info{$current}, $tag_info,
- \@information );
+ \@information, $show_description );
return 1;
}
Reply to: