From eabb327786fd0b08b5db107bbd409e37665fb9ba Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Wed, 16 Nov 2011 00:55:12 +0100 Subject: [PATCH] Remove all occurrences of 'sub readConfigurationFile' in bin/. Use the version from Xen::Tools::Common instead --- bin/xen-create-image | 86 ++------------------------------------------ bin/xen-delete-image | 78 ++-------------------------------------- bin/xen-list-images | 80 ++--------------------------------------- bin/xen-resize-guest | 81 ++--------------------------------------- bin/xen-update-image | 79 ++-------------------------------------- bin/xt-install-image | 86 ++------------------------------------------ 6 files changed, 14 insertions(+), 476 deletions(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index f5adf1a..449301c 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -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 = ) ) - { - chomp $line; - if ( $line =~ s/\\$// ) - { - $line .= ; - 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. diff --git a/bin/xen-delete-image b/bin/xen-delete-image index da58417..25087a6 100755 --- a/bin/xen-delete-image +++ b/bin/xen-delete-image @@ -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 = ) ) - { - chomp $line; - if ( $line =~ s/\\$// ) - { - $line .= ; - 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 diff --git a/bin/xen-list-images b/bin/xen-list-images index d54abf4..85554f4 100755 --- a/bin/xen-list-images +++ b/bin/xen-list-images @@ -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 = ) ) - { - chomp $line; - if ( $line =~ s/\\$// ) - { - $line .= ; - 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. diff --git a/bin/xen-resize-guest b/bin/xen-resize-guest index 95acf56..1868a5f 100755 --- a/bin/xen-resize-guest +++ b/bin/xen-resize-guest @@ -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 = ) ) - { - chomp $line; - if ( $line =~ s/\\$// ) - { - $line .= ; - 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. diff --git a/bin/xen-update-image b/bin/xen-update-image index 004ee81..5f57a28 100755 --- a/bin/xen-update-image +++ b/bin/xen-update-image @@ -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 = ) ) - { - chomp $line; - if ( $line =~ s/\\$// ) - { - $line .= ; - 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. diff --git a/bin/xt-install-image b/bin/xt-install-image index cdac40a..434792f 100755 --- a/bin/xt-install-image +++ b/bin/xt-install-image @@ -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 = ) ) - { - chomp $line; - if ( $line =~ s/\\$// ) - { - $line .= ; - 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.