1
0
mirror of synced 2026-01-18 00:42:31 +00:00

Remove all occurrences of 'sub readConfigurationFile' in bin/.

Use the version from Xen::Tools::Common instead
This commit is contained in:
Axel Beckert 2011-11-16 00:55:12 +01:00
parent 8835b9134b
commit eabb327786
6 changed files with 14 additions and 476 deletions

View File

@ -765,6 +765,7 @@ use File::Temp qw/ tempdir /;
use File::Copy qw/ mv cp /;
use Getopt::Long;
use Pod::Usage;
use Xen::Tools::Common;
@ -829,7 +830,7 @@ setupDefaultOptions();
#
# Read the global configuration file.
#
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
readConfigurationFile("/etc/xen-tools/xen-tools.conf", \%CONFIG);
#
@ -854,7 +855,7 @@ if ( $CONFIG{ 'config' } )
# Read the file, if it exists.
if ( -e $path )
{
readConfigurationFile($path);
readConfigurationFile($path, \%CONFIG);
}
else
{
@ -1432,87 +1433,6 @@ sub setupDefaultOptions
=begin doc
Read the specified configuration file, and update our global configuration
hash with the values found in it.
=end doc
=cut
sub readConfigurationFile
{
my ($file) = (@_);
# Don't read the file if it doesn't exist.
return if ( !-e $file );
my $line = "";
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
while ( defined( $line = <FILE> ) )
{
chomp $line;
if ( $line =~ s/\\$// )
{
$line .= <FILE>;
redo unless eof(FILE);
}
# Skip lines beginning with comments
next if ( $line =~ /^([ \t]*)\#/ );
# Skip blank lines
next if ( length($line) < 1 );
# Strip trailing comments.
if ( $line =~ /(.*)\#(.*)/ )
{
$line = $1;
}
# Find variable settings
if ( $line =~ /([^=]+)=([^\n]+)/ )
{
my $key = $1;
my $val = $2;
# Strip leading and trailing whitespace.
$key =~ s/^\s+//;
$key =~ s/\s+$//;
$val =~ s/^\s+//;
$val =~ s/\s+$//;
# command expansion?
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
{
# store
my $pre = $1;
my $cmd = $2;
my $post = $3;
# get output
my $output = `$cmd`;
chomp($output);
# build up replacement.
$val = $pre . $output . $post;
}
# Store value.
$CONFIG{ $key } = $val;
}
}
close(FILE);
}
=begin doc
Validate options and do what is necessary with them.

View File

@ -158,6 +158,7 @@ use English;
use Getopt::Long;
use Pod::Usage;
use File::Path;
use Xen::Tools::Common;
#
@ -180,7 +181,7 @@ my $RELEASE = '4.2.1+dev';
#
if ( -e "/etc/xen-tools/xen-tools.conf" )
{
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
readConfigurationFile("/etc/xen-tools/xen-tools.conf", \%CONFIG);
}
@ -253,81 +254,6 @@ exit 0;
=begin doc
Read the configuration file specified.
=end doc
=cut
sub readConfigurationFile
{
my ($file) = (@_);
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
my $line = "";
while ( defined( $line = <FILE> ) )
{
chomp $line;
if ( $line =~ s/\\$// )
{
$line .= <FILE>;
redo unless eof(FILE);
}
# Skip lines beginning with comments
next if ( $line =~ /^([ \t]*)\#/ );
# Skip blank lines
next if ( length($line) < 1 );
# Strip trailing comments.
if ( $line =~ /(.*)\#(.*)/ )
{
$line = $1;
}
# Find variable settings
if ( $line =~ /([^=]+)=([^\n]+)/ )
{
my $key = $1;
my $val = $2;
# Strip leading and trailing whitespace.
$key =~ s/^\s+//;
$key =~ s/\s+$//;
$val =~ s/^\s+//;
$val =~ s/\s+$//;
# command expansion?
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
{
# store
my $pre = $1;
my $cmd = $2;
my $post = $3;
# get output
my $output = `$cmd`;
chomp($output);
# build up replacement.
$val = $pre . $output . $post;
}
# Store value.
$CONFIG{ $key } = $val;
}
}
close(FILE);
}
=begin doc

View File

@ -83,6 +83,7 @@ use English;
use File::Temp qw/ tempdir /;
use Getopt::Long;
use Pod::Usage;
use Xen::Tools::Common;
#
@ -108,7 +109,7 @@ my $RELEASE = '4.2.1+dev';
#
# Read the global configuration file if it exists.
#
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
readConfigurationFile("/etc/xen-tools/xen-tools.conf", \%CONFIG);
#
@ -144,83 +145,6 @@ exit;
=begin doc
Read the configuration file specified.
=end doc
=cut
sub readConfigurationFile
{
my ($file) = (@_);
# Don't read the file if it doesn't exist.
return if ( !-e $file );
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
while ( defined( my $line = <FILE> ) )
{
chomp $line;
if ( $line =~ s/\\$// )
{
$line .= <FILE>;
redo unless eof(FILE);
}
# Skip lines beginning with comments
next if ( $line =~ /^([ \t]*)\#/ );
# Skip blank lines
next if ( length($line) < 1 );
# Strip trailing comments.
if ( $line =~ /(.*)\#(.*)/ )
{
$line = $1;
}
# Find variable settings
if ( $line =~ /([^=]+)=([^\n]+)/ )
{
my $key = $1;
my $val = $2;
# Strip leading and trailing whitespace.
$key =~ s/^\s+//;
$key =~ s/\s+$//;
$val =~ s/^\s+//;
$val =~ s/\s+$//;
# command expansion?
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
{
# store
my $pre = $1;
my $cmd = $2;
my $post = $3;
# get output
my $output = `$cmd`;
chomp($output);
# build up replacement.
$val = $pre . $output . $post;
}
# Store value.
$CONFIG{ $key } = $val;
}
}
close(FILE);
}
=begin doc
Parse the arguments specified upon the command line.

View File

@ -104,6 +104,7 @@ use Env;
use Getopt::Long;
use Pod::Usage;
use Text::Template;
use Xen::Tools::Common;
@ -123,7 +124,7 @@ my $RELEASE = '4.2.1+dev';
#
# Read the global configuration file.
#
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
readConfigurationFile("/etc/xen-tools/xen-tools.conf", \%CONFIG);
#
@ -289,84 +290,6 @@ exit 0;
=begin doc
Read the configuration file specified.
=end doc
=cut
sub readConfigurationFile
{
my ($file) = (@_);
# Don't read the file if it doesn't exist.
return if ( !-e $file );
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
my $line = "";
while ( defined( $line = <FILE> ) )
{
chomp $line;
if ( $line =~ s/\\$// )
{
$line .= <FILE>;
redo unless eof(FILE);
}
# Skip lines beginning with comments
next if ( $line =~ /^([ \t]*)\#/ );
# Skip blank lines
next if ( length($line) < 1 );
# Strip trailing comments.
if ( $line =~ /(.*)\#(.*)/ )
{
$line = $1;
}
# Find variable settings
if ( $line =~ /([^=]+)=([^\n]+)/ )
{
my $key = $1;
my $val = $2;
# Strip leading and trailing whitespace.
$key =~ s/^\s+//;
$key =~ s/\s+$//;
$val =~ s/^\s+//;
$val =~ s/\s+$//;
# command expansion?
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
{
# store
my $pre = $1;
my $cmd = $2;
my $post = $3;
# get output
my $output = `$cmd`;
chomp($output);
# build up replacement.
$val = $pre . $output . $post;
}
# Store value.
$CONFIG{ $key } = $val;
}
}
close(FILE);
}
=begin doc
Parse the command line arguments this script was given.

View File

@ -107,6 +107,7 @@ use File::Temp qw/ tempdir /;
use File::Copy qw/ mv cp /;
use Getopt::Long;
use Pod::Usage;
use Xen::Tools::Common;
#
@ -128,7 +129,7 @@ my $RELEASE = '4.2.1+dev';
#
if ( -e "/etc/xen-tools/xen-tools.conf" )
{
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
readConfigurationFile("/etc/xen-tools/xen-tools.conf", \%CONFIG);
}
@ -359,82 +360,6 @@ sub xenRunning
=begin doc
Read the configuration file specified.
=end doc
=cut
sub readConfigurationFile
{
my ($file) = (@_);
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
my $line = "";
while ( defined( $line = <FILE> ) )
{
chomp $line;
if ( $line =~ s/\\$// )
{
$line .= <FILE>;
redo unless eof(FILE);
}
# Skip lines beginning with comments
next if ( $line =~ /^([ \t]*)\#/ );
# Skip blank lines
next if ( length($line) < 1 );
# Strip trailing comments.
if ( $line =~ /(.*)\#(.*)/ )
{
$line = $1;
}
# Find variable settings
if ( $line =~ /([^=]+)=([^\n]+)/ )
{
my $key = $1;
my $val = $2;
# Strip leading and trailing whitespace.
$key =~ s/^\s+//;
$key =~ s/\s+$//;
$val =~ s/^\s+//;
$val =~ s/\s+$//;
# command expansion?
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
{
# store
my $pre = $1;
my $cmd = $2;
my $post = $3;
# get output
my $output = `$cmd`;
chomp($output);
# build up replacement.
$val = $pre . $output . $post;
}
# Store value.
$CONFIG{ $key } = $val;
}
}
close(FILE);
}
=begin doc
Parse the arguments specified upon the command line.

View File

@ -107,6 +107,7 @@ use Env;
use File::Copy;
use Getopt::Long;
use Pod::Usage;
use Xen::Tools::Common;
#
@ -155,7 +156,7 @@ my %dispatch = (
#
# Read the global configuration file.
#
readConfigurationFile("/etc/xen-tools/xen-tools.conf");
readConfigurationFile("/etc/xen-tools/xen-tools.conf", \%CONFIG);
#
@ -178,7 +179,7 @@ if ( $CONFIG{ 'config' } )
}
# Read the file, if it exists.
readConfigurationFile($path) if ( -e $path );
readConfigurationFile($path, \%CONFIG) if ( -e $path );
}
@ -279,87 +280,6 @@ else
=begin doc
Read the specified configuration file, and update our global configuration
hash with the values found in it.
=end doc
=cut
sub readConfigurationFile
{
my ($file) = (@_);
# Don't read the file if it doesn't exist.
return if ( !-e $file );
my $line = "";
open( FILE, "<", $file ) or die "Cannot read file '$file' - $!";
while ( defined( $line = <FILE> ) )
{
chomp $line;
if ( $line =~ s/\\$// )
{
$line .= <FILE>;
redo unless eof(FILE);
}
# Skip lines beginning with comments
next if ( $line =~ /^([ \t]*)\#/ );
# Skip blank lines
next if ( length($line) < 1 );
# Strip trailing comments.
if ( $line =~ /(.*)\#(.*)/ )
{
$line = $1;
}
# Find variable settings
if ( $line =~ /([^=]+)=([^\n]+)/ )
{
my $key = $1;
my $val = $2;
# Strip leading and trailing whitespace.
$key =~ s/^\s+//;
$key =~ s/\s+$//;
$val =~ s/^\s+//;
$val =~ s/\s+$//;
# command expansion?
if ( $val =~ /(.*)`([^`]+)`(.*)/ )
{
# store
my $pre = $1;
my $cmd = $2;
my $post = $3;
# get output
my $output = `$cmd`;
chomp($output);
# build up replacement.
$val = $pre . $output . $post;
}
# Store value.
$CONFIG{ $key } = $val;
}
}
close(FILE);
}
=begin doc
Parse the command line arguments this script was given.