Hi!

On Thu, May 01, 2008 at 07:08:12PM +0800, Paul Wise wrote:
> I do not use the *-alert scripts because of the ridiculously high number
> of issues they present and the fact that there is no way to easily
> prioritise them. I would like it if they grew two options for sorting
> based on popcon data. The first should use local popcon data to do the
> sorting and the second should download data from popcon.d.o and use that
> to sort the bugs/packages.

AFAICS popcon doesn't store any popcon information but regenerates it
once a week and after using it (for submitting probably :)) it discards
the data. I don't see a nice way to use that local data without ugly
piping of a perl script through a perl script. :)

I tried to implement a sorting by remote popcon data, though, and
attached a patch. It's probably not the best patch I've ever written
(feel free to critisize!) but it seems to work.

Cheers,
Hauke
Index: rc-alert.pl
===================================================================
--- rc-alert.pl	(revision 1860)
+++ rc-alert.pl	(working copy)
@@ -26,7 +26,7 @@
 use Getopt::Long;
 
 sub remove_duplicate_values($);
-sub print_if_relevant(%);
+sub store_if_relevant(%);
 sub human_flags($);
 sub unhtmlsanit($);
 
@@ -63,6 +63,9 @@
 my $distincoperation = "or";
 my $distexcoperation = "or";
 
+my $popcon = 0;
+my $popcon_by_vote = 0;
+
 my $progname = basename($0);
 
 my $usage = <<"EOF";
@@ -83,6 +86,10 @@
   --include-dist-op  Must all distributions be matched for inclusion?
   --exclude-dists    Set of distributions to exclude
   --exclude-dist-op  Must all distributions be matched for exclusion?
+
+  Popcon options:
+  --popcon           Sort bugs by package's popcon rank
+  --pc-vote          Sort by_vote instead of by_inst (see debtags(1))
 EOF
 
 my $version = <<"EOF";
@@ -111,6 +118,8 @@
 	   "exclude-dists=s" => \$excludedists,
 	   "include-dist-op|o=s" => \$distincoperation,
 	   "exclude-dist-op=s" => \$distexcoperation,
+       "popcon" => \$popcon,
+       "pc-vote" => \$popcon_by_vote,
 	   );
 
 if ($opt_help) { print $usage; exit 0; }
@@ -164,11 +173,27 @@
     $package_list = InstalledPackages(0);
 }
 
+## Get popcon information
+my %popcon;
+if ($popcon) {
+    my $pc_by = $popcon_by_vote ? 'vote' : 'inst';
+
+    open POPCON, "wget -q -O - http://popcon.debian.org/by_$pc_by.gz | gunzip -c |"
+        or die "Not able to receive remote popcon data!";
+    while (<POPCON>) {
+        next unless /(\d+)\s+(\S+)\s+(\d+\s+){5}\(.*\)/;
+        # rank $1 for package $2
+        $popcon{$2} = $1;
+    }
+    close POPCON;
+}
+
 ## Read the list of bugs
 
 my $found_bugs_start;
 my ($current_package, $comment);
 
+my %pkg_store;
 while (defined(my $line = <BUGS>)) {
     if( $line =~ /^<div class="package">/) {
 	$found_bugs_start = 1;
@@ -181,9 +206,10 @@
     } elsif ($line =~ m%<a name="(\d+)"></a>\s*<a href="[^\"]+">\d+</a> (\[[^\]]+\])( \[[^\]]+\])? ([^<]+)%i) {
 	my ($num, $tags, $dists, $name) = ($1, $2, $3, $4);
 	chomp $name;
-	print_if_relevant(pkg => $current_package, num => $num, tags => $tags, dists => $dists, name => $name, comment => $comment);
+	store_if_relevant(pkg => $current_package, num => $num, tags => $tags, dists => $dists, name => $name, comment => $comment);
     }
 }
+for (sort {$a <=> $b } keys %pkg_store) { print $pkg_store{$_}; }
 
 close BUGS or die "$progname: could not close $cachefile: $!\n";
 
@@ -199,25 +225,39 @@
     return $in;
 }
 
-sub print_if_relevant(%) {
+sub store_if_relevant(%) {
     my %args = @_;
+
     if (exists($$package_list{$args{pkg}})) {
-	# potentially relevant
-	my ($flags, $flagsapply) = human_flags($args{tags});
-	my $distsapply = 1;
-	my $dists;
-	($dists, $distsapply) = human_dists($args{dists}) if defined $args{dists};
-	
-	return unless $flagsapply and $distsapply;
+        # potentially relevant
+        my ($flags, $flagsapply) = human_flags($args{tags});
+        my $distsapply = 1;
+        my $dists;
+        ($dists, $distsapply) = human_dists($args{dists}) if defined $args{dists};
 
-	# yep, relevant
-	print "Package: $args{pkg}\n",
-	    $comment,  # non-empty comments always contain the trailing \n
-	    "Bug:     $args{num}\n",
-	    "Title:   " . unhtmlsanit($args{name}) , "\n",
-	    "Flags:   " . $flags , "\n",
-	    (defined $args{dists} ? "Dists:  " . $dists . "\n" : ""),
-	    "\n";
+        return unless $flagsapply and $distsapply;
+
+        # yep, relevant
+        my $bug_string = "Package: $args{pkg}\n" .
+            $comment .  # non-empty comments always contain the trailing \n
+            "Bug:     $args{num}\n" .
+            "Title:   " . unhtmlsanit($args{name}) . "\n" .
+            "Flags:   " . $flags . "\n" .
+            (defined $args{dists} ? "Dists:  " . $dists . "\n" : "") .
+            (defined $popcon{$args{pkg}} ? "Popcon rank: " . $popcon{$args{pkg}} . "\n" : "") .
+            "\n";
+
+        if ($popcon) {
+            return unless $bug_string;
+            my $index = $popcon{$args{pkg}} ? $popcon{$args{pkg}} : 9999999;
+            if ($pkg_store{$index}) {
+                $pkg_store{$index} .= $bug_string;
+            } else {
+                $pkg_store{$index} = $bug_string;
+            }
+        } else {
+            $pkg_store{1} .= $bug_string;
+        }
     }
 }
 
Index: rc-alert.1
===================================================================
--- rc-alert.1	(revision 1860)
+++ rc-alert.1	(working copy)
@@ -2,7 +2,7 @@
 .SH NAME
 rc-alert \- check for installed packages with release-critical bugs
 .SH SYNOPSIS
-\fBrc-alert [inclusion options] [package ...]\fR
+\fBrc-alert [inclusion options] [--popcon] [package ...]\fR
 .br
 \fBrc-alert \-\-help|\-\-version\fR
 .SH DESCRIPTION
@@ -62,6 +62,18 @@
 If set to \fIand\fP, a bug must apply to all of the specified distributions
 in order to be excluded.  By default the bug will be excluded if it applies
 to any of the listed distributions.
+.P
+Popularity-contest collects data about installation and usage of Debian
+packages. You can additionaly sort the bugs by the popcon rank of the related
+packages.
+.TP
+.BR \-\-popcon
+Sort bugs by popcon rank of the package the bug belongs to.
+.TP
+.BR \-\-pc\-vote
+Packages are sorted by the number of people who installed this package. With
+this option you can change it to the number of people who use this package
+regularly.
 .SH EXAMPLES
 .TP
 .BR \-\-include\-dists " OS"

Attachment: signature.asc
Description: Digital signature

Reply via email to