2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

Added new global attribute <exclude_from_update>

Added new parameter <changed> to updatefhem


git-svn-id: https://svn.fhem.de/fhem/trunk@1601 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
mfr69bs 2012-06-03 15:40:32 +00:00
parent 110c339832
commit 119355b689
5 changed files with 163 additions and 48 deletions

View File

@ -38,7 +38,9 @@
new global attribute <backupsymlink> added
new global attribute <backupcmd> added
new global attribute <backup_before_update> added
- feature: new module 57_Calendar.pm (Boris(
- feature: new module 57_Calendar.pm (Boris)
- feature: new parameter <changed> for updatefhem added (M. Fischer)
new global attribute <exclude_from_update> added (M. Fischer)
- 2011-12-31 (5.2)
- bugfix: applying smallscreen attributes to firefox/opera

View File

@ -9,6 +9,9 @@ use IO::Socket;
sub CommandUpdatefhem($$);
sub CommandCULflash($$);
sub GetHttpFile($$@);
sub ParseChanges($);
sub ReadOldFiletimes($);
sub SplitNewFiletimes($);
sub FileList($);
my $server = "fhem.de:80";
@ -46,7 +49,7 @@ CommandUpdatefhem($$)
my $msg;
if(!$param && !-d $wwwdir) {
$ret = "Usage: updatefhem [<filename>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]\n";
$ret = "Usage: updatefhem [<changed>|<filename>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]\n";
$ret .= "Please note: The update routine has changed! Please consider the manual of command 'updatefhem'!";
return $ret;
}
@ -56,7 +59,13 @@ CommandUpdatefhem($$)
if(@args) {
if (uc($args[0]) eq "PRESERVE") {
# Get list of changes
if (uc($args[0]) eq "CHANGED") {
$ret = ParseChanges($moddir);
return $ret;
# Preserve current structur
} elsif (uc($args[0]) eq "PRESERVE") {
# Check if new wwwdir already exists and an argument is given
if(-d $wwwdir && @args > 1) {
@ -138,45 +147,33 @@ CommandUpdatefhem($$)
# help
} elsif (uc($args[0]) eq "?") {
return "Usage: updatefhem [<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]";
return "Usage: updatefhem [<changed>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]";
# user wants to update a file / module of the old structure
} elsif (!-d $wwwdir) {
return "Usage: updatefhem [<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]";
return "Usage: updatefhem [<changed>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]";
}
}
# Read in the OLD filetimes.txt
my %oldtime = ();
if(open FH, "$moddir/$ftime") {
while(my $l = <FH>) {
chomp($l);
my ($ts, $fs, $file) = split(" ", $l, 3);
$oldtime{$file} = $ts;
}
close(FH);
}
my $oldtime = ReadOldFiletimes("$moddir/$ftime");
# Get new filetimes.txt
my $filetimes = GetHttpFile($server, "$sdir/$ftime");
return "Can't get $ftime from $server" if(!$filetimes);
my (%filetime, %filesize) = ();
foreach my $l (split("[\r\n]", $filetimes)) {
chomp($l);
return "Corrupted filetimes.txt file"
if($l !~ m/^20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /);
my ($ts, $fs, $file) = split(" ", $l, 3);
$filetime{$file} = $ts;
$filesize{$file} = $fs;
}
# split filetime and filesize
my ($sret, $filetime, $filesize) = SplitNewFiletimes($filetimes);
return "$sret" if($sret);
# Check for new / modified files
my $c = 0;
foreach my $f (sort keys %filetime) {
foreach my $f (sort keys %$filetime) {
if($param) {
next if($f !~ m/$param/);
} else {
if(!$clean) {
next if($oldtime{$f} && $filetime{$f} eq $oldtime{$f});
next if($oldtime->{$f} && $filetime->{$f} eq $oldtime->{$f});
}
next if($f =~ m/.hex$/); # skip firmware files
}
@ -189,14 +186,14 @@ CommandUpdatefhem($$)
my $doBackup = (!defined($attr{global}{backup_before_update}) ? 1 : $attr{global}{backup_before_update});
if ($doBackup) {
$ret = AnalyzeCommandChain(undef, "backup");
if($ret !~ m/backup done.*/) {
my $cmdret = AnalyzeCommandChain(undef, "backup");
if($cmdret !~ m/backup done.*/) {
Log 1, "updatefhem: The operation was canceled. Please check manually!";
$msg = "Something went wrong during backup:\n$ret\n";
$msg = "Something went wrong during backup:\n$cmdret\n";
$msg .= "The operation was canceled. Please check manually!";
return $msg;
}
$ret .= "\n";
$ret .= "$cmdret\n";
}
my @reload;
@ -205,12 +202,19 @@ CommandUpdatefhem($$)
my $remfile;
my $oldfile;
my $delfile;
foreach my $f (sort keys %filetime) {
my $excluded = (!defined($attr{global}{exclude_from_update}) ? "" : $attr{global}{exclude_from_update});
foreach my $f (sort keys %$filetime) {
my $ef = substr $f,rindex($f,'/')+1;
if($excluded =~ /$ef/) {
$ret .= "excluded $f\n";
next;
}
if($param) {
next if($f !~ m/$param/);
} else {
if(!$clean) {
next if($oldtime{$f} && $filetime{$f} eq $oldtime{$f});
next if($oldtime->{$f} && $filetime->{$f} eq $oldtime->{$f});
}
next if($f =~ m/.hex$/); # skip firmware files
}
@ -240,7 +244,7 @@ CommandUpdatefhem($$)
my $content = GetHttpFile($server, "$sdir/$remfile");
my $l1 = length($content);
my $l2 = $filesize{$f};
my $l2 = $filesize->{$f};
return "File size for $f ($l1) does not correspond to ".
"filetimes.txt entry ($l2)" if($l1 ne $l2);
open(FH,">$localfile") || return "Can't write $localfile";
@ -340,21 +344,15 @@ CommandCULflash($$)
my $filetimes = GetHttpFile($server, "$sdir/$ftime");
return "Can't get $ftime from $server" if(!$filetimes);
my (%filetime, %filesize);
foreach my $l (split("[\r\n]", $filetimes)) {
chomp($l);
return "Corrupted filetimes.txt file"
if($l !~ m/^20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /);
my ($ts, $fs, $file) = split(" ", $l, 3);
$filetime{$file} = $ts;
$filesize{$file} = $fs;
}
# split filetime and filesize
my ($ret, $filetime, $filesize) = SplitNewFiletimes($filetimes);
return $ret if($ret);
################################
# Now get the firmware file:
my $content = GetHttpFile($server, "$sdir/$target.hex");
my $content = GetHttpFile($server, "$sdir/FHEM/$target.hex");
return "File size for $target.hex does not correspond to filetimes.txt entry"
if(length($content) ne $filesize{"$target.hex"});
if(length($content) ne $filesize->{"FHEM/$target.hex"});
my $localfile = "$moddir/$target.hex";
open(FH,">$localfile") || return "Can't write $localfile";
print FH $content;
@ -416,6 +414,97 @@ GetHttpFile($$@)
return $ret;
}
sub
ParseChanges($)
{
my $moddir = shift;
my $excluded = (!defined($attr{global}{exclude_from_update}) ? "" : $attr{global}{exclude_from_update});
my $ret = "List of new / modified files since last update:\n";
# get list of files
my $filetimes = GetHttpFile($server, "$sdir/$ftime");
return $ret."Can't get $ftime from $server" if(!$filetimes);
# split filetime and filesize
my ($sret, $filetime, $filesize) = SplitNewFiletimes($filetimes);
$ret .= "$sret\n" if($sret);
# Read in the OLD filetimes.txt
my $oldtime = ReadOldFiletimes("$moddir/$ftime");
# Check for new / modified files
my $c = 0;
foreach my $f (sort keys %$filetime) {
next if($oldtime->{$f} && $filetime->{$f} eq $oldtime->{$f});
next if($f =~ m/.hex$/); # skip firmware files
$c = 1;
my $ef = substr $f,rindex($f,'/')+1;
if($excluded !~ /$ef/) {
$ret .= "$filetime->{$f} $f\n";
} else {
$ret .= "$filetime->{$f} $f ==> excluded from update!\n";
}
}
if (!$c) {
$ret .= "nothing to do...";
} else {
# get list of changes
$ret .= "\nList of changes:\n";
my $changed = GetHttpFile($server, "$sdir/CHANGED");
if(!$changed || $changed =~ m/Error 404/g) {
$ret .= "Can't get list of changes from $server";
} else {
my @lines = split(/\015\012|\012|\015/,$changed);
foreach my $line (@lines) {
last if($line eq "");
$ret .= $line."\n";
}
}
}
return $ret;
}
sub
ReadOldFiletimes($)
{
my $filetimes = shift;
my %oldtime = ();
my $excluded = (!defined($attr{global}{exclude_from_update}) ? "" : $attr{global}{exclude_from_update});
# Read in the OLD filetimes.txt
if(open FH, "$filetimes") {
while(my $l = <FH>) {
chomp($l);
my ($ts, $fs, $file) = split(" ", $l, 3);
my $ef = substr $file,rindex($file,'/')+1;
next if($excluded =~ /$ef/);
$oldtime{$file} = $ts;
}
close(FH);
}
return (\%oldtime);
}
sub
SplitNewFiletimes($)
{
my $filetimes = shift;
my $ret;
my (%filetime, %filesize) = ();
foreach my $l (split("[\r\n]", $filetimes)) {
chomp($l);
$ret = "Corrupted filetimes.txt file"
if($l !~ m/^20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /);
last if($ret);
my ($ts, $fs, $file) = split(" ", $l, 3);
$filetime{$file} = $ts;
$filesize{$file} = $fs;
}
return ($ret, \%filetime, \%filesize);
}
sub
FileList($)
{

View File

@ -509,3 +509,7 @@
- Sat Jun 02 2012 (M. Fischer)
- Added new global attribute <backup_before_update>
- Backuproutine from updatefhem removed. updatefhem use the command backup from now.
- Sun Jun 03 2012 (M. Fischer)
- Added new global attribute <exclude_from_update>
- Added new parameter <changed> to updatefhem

View File

@ -775,7 +775,7 @@ A line ending with \ will be concatenated with the next one, so long lines
<a name="updatefhem"></a>
<h3>updatefhem</h3>
<ul>
<code>updatefhem [&lt;filename&gt;|&lt;housekeeping&gt; [&lt;clean&gt;] [&lt;yes&gt;]|&lt;preserve&gt; [&lt;filename&gt;]]</code> <br>
<code>updatefhem [&lt;changed&gt;|&lt;filename&gt;|&lt;housekeeping&gt; [&lt;clean&gt;] [&lt;yes&gt;]|&lt;preserve&gt; [&lt;filename&gt;]]</code> <br>
<br>
Update the fhem modules and documentation from a nightly SVN checkout. For
this purpose Fhem contacts http://fhem.de/fhemupdate, compares the stored
@ -796,6 +796,17 @@ A line ending with \ will be concatenated with the next one, so long lines
the global attribute <a href="#backup_before_update">backup_before_update</a> to 0.
<br>
<br>
Have you change or replace original files of the Fhem Distribution,
these files will normally be overwritten during an update. To protect
your locally modified or replaced files during an update, you can exclude
these files with the global attribute <a href="#exclude_from_update">exclude_from_update</a>.
<br>
<br>
If &lt;changed&gt; is specified, updatefhem returns a list of new or
modified files since the last update. Furthermore it returns the last
changes from the CHANGED file (if the file exists on the update server).
<br>
<br>
If an explicit &lt;filename&gt; is given, then only this file will be
downloaded.
<br>
@ -1236,6 +1247,16 @@ A line ending with \ will be concatenated with the next one, so long lines
be written to this file.
</li><br>
<a name="exclude_from_update"></a>
<li>exclude_from_update<br>
Contains a space separated list of file which will be excluded by an update.
This Attribute is used by the <a href="#updatefhem">updatefhem</a> command.<br>
Example:<br>
<ul>
attr global exclude_from_update 21_OWTEMP.pm temp4hum4.gplot FS20.on.png FS20.off.png
</ul>
</li><br>
<a name="holiday2we"></a>
<li>holiday2we<br>
If this attribute is set, then the <a href="#perl">$we</a> variable

View File

@ -193,12 +193,11 @@ $modules{Global}{AttrList} =
"archivecmd allowfrom apiversion archivedir configfile lastinclude logfile " .
"modpath nrarchive pidfilename port statefile title userattr " .
"verbose:1,2,3,4,5 mseclog version nofork logdir holiday2we " .
"autoload_undefined_devices dupTimeout latitude longitude ".
"backupcmd backupdir backupsymlink backup_before_update";
"autoload_undefined_devices dupTimeout latitude longitude " .
"backupcmd backupdir backupsymlink backup_before_update " .
"exclude_from_update ";
$modules{Global}{AttrFn} = "GlobalAttr";
%cmds = (
"?" => { Fn=>"CommandHelp",
Hlp=>",get this help" },