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

[RFC/PATCH] Some improvements to --display-level



While formulating a news post about the new features of lintian 2.0.0
I noticed that the --display-level option is sometimes unneccessary
hard to use.

Here are some patches that add the possibility to specify severities and
certainties with >= or <= (for completness sake you can also specify > or
< but I doubt that this adds any real value).

Comments welcome.

Gruesse,
-- 
Frank Lichtenheld <djpig@debian.org>
www: http://www.djpig.de/
>From 581b7b7329cababa2b544a57ea8c05e00153b705 Mon Sep 17 00:00:00 2001
From: Frank Lichtenheld <djpig@debian.org>
Date: Wed, 17 Sep 2008 00:35:52 +0200
Subject: [PATCH] frontend/lintian: Add support for ranges to --display-level

You can use >=, >, <, <= to specify ranges of certainties/severities.
---
 debian/changelog |    3 ++
 frontend/lintian |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/lintian.1    |    2 +-
 3 files changed, 65 insertions(+), 1 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 7b8a81c..f5607e0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,9 @@ lintian (2.0.0) unstable; urgency=low
   * checks/copyright-file:
     + [FL] Also detect v1.1 of CeCILL license, not only v2.0.
       (Closes: #498994)
+  
+  * frontend/lintian:
+    + [FL] Add support for ranges to --display-level.
 
  -- Frank Lichtenheld <djpig@debian.org>  Tue, 16 Sep 2008 19:34:29 +0200
 
diff --git a/frontend/lintian b/frontend/lintian
index 73afec2..757f7fe 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -288,10 +288,71 @@ sub reset_display_level {
     }
 }
 
+sub set_display_level_multi {
+    my ($op, $level, $val) = @_;
+
+    my @inc_severities = @severities;
+    my @inc_certainties = @certainties;
+    my $inc_border = ($op =~ /^[<>]=$/) ? 1 : 0;
+    if ($op =~ /^>/) {
+	@inc_severities = reverse @inc_severities;
+	@inc_certainties = reverse @inc_certainties;
+    }
+    my $severity = join("|", @severities);
+    my $certainty = join("|", @certainties);
+    if ($level =~ m/^($severity)$/) {
+	foreach my $s (cut_list($level, $inc_border, @inc_severities)) {
+	    map { $display_level{$s}{$_} = $val } @certainties;
+	}
+    } elsif ($level =~ m/^($certainty)$/) {
+	foreach my $c (cut_list($level, $inc_border, @inc_certainties)) {
+	    map { $display_level{$_}{$c} = $val } @severities;
+	}
+    } elsif ($level =~ m/^($severity)\/($certainty)$/) {
+	foreach my $s (cut_list($1, $inc_border, @inc_severities)) {
+	    foreach my $c (cut_list($2, $inc_border, @inc_certainties)) {
+		$display_level{$s}{$c} = $val;
+	    }
+	}
+    } else {
+	die "invalid argument to --display-level: $level\n";
+    }
+
+}
+
+sub cut_list {
+    my ($border, $inc_border, @list) = @_;
+
+    my (@newlist, $found);
+    foreach (@list) {
+	if ($_ eq $border) {
+	    push @newlist, $_ if $inc_border;
+	    $found = 1;
+	    last;
+	} else {
+	    push @newlist, $_;
+	}
+    }
+    die "internal error: cut_list did not find border $border\n"
+	unless $found;
+    if (!$inc_border and !@newlist
+	and $border eq $list[0]) {
+	warn "warning: display level $border specified with > (or <) is empty set, assuming >= (or <=)\n";
+	push @newlist, $list[0];
+    }
+
+    return @newlist;
+}
+
 # Parse input display level to enable (val 1) or disable (val 0) it
 # accordingly
 sub set_display_level {
     my ($level, $val) = @_;
+    if ($level =~ m/^([<>]=?)(.+)/) {
+	set_display_level_multi($1, $2, $val);
+	return;
+    }
+
     my $severity = join("|", @severities);
     my $certainty = join("|", @certainties);
     if ($level =~ m/^($severity)$/) {
diff --git a/man/lintian.1 b/man/lintian.1
index 1601242..8effead 100644
--- a/man/lintian.1
+++ b/man/lintian.1
@@ -168,7 +168,7 @@ Display informational ("I:") tags as well.  They are normally suppressed.
 Display experimental ("X:") tags as well.  They are normally suppressed.
 
 .TP
-.BR \-L " [+|-|=][S|C|S/C], " \-\-display\-level " [+|-|=][S|C|S/C]"
+.BR \-L " [+|-|=][>=|>|<|<=][S|C|S/C], " \-\-display\-level " [+|-|=][>=|>|<|<=][S|C|S/C]"
 Fine-grained selection of tags to be displayed. It is possible to add, remove
 or set the levels to display, specifying a severity (S: serious, important,
 normal, minor, wishlist), a certainty (C: certain, possible, wild-guess), or
-- 
1.6.0.1

>From e787364c02c2fc9fcf5554d86e8599cf6c40595e Mon Sep 17 00:00:00 2001
From: Frank Lichtenheld <djpig@debian.org>
Date: Wed, 17 Sep 2008 00:38:34 +0200
Subject: [PATCH] Use the new --display-level range support

Use it to simplify setting the default levels. Also improve the
documentation in the man page.
---
 frontend/lintian |    6 ++----
 man/lintian.1    |    5 ++++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/frontend/lintian b/frontend/lintian
index 757f7fe..d2656da 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -428,10 +428,8 @@ my %opthash = (			# ------------------ actions
 
 # init display level settings
 reset_display_level();
-set_display_level('serious', 1);
-set_display_level('important', 1);
-set_display_level('normal/certain', 1);
-set_display_level('normal/possible', 1);
+set_display_level_multi('>=', 'important', 1);
+set_display_level_multi('>=', 'normal/possible', 1);
 set_display_level('minor/certain', 1);
 
 # init commandline parser
diff --git a/man/lintian.1 b/man/lintian.1
index 8effead..d15508c 100644
--- a/man/lintian.1
+++ b/man/lintian.1
@@ -162,6 +162,8 @@ without running lintian, see
 .TP
 .BR \-I ", " \-\-display\-info
 Display informational ("I:") tags as well.  They are normally suppressed.
+(This is \equivalent to
+.BR \-L " \(dq>=wishlist\(dq)."
 
 .TP
 .BR \-E ", " \-\-display\-experimental
@@ -172,7 +174,8 @@ Display experimental ("X:") tags as well.  They are normally suppressed.
 Fine-grained selection of tags to be displayed. It is possible to add, remove
 or set the levels to display, specifying a severity (S: serious, important,
 normal, minor, wishlist), a certainty (C: certain, possible, wild-guess), or
-both (S/C).
+both (S/C).  The default settings are equivalent to
+.BR \-L " \(dq>=important\(dq " \-L " \(dq+>=normal/possible\(dq " \-L " +minor/certain)."
 
 .TP
 .BR \-l " n, " \-\-unpack\-level " n"
-- 
1.6.0.1

>From 3447c7d9e6c32f44678f4f78372907214b4ab8da Mon Sep 17 00:00:00 2001
From: Frank Lichtenheld <djpig@debian.org>
Date: Wed, 17 Sep 2008 00:43:27 +0200
Subject: [PATCH] frontend/lintian: reorder some code to make it more logical

Move all subs used in GetOptions together.
---
 frontend/lintian |   51 +++++++++++++++++++++++++++------------------------
 1 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/frontend/lintian b/frontend/lintian
index d2656da..2d5f7dd 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -278,6 +278,33 @@ sub record_pkgmode {
     $pkg_mode = 'u' if $_[0] eq 'udeb';
 }
 
+# Process -L|--display-level flag
+sub record_display_level {
+    my $level = $_[1];
+    if ($level =~ m/^\+(.+)/) {
+	set_display_level($1, 1);
+    } elsif ($level =~ m/^\-(.+)/) {
+	set_display_level($1, 0);
+    } elsif ($level =~ m/^\=?(.+)/) {
+	reset_display_level();
+	set_display_level($1, 1);
+    } else {
+	die "invalid argument to --display-level: $level\n";
+    }
+}
+
+# Process -I|--display-info flag
+sub display_infotags {
+    foreach my $s (@severities) {
+	set_display_level($s, 1);
+    }
+}
+
+# Process --display-source flag
+sub record_display_source {
+    $display_source{$_[1]} = 1;
+}
+
 # Clears current display level information, disabling all severities and
 # certainties
 sub reset_display_level {
@@ -474,30 +501,6 @@ if (($check_everything or $packages_file) and $#ARGV+1 > 0) {
     undef $packages_file;
 }
 
-sub record_display_level {
-    my $level = $_[1];
-    if ($level =~ m/^\+(.+)/) {
-	set_display_level($1, 1);
-    } elsif ($level =~ m/^\-(.+)/) {
-	set_display_level($1, 0);
-    } elsif ($level =~ m/^\=?(.+)/) {
-	reset_display_level();
-	set_display_level($1, 1);
-    } else {
-	die "invalid argument to --display-level: $level\n";
-    }
-}
-
-sub display_infotags {
-    foreach my $s (@severities) {
-	set_display_level($s, 1);
-    }
-}
-
-sub record_display_source {
-    $display_source{$_[1]} = 1;
-}
-
 # check permitted values for --color
 if ($color and $color !~ /^(never|always|auto|html)$/) {
     die "invalid argument to --color: $color\n";
-- 
1.6.0.1


Reply to: