98_update.pm: simplify updateInBackground logging (Forum #47203)

git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@10551 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2016-01-17 11:03:44 +00:00
parent f68b0ea9e0
commit bf40a96a3a
8 changed files with 86 additions and 66 deletions

View File

@@ -1,12 +1,11 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- feature: update is executed per default in the background
- bugfix: FB_CALLLIST: fix "Use of uninitialized value" warnings on startup - bugfix: FB_CALLLIST: fix "Use of uninitialized value" warnings on startup
- feature: 2016-01-17 - *** - feature: *** 2016-01-17
*** Do not worry about a lot of updates. Many *** Do not worry about a lot of updates. Many modules were
*** modules were modified only to support the *** modified only to support the new commandref mechanism for
*** new commandref mechanism for automatic *** automatic classification of helper and command modules.
*** classification of helper and command modules.
***
- change: 49_SSCam: Change of define-string related to rectime. - change: 49_SSCam: Change of define-string related to rectime.
Note: see all changes of rectime usage in commandref Note: see all changes of rectime usage in commandref
or in Forum: or in Forum:

View File

@@ -2001,10 +2001,11 @@ FW_style($$)
FW_pO "<script type=\"text/javascript\" src=\"$FW_ME/pgm2/console.js\">". FW_pO "<script type=\"text/javascript\" src=\"$FW_ME/pgm2/console.js\">".
"</script>"; "</script>";
FW_pO "<div id=\"content\">"; FW_pO "<div id=\"content\">";
my $filter = ($a[2] && $a[2] ne "1") ? $a[2] : ".*"; my $filter = ($a[2] && $a[2] ne "log") ? $a[2] : ".*";
FW_pO "Events (Filter: <a href=\"#\" id=\"eventFilter\">$filter</a>) ". FW_pO "Events (Filter: <a href=\"#\" id=\"eventFilter\">$filter</a>) ".
"&nbsp;&nbsp;<span class='changed'>FHEM log ". "&nbsp;&nbsp;<span class='fhemlog'>FHEM log ".
"<input id='eventWithLog' type='checkbox'></span>". "<input id='eventWithLog' type='checkbox'".
($a[2] && $a[2] eq "log" ? " checked":"")."></span>".
"&nbsp;&nbsp;<button id='eventReset'>Reset</button><br><br>\n"; "&nbsp;&nbsp;<button id='eventReset'>Reset</button><br><br>\n";
FW_pO "<div id=\"console\"></div>"; FW_pO "<div id=\"console\"></div>";
FW_pO "</div>"; FW_pO "</div>";
@@ -2482,7 +2483,7 @@ FW_logInform($$)
return; return;
} }
$msg = FW_htmlEscape($msg); $msg = FW_htmlEscape($msg);
if(!addToWritebuffer($ntfy, "<div class='changed'>$msg</div>") ){ if(!addToWritebuffer($ntfy, "<div class='fhemlog'>$msg</div>") ){
TcpServer_Close($ntfy); TcpServer_Close($ntfy);
delete $logInform{$me}; delete $logInform{$me};
delete $defs{$me}; delete $defs{$me};

View File

@@ -26,11 +26,14 @@ telnet_Initialize($)
"encoding:utf8,latin1 sslVersion"; "encoding:utf8,latin1 sslVersion";
$hash->{ActivateInformFn} = "telnet_ActivateInform"; $hash->{ActivateInformFn} = "telnet_ActivateInform";
my %lhash = ( Fn=>"CommandTelnetEncoding", $cmds{encoding} = { Fn=>"CommandTelnetEncoding",
ClientFilter => "telnet", ClientFilter => "telnet",
Hlp=>"[utf8|latin1],query and set the character encoding ". Hlp=>"[utf8|latin1],query and set the character encoding ".
"for the current telnet session" ); "for the current telnet session" };
$cmds{encoding} = \%lhash;
$cmds{inform} = { Fn=>"CommandTelnetInform",
ClientFilter => "telnet",
Hlp=>"{on|off|log|raw|timer|status},echo all events to this client" };
} }
sub sub
@@ -348,16 +351,59 @@ sub
telnet_Undef($$) telnet_Undef($$)
{ {
my ($hash, $arg) = @_; my ($hash, $arg) = @_;
delete($logInform{$hash->{NAME}});
delete($inform{$hash->{NAME}});
return TcpServer_Close($hash); return TcpServer_Close($hash);
} }
#####################################
sub sub
telnet_ActivateInform($;$) CommandTelnetInform($$)
{ {
my ($cl, $arg) = @_; my ($cl, $param) = @_;
return if(!$cl);
my $name = $cl->{NAME}; my $name = $cl->{NAME};
$arg = "" if(!defined($arg));
CommandInform($cl, "timer $arg") if(!$inform{$name}); return "Usage: inform {on|off|raw|timer|log|status} [regexp]"
if($param !~ m/^(on|off|raw|timer|log|status)/);
if($param eq "status") {
my $i = $inform{$name};
return $i ? ($i->{type} . ($i->{regexp} ? " ".$i->{regexp} : "")) : "off";
}
if($param eq "off") {
delete($logInform{$name});
delete($inform{$name});
} elsif($param eq "log") {
$logInform{$name} = sub($$){
my ($me, $msg) = @_; # _NO_ Log3 here!
telnet_Output($defs{$me}, $msg."\n");
}
} elsif($param ne "off") {
my ($type, $regexp) = split(" ", $param);
$inform{$name}{NR} = $cl->{NR};
$inform{$name}{type} = $type;
if($regexp) {
eval { "Hallo" =~ m/$regexp/ };
return "Bad regexp: $@" if($@);
$inform{$name}{regexp} = $regexp;
}
Log 4, "Setting inform to $param";
}
return undef;
}
sub
telnet_ActivateInform($)
{
my ($cl) = @_;
CommandTelnetInform($cl, "log");
} }

View File

@@ -25,6 +25,7 @@ my $updArg;
my $mainPgm = "/fhem.pl\$"; my $mainPgm = "/fhem.pl\$";
my %upd_connecthash; my %upd_connecthash;
my $upd_needJoin; my $upd_needJoin;
my $upd_nChanged;
######################################## ########################################
@@ -64,11 +65,11 @@ CommandUpdate($$)
if($arg =~ m/^[-\?\*]/ || $ret); if($arg =~ m/^[-\?\*]/ || $ret);
$arg = lc($arg) if($arg =~ m/^(check|all|force)$/i); $arg = lc($arg) if($arg =~ m/^(check|all|force)$/i);
$updateInBackground = AttrVal("global","updateInBackground",undef); $updateInBackground = AttrVal("global","updateInBackground",1);
$updateInBackground = 0 if($arg ne "all"); $updateInBackground = 0 if($arg ne "all");
$updArg = $arg; $updArg = $arg;
if($updateInBackground) { if($updateInBackground) {
CallFn($cl->{NAME}, "ActivateInformFn", $cl, "global"); CallFn($cl->{NAME}, "ActivateInformFn", $cl, "log");
BlockingCall("doUpdateInBackground", {src=>$src,arg=>$arg}); BlockingCall("doUpdateInBackground", {src=>$src,arg=>$arg});
return "Executing the update the background."; return "Executing the update the background.";
@@ -167,7 +168,6 @@ update_Log2Event($$)
return if($inLog || $level > $attr{global}{verbose}); return if($inLog || $level > $attr{global}{verbose});
$inLog = 1; $inLog = 1;
$text =~ s/\n/ /g; # Multiline text causes havoc in Analyze $text =~ s/\n/ /g; # Multiline text causes havoc in Analyze
BlockingInformParent("DoTrigger", ["global", $text, 1], 0);
BlockingInformParent("Log", [$level, $text], 0); BlockingInformParent("Log", [$level, $text], 0);
$inLog = 0; $inLog = 0;
} }
@@ -189,6 +189,7 @@ doUpdateLoop($$)
my ($src, $arg) = @_; my ($src, $arg) = @_;
$upd_needJoin = 0; $upd_needJoin = 0;
$upd_nChanged = 0;
if($src =~ m/^http.*/) { if($src =~ m/^http.*/) {
doUpdate(1,1, $src, $arg); doUpdate(1,1, $src, $arg);
HttpUtils_Close(\%upd_connecthash); HttpUtils_Close(\%upd_connecthash);
@@ -233,7 +234,8 @@ doUpdate($$$$)
$ctrlFileName =~ m/controls_(.*).txt/; $ctrlFileName =~ m/controls_(.*).txt/;
my $srcName = $1; my $srcName = $1;
if(AttrVal("global", "backup_before_update", 0) && $arg ne "check" && $curr==1) { if(AttrVal("global", "backup_before_update", 0) &&
$arg ne "check" && $curr==1) {
my $cmdret = AnalyzeCommand(undef, "backup"); my $cmdret = AnalyzeCommand(undef, "backup");
if ($cmdret !~ m/backup done.*/) { if ($cmdret !~ m/backup done.*/) {
uLog 1, "Something went wrong during backup: $cmdret"; uLog 1, "Something went wrong during backup: $cmdret";
@@ -391,7 +393,8 @@ doUpdate($$$$)
} }
} }
return "" if(!$nChanged); $upd_nChanged += $nChanged;
return "" if(!$upd_nChanged);
uLog(1, ""); uLog(1, "");
if($curr == $max) { if($curr == $max) {
@@ -658,7 +661,7 @@ upd_initRestoreDirs($)
If this attribute is set (to 1), the update will be executed in a If this attribute is set (to 1), the update will be executed in a
background process. The return message is communicated via events, and background process. The return message is communicated via events, and
in telnet the inform command is activated, in FHEMWEB the Event in telnet the inform command is activated, in FHEMWEB the Event
Monitor. Monitor. Default is set. Set it to 0 to switch it off.
</li><br> </li><br>
<a name="updateNoFileCheck"></a> <a name="updateNoFileCheck"></a>
@@ -760,7 +763,8 @@ upd_initRestoreDirs($)
Wenn dieses Attribut gesetzt ist, wird das update Befehl in einem Wenn dieses Attribut gesetzt ist, wird das update Befehl in einem
separaten Prozess ausgef&uuml;hrt, und alle Meldungen werden per Event separaten Prozess ausgef&uuml;hrt, und alle Meldungen werden per Event
&uuml;bermittelt. In der telnet Sitzung wird inform, in FHEMWEB wird &uuml;bermittelt. In der telnet Sitzung wird inform, in FHEMWEB wird
das Event Monitor aktiviert. das Event Monitor aktiviert. Die Voreinstellung ist an, zum
Deaktivieren bitte Attribut auf 0 setzen.
</li><br> </li><br>
<a name="updateNoFileCheck"></a> <a name="updateNoFileCheck"></a>

View File

@@ -139,7 +139,6 @@ sub CommandDisplayAttr($$);
sub CommandGet($$); sub CommandGet($$);
sub CommandIOWrite($$); sub CommandIOWrite($$);
sub CommandInclude($$); sub CommandInclude($$);
sub CommandInform($$);
sub CommandList($$); sub CommandList($$);
sub CommandModify($$); sub CommandModify($$);
sub CommandQuit($$); sub CommandQuit($$);
@@ -333,9 +332,6 @@ $readingFnAttributes = "event-on-change-reading event-on-update-reading ".
Hlp=>"<devspec> <type dependent>,request data from <devspec>" }, Hlp=>"<devspec> <type dependent>,request data from <devspec>" },
"include" => { Fn=>"CommandInclude", "include" => { Fn=>"CommandInclude",
Hlp=>"<filename>,read the commands from <filenname>" }, Hlp=>"<filename>,read the commands from <filenname>" },
"inform" => { Fn=>"CommandInform",
ClientFilter => "telnet",
Hlp=>"{on|off|raw|timer|status},echo all events to this client" },
"iowrite" => { Fn=>"CommandIOWrite", "iowrite" => { Fn=>"CommandIOWrite",
Hlp=>"<iodev> <data>,write raw data with iodev" }, Hlp=>"<iodev> <data>,write raw data with iodev" },
"list" => { Fn=>"CommandList", "list" => { Fn=>"CommandList",
@@ -498,7 +494,7 @@ if(time() < 2*3600) {
require RTypes; require RTypes;
RTypes_Initialize(); RTypes_Initialize();
my $cfgErrMsg = "Error messages while initializing FHEM:"; my $cfgErrMsg = "Messages collected while initializing FHEM:";
my $cfgRet=""; my $cfgRet="";
if(configDBUsed()) { if(configDBUsed()) {
my $ret = cfgDB_ReadAll(undef); my $ret = cfgDB_ReadAll(undef);
@@ -838,7 +834,11 @@ Log3($$$)
no strict "refs"; no strict "refs";
foreach my $li (keys %logInform) { foreach my $li (keys %logInform) {
if($defs{$li}) {
&{$logInform{$li}}($li, "$tim $loglevel : $text"); &{$logInform{$li}}($li, "$tim $loglevel : $text");
} else {
delete $logInform{$li};
}
} }
use strict "refs"; use strict "refs";
@@ -2637,40 +2637,6 @@ CommandTrigger($$)
return join("\n", @rets); return join("\n", @rets);
} }
#####################################
sub
CommandInform($$)
{
my ($cl, $param) = @_;
return if(!$cl);
my $name = $cl->{NAME};
return "Usage: inform {on|timer|raw|off} [regexp]"
if($param !~ m/^(on|off|raw|timer|status)/);
if($param eq "status") {
my $i = $inform{$name};
return $i ? ($i->{type} . ($i->{regexp} ? " ".$i->{regexp} : "")) : "off";
}
delete($inform{$name});
if($param !~ m/^off/) {
my ($type, $regexp) = split(" ", $param);
$inform{$name}{NR} = $cl->{NR};
$inform{$name}{type} = $type;
if($regexp) {
eval { "Hallo" =~ m/$regexp/ };
return "Bad regexp: $@" if($@);
$inform{$name}{regexp} = $regexp;
}
Log 4, "Setting inform to $param";
}
return undef;
}
##################################### #####################################
sub sub
WakeUpFn($) WakeUpFn($)

View File

@@ -65,6 +65,7 @@ consStart()
if(consFilter == undefined) if(consFilter == undefined)
consFilter = ".*"; consFilter = ".*";
oldFilter = consFilter; oldFilter = consFilter;
withLog = ($("#eventWithLog").is(':checked') ? 1 : 0);
setTimeout(consFill, 1000); setTimeout(consFill, 1000);
$("#eventReset").click(function(evt){ // Event Monitor Reset $("#eventReset").click(function(evt){ // Event Monitor Reset

View File

@@ -11,3 +11,5 @@ div.ui-widget-content a {color: #CCCCCC!important; text-decoration: none!importa
.ui-button-text { font-weight:normal!important; color:#555!important; } .ui-button-text { font-weight:normal!important; color:#555!important; }
div.detLink { display:inline-block; margin-right:0.5em; } div.detLink { display:inline-block; margin-right:0.5em; }
.fhemlog { color:#FFFFFF; }

View File

@@ -21,6 +21,7 @@ table.room { border:1px solid gray; width: 100%; background: #D7FFFF; }
table.room tr.sel { background: #A0FFFF; } table.room tr.sel { background: #A0FFFF; }
tr.column > td { padding:0; vertical-align:top;} tr.column > td { padding:0; vertical-align:top;}
.changed a, .changed { color:red; } .changed a, .changed { color:red; }
.fhemlog { color:#278727; }
.col2 { text-align:center; } .col2 { text-align:center; }
/* Documentation */ /* Documentation */