configDB: some code cleanup, documentation updated,

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@22340 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2020-07-03 11:01:06 +00:00
parent 0c41ae0bd7
commit 720162cbcc
2 changed files with 44 additions and 12 deletions

View File

@ -39,7 +39,7 @@ sub CommandConfigdb {
when ('attr') {
Log3('configdb', 4, "configdb: attr $param1 $param2 requested.");
if ($param1 eq "" && $param2 eq "") {
if ($param1 eq '' && $param2 eq '') {
# list attributes
foreach my $c (sort keys %{$configDB{attr}}) {
my $val = $configDB{attr}{$c};
@ -47,7 +47,19 @@ sub CommandConfigdb {
$val =~ s/\n/\\\n/g;
$ret .= "configdb attr $c $val\n";
}
} elsif($param2 eq "") {
} elsif(lc($param1) eq '?' || lc($param1) eq 'help') {
# list all available attributes
my $l = 0;
foreach my $c (sort keys %{$configDB{knownAttr}}) {
$l = length($c) > $l ? length($c) : $l;
}
foreach my $c (sort keys %{$configDB{knownAttr}}) {
my $val = $configDB{knownAttr}{$c};
$val =~ s/;/;;/g;
$val =~ s/\n/\\\n/g;
$ret .= sprintf("%-*s : ",$l,$c)."$val\n";
}
} elsif($param2 eq '') {
# delete attribute
delete $configDB{attr}{$param1};
$ret = " attribute $param1 deleted";
@ -68,8 +80,6 @@ sub CommandConfigdb {
when ('diff') {
return "\n Syntax: configdb diff <device> <version>" if @a != 3;
# return "Invalid paramaeter '$param1' for diff. Must be a number."
# unless looks_like_number($param1);
return "Invalid paramaeter '$param2' for diff. Must be a number."
unless (looks_like_number($param2) || $param2 eq 'current');
Log3('configdb', 4, "configdb: diff requested for device: $param1 in version $param2.");
@ -439,13 +449,7 @@ sub _cfgDB_readConfig() {
<br/>
<code> configdb attr</code> - show all defined attributes.<br/>
<br/>
<ul>Supported attributes:</ul>
<br/>
<ul><b>deleteimported</b> if set to 1 files will always be deleted from filesystem after import to database.<br/></ul><br/>
<ul><b>maxversions</b> set the maximum number of configurations stored in database. <br/>
The oldest version will be dropped in a "save config" if it would exceed this number.</ul><br/>
<ul><b>private</b> if set to 0 the database user and password info will be shown in 'configdb info' output.</ul><br/>
<ul><b>dumpPath</b> define a path for database dumps<br/></ul><br/>
<code> configdb attr ?|help</code> - show a list of available attributes.<br/>
<br/>
<li><code>configdb diff &lt;device&gt; &lt;version&gt;</code></li><br/>

View File

@ -149,6 +149,13 @@
#
# 2020-02-25 - added support weekprofile in automatic migration
#
# 2020-06-37 - added support for special strange readings (length check)
#
# 2020-06-29 - added support for mysqldump parameter by attribute
#
# 2020-07-02 - changed code cleanup after last changes (remove debug code)
# add "configdb attr ?" to show known attributes
#
##############################################################################
=cut
@ -207,6 +214,7 @@ sub _cfgDB_Search;
sub _cfgDB_Uuid;
sub _cfgDB_table_exists;
sub _cfgDB_dump;
sub _cfgDB_knownAttr;
##################################################
# Read configuration file for DB connection
@ -272,6 +280,8 @@ $configDB{attr}{nostate} = defined($dbconfig{nostate}) ? $dbconfig{nosta
$configDB{attr}{rescue} = defined($dbconfig{rescue}) ? $dbconfig{rescue} : 0;
$configDB{attr}{loadversion} = defined($dbconfig{loadversion}) ? $dbconfig{loadversion} : 0;
_cfgDB_knownAttr();
%dbconfig = ();
@config = ();
$configs = undef;
@ -538,7 +548,6 @@ sub cfgDB_SaveState {
$val =~ s/\n/\\\n/g;
$out = "setstate $d $rd->{TIME} $c $val";
if (length($out) > 65530) {
# if ($out =~ m/externalTest/) {
my $uid = _cfgDB_Uuid();
FileWrite($uid,$val);
$out = "setstate $d $rd->{TIME} $c cfgDBkey:$uid";
@ -1178,6 +1187,25 @@ sub _cfgDB_dump {
}
sub _cfgDB_knownAttr {
$configDB{knownAttr}{deleteimported} =
"(0|1) delete file from filesystem after import";
$configDB{knownAttr}{dumpPath} =
"(valid path) define path for database dump";
$configDB{knownAttr}{loadversion}=
"for internal use only";
$configDB{knownAttr}{maxversions}=
"(number) define maximum number of configurations stored in database";
$configDB{knownAttr}{mysqldump}=
"(valid parameter string) define additional parameters used for dump in mysql environment";
$configDB{knownAttr}{nostate}=
"for internal use only";
$configDB{knownAttr}{private}=
"(0|1) show or supress userdata in info output";
$configDB{knownAttr}{rescue}=
"for internal use only";
}
##################################################
# functions used for file handling
# called by 98_configdb.pm