mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
configDB.pm: improve config file read
git-svn-id: https://svn.fhem.de/fhem/trunk@11762 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
139fd9df05
commit
e20758ec1c
@ -1,5 +1,6 @@
|
|||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
|
=pod
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# configDB.pm
|
# configDB.pm
|
||||||
@ -115,18 +116,18 @@
|
|||||||
# added configdb dump (for postgresql)
|
# added configdb dump (for postgresql)
|
||||||
#
|
#
|
||||||
# 2016-07-03 - added support for multiple hosts (experimental)
|
# 2016-07-03 - added support for multiple hosts (experimental)
|
||||||
#
|
|
||||||
# 2016-07-04 - fixed improve config file read
|
# 2016-07-04 - fixed improve config file read
|
||||||
|
# 2016-07-07 - bugfix select configuration
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
=cut
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Text::Diff;
|
use Text::Diff;
|
||||||
use DBI;
|
use DBI;
|
||||||
use Sys::Hostname;
|
use Sys::Hostname;
|
||||||
use Data::Dumper;
|
#use Data::Dumper;
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# Forward declarations for functions in fhem.pl
|
# Forward declarations for functions in fhem.pl
|
||||||
@ -187,7 +188,8 @@ if(!open(CONFIG, 'configDB.conf')) {
|
|||||||
my @config;
|
my @config;
|
||||||
while (<CONFIG>){
|
while (<CONFIG>){
|
||||||
my $line = $_;
|
my $line = $_;
|
||||||
$line =~ s/^\s+|\s+$//g;
|
$line =~ s/^\s+|\s+$//g; # remove whitespaces etc.
|
||||||
|
$line =~ s/;$/;;/; # duplicate ; at end-of-line
|
||||||
push (@config,$line) if($line !~ m/^#/ && length($line) > 0);
|
push (@config,$line) if($line !~ m/^#/ && length($line) > 0);
|
||||||
}
|
}
|
||||||
close CONFIG;
|
close CONFIG;
|
||||||
@ -195,28 +197,23 @@ close CONFIG;
|
|||||||
use vars qw(%configDB);
|
use vars qw(%configDB);
|
||||||
|
|
||||||
my %dbconfig;
|
my %dbconfig;
|
||||||
##eval join("", @config);
|
|
||||||
|
|
||||||
## begin experimental
|
my $configs = join("",@config);
|
||||||
## support multiple hosts from one fhem installation
|
my @configs = split(/;;/,$configs);
|
||||||
##
|
my $count = @configs;
|
||||||
my $configs = join("",@config);
|
my $fhemhost = hostname;
|
||||||
my @configs = split(/;\n/,$configs);
|
|
||||||
my $count = @configs;
|
|
||||||
|
|
||||||
if ($count > 1) {
|
if ($count > 1) {
|
||||||
my $fhemhost = hostname;
|
|
||||||
foreach my $c (@configs) {
|
foreach my $c (@configs) {
|
||||||
next unless $c =~ m/^%dbconfig.*/;
|
next unless $c =~ m/^%dbconfig.*/;
|
||||||
|
$dbconfig{fhemhost} = "";
|
||||||
eval $c;
|
eval $c;
|
||||||
last if ($dbconfig{fhemhost} eq $fhemhost);
|
last if ($dbconfig{fhemhost} eq $fhemhost);
|
||||||
}
|
}
|
||||||
eval $configs[0] unless (defined($dbconfig{fhemhost}) && length($dbconfig{fhemhost}))
|
eval $configs[0] if ($dbconfig{fhemhost} eq "");
|
||||||
} else {
|
} else {
|
||||||
eval $configs[0];
|
eval $configs[0];
|
||||||
}
|
}
|
||||||
##
|
|
||||||
## end experimental
|
|
||||||
|
|
||||||
my $cfgDB_dbconn = $dbconfig{connection};
|
my $cfgDB_dbconn = $dbconfig{connection};
|
||||||
my $cfgDB_dbuser = $dbconfig{user};
|
my $cfgDB_dbuser = $dbconfig{user};
|
||||||
@ -225,6 +222,8 @@ my $cfgDB_dbtype;
|
|||||||
|
|
||||||
%dbconfig = ();
|
%dbconfig = ();
|
||||||
@config = ();
|
@config = ();
|
||||||
|
$configs = undef;
|
||||||
|
$count = undef;
|
||||||
|
|
||||||
if($cfgDB_dbconn =~ m/pg:/i) {
|
if($cfgDB_dbconn =~ m/pg:/i) {
|
||||||
$cfgDB_dbtype ="POSTGRESQL";
|
$cfgDB_dbtype ="POSTGRESQL";
|
||||||
@ -237,7 +236,7 @@ if($cfgDB_dbconn =~ m/pg:/i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$configDB{attr}{nostate} = 1 if($ENV{'cfgDB_nostate'});
|
$configDB{attr}{nostate} = 1 if($ENV{'cfgDB_nostate'});
|
||||||
$configDB{attr}{rescue} = 1 if($ENV{'cfgDB_rescue'});
|
$configDB{attr}{rescue} = 1 if($ENV{'cfgDB_rescue'});
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# Basic functions needed for DB configuration
|
# Basic functions needed for DB configuration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user