[Debtags-commits] [svn] r1463 - autodebtag/trunk/dbacl

Enrico Zini enrico at costa.debian.org
Mon Oct 31 20:40:49 UTC 2005


Author: enrico
Date: Mon Oct 31 20:40:49 2005
New Revision: 1463

Modified:
   autodebtag/trunk/dbacl/debtags-ai
Log:
Implemented pkgstats feature

Modified: autodebtag/trunk/dbacl/debtags-ai
==============================================================================
--- autodebtag/trunk/dbacl/debtags-ai	(original)
+++ autodebtag/trunk/dbacl/debtags-ai	Mon Oct 31 20:40:49 2005
@@ -86,7 +86,7 @@
 sub usage (;$)
 {
 	my ($status) = $_;
-	print STDERR qq{Usage: $0 [options] train|patch
+	print STDERR qq{Usage: $0 [options] command
 Commands are:
   train           Generates training data for dbacl.
   patch [pkgs]    Generate a tag patch for the given packages (or all packages
@@ -97,6 +97,10 @@
                   confirmed by dbacl.
   fixpatch1       Reads a patch from stdin and only output those parts on which
                   dbacl does not disagree.
+  pkgstats [pkgs] Prints, for every tag, the likelyhood that the package could
+				  have that tag.  If there is only one argument and contains
+				  '%p', then it is taken as a file template and the computed
+				  data will be written into a different file per every package.
 Options are:
   --help, -h      Print this help message.
   --verbose, -v   Be verbose.  A number can be provided for more verbose
@@ -203,6 +207,66 @@
 		check_training();
 		read_apt();
 		fix_patch1();
+	} elsif ($cmd eq 'pkgstats') {
+		usage if not @ARGV;
+		check_training();
+		read_apt();
+
+		# Filter out tags for which we know the bayesian doesn't do a good job
+		for my $tag (sort keys %tags)
+		{
+			push @interesting_tags, $tag 
+				if $tag !~ $tag_blacklist;
+		}
+
+		if ($ARGV[0] =~ /%p/)
+		{
+			my $i = 0;
+			my $totpkgs = scalar keys %pkgdata;
+			printf STDERR "Doing $totpkgs packages.  Create a file called stop-pkgstats to pause.\n"
+				if $verbose > 0;
+			for my $pkg (keys %pkgdata)
+			{
+				last if -e 'stop-pkgstats';
+				++$i;
+				my $file = $ARGV[0];
+				$file =~ s/%p/$pkg/g;
+				if (not -f $file)
+				{
+					$SIG{INT} = 'IGNORE';
+					open OUT, ">$file" or die "Can't write to $file: $!";
+					for my $tag (@interesting_tags)
+					{
+						my $val = testtag($pkg, $tag);
+						printf OUT "%s %d\n", $tag, $val if defined $val;
+					}
+					close OUT;
+					$SIG{INT} = 'DEFAULT';
+				}
+				printf STDERR "Computing package %s (%d/%d)...\e[K\r",
+					$pkg, $i, $totpkgs
+						if ($verbose > 0);
+			}
+			unlink 'stop-pkgstats';
+		} elsif (@ARGV == 1) {
+			for my $pkg (@ARGV)
+			{
+				for my $tag (@interesting_tags)
+				{
+					my $val = testtag($pkg, $tag);
+					printf "%s %d\n", $tag, $val if defined $val;
+				}
+			}
+		} else {
+			for my $pkg (@ARGV)
+			{
+				for my $tag (@interesting_tags)
+				{
+					my $val = testtag($pkg, $tag);
+					printf "%s %s %d\n", $pkg, $tag, $val if defined $val;
+				}
+			}
+		}
 	} else {
 		usage();
 	}



More information about the Debtags-commits mailing list