[Fai-commit] r4642 - people/eartoast/addons/class-reference

glaweh-guest at alioth.debian.org glaweh-guest at alioth.debian.org
Sat Oct 20 12:04:39 UTC 2007


Author: glaweh-guest
Date: 2007-10-20 12:04:39 +0000 (Sat, 20 Oct 2007)
New Revision: 4642

Modified:
   people/eartoast/addons/class-reference/fai-classes-log
Log:
throw out half of the code... make it follow the KISS principle.
it now only has one output option: simple table consisting of
class datetime host classpriority


Modified: people/eartoast/addons/class-reference/fai-classes-log
===================================================================
--- people/eartoast/addons/class-reference/fai-classes-log	2007-10-19 23:13:22 UTC (rev 4641)
+++ people/eartoast/addons/class-reference/fai-classes-log	2007-10-20 12:04:39 UTC (rev 4642)
@@ -1,11 +1,9 @@
 #!/usr/bin/perl
-# HG: create a reference of all classes referenced in the fai logfiles
-#     run this script in the FAI logdir on the logserver
+# HG: create a list all classes referenced in the fai logfiles
+#     run this script with the FAI logdir on the logserver as argument
 #     it extracts all references to classes and prints them on stdout
 #     Format:
-#       class: $classname
-#         $hostname:$date
-#         ...
+#       $class $datetime $hostname $class_priority
 
 use strict;
 use warnings;
@@ -14,27 +12,13 @@
 use File::Basename;
 
 my $log_topdir;
-my $listingtype;
 our ($opt_h);
 
 # Dirs within the logdirs to be ignored
 my @ignore_dirs = qw'backup ssh .ssh';
 
-# Hash of array-refs
-#     keys: classes
-#   values: list of places where the classes are referenced
-my %config_classes;
-
-# add a location to %config_classes
-sub add_class_ref {
-	my $class = shift;
-	my $location = shift;
-
-	# strip heading/tailing nonword-characters
-	$class =~ s#^\W*([\w-]+)\W*$#$1#;
-	push @{$config_classes{$class}},$location; 
-}
-
+# array to accumulate lines
+my @lines;
 # scan $logfdir/$hostname/FAI_CLASSES for references on classes
 sub scan_log {
 	sub read_class_file {
@@ -46,6 +30,7 @@
 			my $host=$2;
 			my $date=$3;
 			my $time=$4;
+			my $position=0;
 			
 			open $fh,$fname;
 			while (<$fh>) {
@@ -53,7 +38,10 @@
 				chomp;
 				my @classes=split;
 				foreach (@classes) {
-					add_class_ref($_,"$date $host");
+					s#^\W*([\w-]+)\W*$#$1#;
+					my $line="$_ $date$time $host $position";
+					push @lines,$line;
+					$position++;
 				}
 			}
 			close $fh;
@@ -75,112 +63,19 @@
 		$log_topdir);
 }
 
-# print the classes and the places referencing them
-sub dump_class_refs_full {
-	foreach my $class (sort keys %config_classes) {
-		print "$class\n";
-		my $lastdate='';
-		my $lasthost='';
-		foreach (sort @{$config_classes{$class}}) {
-			my ($date,$host)=split;
-			if ($date ne $lastdate) {
-				print "\t$date\n";
-				$lastdate=$date;
-				$lasthost='';
-			}
-			if ($host ne $lasthost) {
-				print "\t\t$host\n";
-				$lasthost=$host;
-			}
-		}
-	}
-}
-
-# print the classes and the hosts in them with the respective last-seen times
-sub dump_class_refs_host_last_seen {
-	my $type = shift;
-	foreach my $class (sort keys %config_classes) {
-		print "$class\n";
-		my %last_seen;
-		my @output;
-
-		# show only the last time, when a host had a class
-		foreach (sort @{$config_classes{$class}}) {
-			# array elements are "$date $host"
-			my ($date,$host)=split;
-			# as we are walking time-sorted through the list,
-			# $last_seen{$host} will contain "$last-seen-date $host"
-			# at the end of this loop
-			$last_seen{$host}=$_;
-		}
-		# print out a list, indented with two spaces, sorted by date and hostname
-		# of the last-seen data
-		#print "  ".join("\n  ",sort values %last_seen)."\n";
-		my $lastdate='';
-		my $lasthost='';
-		foreach (sort values %last_seen) {
-			my ($date,$host)=split;
-			if ($date ne $lastdate) {
-				print "\t$date\n";
-				$lastdate=$date;
-				$lasthost='';
-			}
-			if ($host ne $lasthost) {
-				print "\t\t$host\n";
-				$lasthost=$host;
-			}
-		}
-	}
-}
-
-# print only the classes and the dates they were seen the last time
-sub dump_class_refs_last_seen {
-	my @refs;
-	foreach my $class (sort keys %config_classes) {
-		$_=(sort @{$config_classes{$class}})[-1];
-		s# .*$##;
-		push @refs,"$_ $class";
-	}
-	my $lastdate='';
-	foreach (sort @refs) {
-		my ($date,$class)=split;
-		if ($date ne $lastdate) {
-			print "$date\n";
-			$lastdate=$date;
-		}
-		print "\t$class\n";
-	}
-}
 sub HELP_MESSAGE {
 	my $name = basename($0);
 	print << "EOF";
-Usage: $name <listingtype> <fai-log-topdir>
-
-listingtypes:
-  last_seen
-    just class and last-seen-date
-  host_last_seen
-    hostname and the date this class was last seen on it
-  full
-    all times a class was defined by any host, together with the hostnames
+Usage: $name <fai-log-topdir>
 EOF
 	exit 1;
 }
 
 getopts('h');
 HELP_MESSAGE() if ($opt_h);
-HELP_MESSAGE() if ($#ARGV < 1);
+HELP_MESSAGE() if ($#ARGV < 0);
 
-$listingtype=$ARGV[0];
-$log_topdir=$ARGV[1];
+$log_topdir=$ARGV[0];
 scan_log();
 
-if ($listingtype eq "full") {
-	dump_class_refs_full();
-} elsif ($listingtype eq "last_seen") {
-	dump_class_refs_last_seen();
-} elsif ($listingtype eq "host_last_seen") {
-	dump_class_refs_host_last_seen();
-} else {
-	HELP_MESSAGE();
-}
+print join("\n",sort @lines);




More information about the Fai-commit mailing list