summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOliver Tappe2007-07-21 21:16:57 +0200
committerOliver Tappe2007-07-21 21:16:57 +0200
commitd5d920e992c24e5bce65e2a95f5c1d95dd41405e (patch)
treea757da40246e3be48b6fb85b28fa70fe72d6b066 /lib
parent* minor cleanup (two uninit values) (diff)
downloadcore-d5d920e992c24e5bce65e2a95f5c1d95dd41405e.tar.gz
core-d5d920e992c24e5bce65e2a95f5c1d95dd41405e.tar.xz
core-d5d920e992c24e5bce65e2a95f5c1d95dd41405e.zip
* 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
Diffstat (limited to 'lib')
-rw-r--r--lib/OpenSLX/Basics.pm30
1 files changed, 11 insertions, 19 deletions
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