X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLxOfficeConf.pm;h=51ad991d916cfad4ed80d65233bef4320355c01a;hb=72be9c763f3b7f7df1fae4fe10011e45f9e2ad1d;hp=b0d801024c0056df8e9fd07ff0dffcd6cb2e19c1;hpb=3a94f4d2dd9a835d4a7007e1b999ea00b3c4e1cd;p=kivitendo-erp.git diff --git a/SL/LxOfficeConf.pm b/SL/LxOfficeConf.pm index b0d801024..51ad991d9 100644 --- a/SL/LxOfficeConf.pm +++ b/SL/LxOfficeConf.pm @@ -5,10 +5,24 @@ use strict; use Config::Std; use Encode; +my $environment_initialized; + sub read { - my $file = -f 'config/lx_office.conf' ? 'config/lx_office.conf' : 'config/lx_office.conf.default'; - read_config $file => %::lx_office_conf; + my ($class, $file_name) = @_; + + read_config 'config/lx_office.conf.default' => %::lx_office_conf; _decode_recursively(\%::lx_office_conf); + + $file_name ||= 'config/lx_office.conf'; + + if (-f $file_name) { + read_config $file_name => my %local_conf; + _decode_recursively(\%local_conf); + _flat_merge(\%::lx_office_conf, \%local_conf); + } + + _init_environment(); + _determine_application_paths(); } sub _decode_recursively { @@ -23,4 +37,57 @@ sub _decode_recursively { } } +sub _flat_merge { + my ($dst, $src) = @_; + + while (my ($key, $value) = each %{ $src }) { + if (!exists $dst->{$key}) { + $dst->{$key} = $value; + + } else { + map { $dst->{$key}->{$_} = $value->{$_} } keys %{ $value }; + } + } +} + +sub _init_environment { + return if $environment_initialized; + + my %key_map = ( lib => { name => 'PERL5LIB', append_path => 1 }, + path => { name => 'PATH', append_path => 1 }, + ); + my $cfg = $::lx_office_conf{environment} || {}; + + while (my ($key, $value) = each %{ $cfg }) { + next unless $value; + + my $info = $key_map{$key} || {}; + $key = $info->{name} || $key; + + if ($info->{append_path}) { + $value = ':' . $value unless $value =~ m/^:/ || !$ENV{$key}; + $value = $ENV{$key} . $value if $ENV{$key}; + } + + $ENV{$key} = $value; + } + + $environment_initialized = 1; +} + +sub _determine_application_paths { + my @paths = grep { $_ } split m/:/, $ENV{PATH}; + + foreach my $key (keys %{ $::lx_office_conf{applications} }) { + my ($program) = split m/\s+/, $::lx_office_conf{applications}->{$key}; + next if $program =~ m|/|; + + foreach my $path (@paths) { + next unless -f "${path}/${program}"; + $::lx_office_conf{applications}->{$key} = "${path}/" . $::lx_office_conf{applications}->{$key}; + last; + } + } +} + 1;