From d5d920e992c24e5bce65e2a95f5c1d95dd41405e Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 21 Jul 2007 19:16:57 +0000 Subject: * first part of configuration file migration to Config::General git-svn-id: http://svn.openslx.org/svn/openslx/trunk@1268 95ad53e4-c205-0410-b2fa-d234c58c8868 --- lib/OpenSLX/Basics.pm | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/OpenSLX/Basics.pm b/lib/OpenSLX/Basics.pm index 4c3bf49c..fb7db676 100644 --- a/lib/OpenSLX/Basics.pm +++ b/lib/OpenSLX/Basics.pm @@ -50,6 +50,7 @@ use Carp::Heavy; # use it here to have it loaded immediately, not at # be at a point in time where the script executes in # a chrooted environment, such that the module can't # be loaded anymore). +use Config::General; use Encode; require File::Glob; use FindBin; @@ -160,38 +161,29 @@ sub openslxInit my $configPath = $cmdlineConfig{'config-path'} || $openslxConfig{'config-path'}; my $sharePath = "$openslxConfig{'base-path'}/share"; - my $configFH; my $verboseLevel = $cmdlineConfig{'verbose-level'} || 0; foreach my $f ("$sharePath/settings.default", "$configPath/settings", "$ENV{HOME}/.openslx/settings") { - next unless open($configFH, '<', $f); + next unless -e $f; if ($verboseLevel >= 2) { vlog(0, "reading config-file $f..."); } - while (<$configFH>) { - chomp; - s/#.*//; - s/^\s+//; - s/\s+$//; - next unless length; - if (!/^(\w+)=(.*)$/) { - die _tr("config-file <%s> has incorrect syntax here:\n\t%s\n", - $f, $_); - } - my ($key, $value) = ($1, $2); - - # N.B.: the config files are used by shell-scripts, too, so in + my %config = ParseConfig( + -ConfigFile => $f, -AutoTrue => 1, -LowerCaseNames => 1 + ); + foreach my $key (keys %config) { + # N.B.: these config files are used by shell-scripts, too, so in # order to comply with shell-style, the config files use shell # syntax and an uppercase, underline-as-separator format. # Internally, we use lowercase, minus-as-separator format, so we # need to convert the environment variable names to our own # internal style here (e.g. 'SLX_BASE_PATH' to 'base-path'): - $key =~ s[^SLX_][]; - $key =~ tr/[A-Z]_/[a-z]-/; - $openslxConfig{$key} = $value; + my $ourKey = $key; + $ourKey =~ s[^slx_][]; + $ourKey =~ tr/_/-/; + $openslxConfig{$ourKey} = $config{$key}; } - close $configFH; } # push any cmdline argument into our config hash, possibly overriding any -- cgit v1.2.3-55-g7522