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

r10400 - /man-cgi/extractor/compare-manpage-stats.pl



Author: jfs
Date: Wed May 21 21:01:11 2014
New Revision: 10400

URL: http://svn.debian.org/wsvn/?sc=1&rev=10400
Log:
Add Perl script to compare the manpage stats between runs

Added:
    man-cgi/extractor/compare-manpage-stats.pl   (with props)

Added: man-cgi/extractor/compare-manpage-stats.pl
URL: http://svn.debian.org/wsvn/man-cgi/extractor/compare-manpage-stats.pl?rev=10400&op=file
==============================================================================
--- man-cgi/extractor/compare-manpage-stats.pl	(added)
+++ man-cgi/extractor/compare-manpage-stats.pl	Wed May 21 21:01:11 2014
@@ -0,0 +1,132 @@
+#!/usr/bin/perl
+#
+# Analyse stats of manpages and review the differences.
+#
+# (c) 2014 Javier Fernandez-Sanguino <jfs@debian.org>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; version 2 dated June, 1991.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+#
+
+use strict;
+use Getopt::Long;
+
+# -d - debug
+# -s directory - Stats directory (defaults to './data')
+
+
+my $pwd = `pwd`;
+chomp $pwd;
+# Default values for options
+my $STATSDIR = $pwd."/data";
+my $debug = '';
+GetOptions (
+                "statsdir=s"   => \$STATSDIR,      # string
+                "debug"  => \$debug)   # flag
+         or die("Error in command line arguments\n");
+
+if ( $#ARGV > 0  ) {
+    die "usage: $0 [-d] [-s dir] [-w dir]\n";
+}
+
+# Check directories
+if (! -e $STATSDIR) {
+        die ("ERROR: There is no stats directory in $STATSDIR: $!");
+}
+
+# We always compare the 'stats' file with 'stats.0' (previous run using rotate log)
+# First we check that the files exist
+if (! -e "$STATSDIR/stats" ) {
+        die ("ERROR: There is no current stats file in $STATSDIR: $!");
+}
+if (! -e "$STATSDIR/stats.0" ) {
+        die ("ERROR: There is no previous stats file in $STATSDIR: $!");
+}
+
+# Now we read both files' contents
+my %manstats;
+
+open (STATS, "$STATSDIR/stats") || die ("Could not read $STATSDIR/stats");
+while (<STATS>) {
+	chomp;
+	if ( /^(\w+) (\d+)/ )  {
+		my $d = $1; my $m = $2;
+		$manstats{cur}{$d}=$m;
+		$manstats{prev}{$d}=0;
+		print "DEBUG: Current stats - $m manpages in $d\n" if $debug;
+	}
+}
+close STATS;
+
+open (STATS, "$STATSDIR/stats.0") || die ("Could not read $STATSDIR/stats.0");
+while (<STATS>) {
+	chomp;
+	if ( /^(\w+) (\d+)/ )  {
+		my $d = $1; my $m = $2;
+		$manstats{cur}{$d}=$m;
+		$manstats{prev}{$d}=0;
+		$manstats{prev}{$d}=$m;
+		$manstats{cur}{$d}=0 if ! defined($manstats{cur}{$d});
+		print "DEBUG: Previous stats - $m manpages in $d\n" if $debug;
+	}
+}
+close STATS;
+
+# Specific checks
+# 1.- We expect the manpages for the stable distribution to remain the same 
+# 2.- We expect the manpages in the unstable distribution to increase
+
+print "\n";
+print "-"x80;
+print "\n";
+print "Manpage report - comparison with previous run\n";
+print "-"x80;
+print "\n";
+my $finmsg = "";
+my $warnsign ="\n - WARNING -  - WARNING - - WARNING - - WARNING -\n";
+my $errorsign ="\n - ERROR - - ERROR - - ERROR - - ERROR - - ERROR - \n";
+foreach my $d ( keys(%{$manstats{cur}}) ) {
+	print "DEBUG: Analysing distribution $d\n" if $debug;
+	print "DEBUG: $manstats{cur}{$d} vs $manstats{prev}{$d}\n" if $debug;
+	my $diff=$manstats{cur}{$d}-$manstats{prev}{$d};
+	if ($manstats{cur}{$d} == $manstats{prev}{$d} ) {
+		print "No change in distribution '$d'.\n";
+		if ( $d eq "sid" ) {
+			$finmsg =  $finmsg. $errorsign. "Possible error in extraction scripts? The number of manpages for distribution '$d' should increase and it did not increase.\n Please review the logs\n";
+		}
+	}
+	if ($manstats{cur}{$d} > $manstats{prev}{$d} ) {
+		print "INCREASE in distribution $d: ".$diff." more manpages\n";
+	}
+	if ($manstats{cur}{$d} < $manstats{prev}{$d} ) {
+		print "DECREASE in distribution $d: ".$diff." manpages\n";
+# Todo: use a list of keys for released distributions to compare
+		if ( $d eq "wheezy"  or $d eq "squeeze" ) {
+			$finmsg = $finmsg. $warnsign. "The number of manpages for distribution '$d' should not decrease.\nPlease review the extraction logs.\n - WARNING - \n";
+		}
+	}
+}
+
+# TODO: Cat the extraction logs of the last run for review.
+
+if ($finmsg eq "" ) {
+	$finmsg = "Everything seems OK.";
+}
+
+
+# Final report
+print  $finmsg;
+
+
+
+exit 0;

Propchange: man-cgi/extractor/compare-manpage-stats.pl
------------------------------------------------------------------------------
    svn:executable = *


Reply to: