2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

Rename added, rereadcfg bugfix

git-svn-id: https://svn.fhem.de/fhem/trunk@31 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2007-03-19 15:34:34 +00:00
parent 1af4b93426
commit 2c8f2dd2c2
4 changed files with 73 additions and 29 deletions

View File

@ -294,7 +294,7 @@
- bugfix: empty FHT battery is not reported (by Holger)
- feature: new FHT codes, e.g. month/day/hour/minute setting (by Holger)
- ==DATE== (3.4)
- ==DATE== (4.0)
- bugfix: deny at +{3}... (only +*{3} allowed), reported by Bernd, 25.01
- bugfix: allow numbers greater then 9 in at +{<number>}
- feature: new 50_WS300.pm from Martin (bugfix + rain statistics, 26.01)
@ -315,6 +315,6 @@
- list/xmllist format changed
- disable attribute for at/notify/filelog
See HISTORY for details and reasoning
- TODO: bugfix: more thorough serial line initialization
- added rename command
- RENAME
- TODO: bugfix: more thorough serial line initialization

View File

@ -236,7 +236,7 @@ FHZ_Undef($$)
my ($hash, $arg) = @_;
my $name = $hash->{NAME};
foreach my $d (keys %defs) {
foreach my $d (sort keys %defs) {
if(defined($defs{$d}) &&
defined($defs{$d}{IODev}) &&
$defs{$d}{IODev} == $hash)
@ -245,7 +245,7 @@ FHZ_Undef($$)
delete $defs{$d}{IODev};
}
}
$hash->{PortObj}->close();
$hash->{PortObj}->close() if($hash->{PortObj});
return undef;
}

View File

@ -15,7 +15,13 @@
- Added doc/linux.html (multiple USDB devices, udev links)
- Linked fhem.html and commandref.html to linux.html
- rudi, Sun Mar 4 11:18:10 MET 2007
- Martin Haas, Fri Feb 23 10:18 MET 2007
- ARM-Section (NSLU2) added to doc/linux.html
- Pest, Sat Feb 24 18:30 MET 2007
- doc/linux.html: Module build re-written.
- Rudi, Sun Mar 4 11:18:10 MET 2007
Reorganization. Goal: making attribute adding/deleting more uniform
("at/notify" and other device differences), and making web-configuration
possible (i.e. saving the configfile, list of possible devices etc).
@ -48,9 +54,4 @@
- "define/set/get/attr name ?" returns a list of possible arguments
in the same format. This data is contained in the xmllist.
- disable attribute for at/notify/filelog
- Martin Haas, Fri Feb 23 10:18 MET 2007
- ARM-Section (NSLU2) added to doc/linux.html
- Pest, Sat Feb 24 18:30 MET 2007
- doc/linux.html: Module build re-written.
- rename added

View File

@ -60,6 +60,7 @@ sub TimeNow();
sub WriteStatefile();
sub XmlEscape($);
sub fhem($);
sub doGlobalDef($);
sub CommandAttr($$);
sub CommandDefAttr($$);
@ -72,6 +73,7 @@ sub CommandInclude($$);
sub CommandInform($$);
sub CommandList($$);
sub CommandRereadCfg($$);
sub CommandRename($$);
sub CommandQuit($$);
sub CommandSave($$);
sub CommandSet($$);
@ -129,6 +131,7 @@ my %defattr; # Default attributes
my %intAt; # Internal at timer hash.
my $intAtCnt=0;
my $init_done = 0;
my $reread_active = 0;
my $AttrList = "room";
@ -136,15 +139,7 @@ $modules{Internal}{ORDER} = -1;
$modules{Internal}{AttrList} = "configfile logfile modpath " .
"pidfilename port statefile userattr verbose:1,2,3,4,5 version";
$defs{global}{NR} = $devcount++;
$defs{global}{TYPE} = "Internal";
$defs{global}{STATE} = "Internal";
$defs{global}{DEF} = "<no definition>";
CommandAttr(undef, "global verbose 3");
CommandAttr(undef, "global configfile $ARGV[0]");
CommandAttr(undef, "global logfile -");
CommandAttr(undef, "global version =VERS= from =DATE=");
doGlobalDef($ARGV[0]);
my %cmds = (
"?" => { Fn=>"CommandHelp",
@ -173,6 +168,8 @@ my %cmds = (
Hlp=>",end the client session" },
"reload" => { Fn=>"CommandReload",
Hlp=>"<module-name>,reload the given module (e.g. 99_PRIV)" },
"rename" => { Fn=>"CommandRename",
Hlp=>"<old> <new>,rename a definition" },
"rereadcfg" => { Fn=>"CommandRereadCfg",
Hlp=>",reread the config file" },
"save" => { Fn=>"CommandSave",
@ -604,14 +601,20 @@ CommandRereadCfg($$)
return $ret if($ret);
}
my $cfgfile = $attr{global}{configfile};
%defs = ();
%attr = ();
doGlobalDef($cfgfile);
my $ret;
$ret = CommandInclude($cl, $attr{global}{configfile});
return $ret if($ret);
$ret = CommandInclude($cl, $attr{global}{statefile})
if($attr{global}{statefile} && -r $attr{global}{statefile});
$reread_active=1;
my $ret = CommandInclude($cl, $cfgfile);
if(!$ret && $attr{global}{statefile} && -r $attr{global}{statefile}) {
$ret = CommandInclude($cl, $attr{global}{statefile});
}
$reread_active=0;
return $ret;
}
@ -916,6 +919,7 @@ CommandDelete($$)
{
my ($cl, $def) = @_;
return "Please define $def first" if(!defined($defs{$def}));
my $ret = CallFn($def, "UndefFn", $defs{$def}, $def);
return $ret if($ret);
@ -1107,6 +1111,26 @@ CommandReload($$)
return undef;
}
#####################################
sub
CommandRename($$)
{
my ($cl, $param) = @_;
my ($old, $new) = split(" ", $param);
return "Please define $old first" if(!defined($defs{$old}));
return "Invalid characters in name (not A-Za-z0-9.:-): $new"
if($new !~ m/^[a-z0-9.:_-]*$/i);
return "Cannot rename global" if($old eq "global");
$defs{$new} = $defs{$old};
delete($defs{$old});
$attr{$new} = $attr{$old};
delete($attr{$old});
return undef;
}
#####################################
sub
@ -1163,6 +1187,8 @@ CommandAttr($$)
################
elsif($a[1] eq "port") {
return undef if($reread_active);
my ($port, $global) = split(" ", $a[2]);
if($global && $global ne "global") {
return "Bad syntax, usage: attr global port <portnumber> [global]";
@ -1174,9 +1200,10 @@ CommandAttr($$)
LocalPort => $port,
Listen => 10,
ReuseAddr => 1);
if($ret) {
return $ret if($init_done);
die "Can't open server port at $port\n";
if(!$server2) {
Log 1, "Can't open server port at $port: $!\n";
return "$!" if($init_done);
die "Can't open server port at $port: $!\n";
}
close($server) if($server);
$server = $server2;
@ -1550,3 +1577,19 @@ fhem($)
return AnalyzeCommandChain($global_cl, $param);
}
sub
doGlobalDef($)
{
my ($arg) = @_;
$devcount = 0;
$defs{global}{NR} = $devcount++;
$defs{global}{TYPE} = "Internal";
$defs{global}{STATE} = "Internal";
$defs{global}{DEF} = "<no definition>";
CommandAttr(undef, "global verbose 3");
CommandAttr(undef, "global configfile $arg");
CommandAttr(undef, "global logfile -");
CommandAttr(undef, "global version =VERS= from =DATE=");
}