[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Additional checking of conf files
From: |
Lyndon C. Lim |
Subject: |
Additional checking of conf files |
Date: |
Tue, 28 Sep 2004 16:30:45 -0700 |
I wrote the little Perl script below,
to help me check that my config files
are consistent with their definitions
and references of classes.
Its usefulness depends much on your
specific style. But, you can probably
modify it to match how you write your
config files.
Hope somebody finds it helpful.
#!/usr/bin/perl
########################################################################
#
# checkConf.pl - Sanity check for cfengine configuration files.
#
########################################################################
#
# $Id: checkConf.pl,v 1.1 2004/09/28 20:41:37 lyndon Exp $
# $Source: /nfs/cad-root/ECS/conf/RCS/checkConf.pl,v $
#
########################################################################
# Libraries
########################################################################
# ({[
use strict;
use English;
use FileHandle;
########################################################################
# Functions
########################################################################
# function: uniq
# purpose: Given an array, return an array with unique values.
# args: @values - array, list of scalars.
# returns: array - redundant values removed.
# example: uniq(1, 2, 3, "a", "a")
#
sub uniq(@) {
my(@list) = @ARG;
my($member, %values);
foreach $member (@list) {
$values{$member} = 1;
}
return(sort(keys(%values)));
}
########################################################################
# Main
########################################################################
MAIN: {
my($buf, %defined, $fh, $flag, $inputFile, %installed, @keys,
%referenced, $tmp);
$inputFile = $ARGV[0];
$fh = FileHandle::new();
$fh->open("< $inputFile") or die("Unable to open $inputFile");
$flag = 0;
while ($buf = <$fh>) {
chomp($buf);
SWITCH: {
# Process addInstallable classes
if ($buf =~ /addInstallable/) {
$flag = 1;
last(SWITCH);
}
if ($buf =~ /\)/) {
$flag = 0;
last(SWITCH);
}
if ($flag) {
$buf =~ s/ //g;
$installed{$buf} = 1;
}
# Process classes defined in copy
if ($buf =~ /define=/) {
($tmp, $buf) = split('=', $buf);
$referenced{$buf} = 1;
last(SWITCH);
}
# Process class definitions
if ($buf =~ /[^:]*::/) {
$buf =~ s/[ :]*//g;
$defined{$buf} = 1;
last(SWITCH);
}
}
}
$fh->close();
@keys = keys(%installed);
push(@keys, keys(%referenced));
push(@keys, keys(%defined));
@keys = uniq(@keys);
foreach $buf (@keys) {
if (exists($defined{$buf}) && !exists($referenced{$buf})) {
printf("%-20s is defined but not referenced.\n", $buf);
}
if (exists($defined{$buf}) && !exists($installed{$buf}) ) {
printf("%-20s is defined but not installed.\n", $buf);
}
if (exists($referenced{$buf}) && !exists($defined{$buf}) ) {
printf("%-20s is referenced but not defined.\n", $buf);
}
if (exists($referenced{$buf}) && !exists($installed{$buf}) ) {
printf("%-20s is referenced but not installed.\n", $buf);
}
if (exists($installed{$buf}) && !exists($defined{$buf}) ) {
printf("%-20s is installed but not defined.\n", $buf);
}
if (exists($installed{$buf}) && !exists($referenced{$buf})) {
printf("%20s is installed but not referenced.\n", $buf);
}
}
}
# ]})
# end
--
Lyndon C. Lim; lyndon@artisan.com; 408.734.5600; 408.734.5050 (fax)
Artisan Components; 141 Caspian Court; Sunnyvale, CA 94089-1013; USA
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Additional checking of conf files,
Lyndon C. Lim <=