diff --git a/fhem/CHANGED b/fhem/CHANGED index f8741ed9e..728f442e3 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -38,7 +38,9 @@ new global attribute added new global attribute added new global attribute added - - feature: new module 57_Calendar.pm (Boris( + - feature: new module 57_Calendar.pm (Boris) + - feature: new parameter for updatefhem added (M. Fischer) + new global attribute added (M. Fischer) - 2011-12-31 (5.2) - bugfix: applying smallscreen attributes to firefox/opera diff --git a/fhem/FHEM/99_updatefhem.pm b/fhem/FHEM/99_updatefhem.pm index 3573bcc66..b67034e1d 100644 --- a/fhem/FHEM/99_updatefhem.pm +++ b/fhem/FHEM/99_updatefhem.pm @@ -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 [| [] []| []]\n"; + $ret = "Usage: updatefhem [|| [] []| []]\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 [ [] []| []]"; + return "Usage: updatefhem [| [] []| []]"; # user wants to update a file / module of the old structure } elsif (!-d $wwwdir) { - return "Usage: updatefhem [ [] []| []]"; + return "Usage: updatefhem [| [] []| []]"; } } # Read in the OLD filetimes.txt - my %oldtime = (); - if(open FH, "$moddir/$ftime") { - while(my $l = ) { - 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 = ) { + 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($) { diff --git a/fhem/HISTORY b/fhem/HISTORY index 65849ff3d..ca39ace74 100644 --- a/fhem/HISTORY +++ b/fhem/HISTORY @@ -509,3 +509,7 @@ - Sat Jun 02 2012 (M. Fischer) - Added new global attribute - Backuproutine from updatefhem removed. updatefhem use the command backup from now. + +- Sun Jun 03 2012 (M. Fischer) + - Added new global attribute + - Added new parameter to updatefhem diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index 627dddfc2..d18198137 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -775,7 +775,7 @@ A line ending with \ will be concatenated with the next one, so long lines

updatefhem

    - updatefhem [<filename>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]
    + updatefhem [<changed>|<filename>|<housekeeping> [<clean>] [<yes>]|<preserve> [<filename>]]

    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 backup_before_update to 0.

    + 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 exclude_from_update. +
    +
    + If <changed> 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). +
    +
    If an explicit <filename> is given, then only this file will be downloaded.
    @@ -1236,6 +1247,16 @@ A line ending with \ will be concatenated with the next one, so long lines be written to this file.
    + +
  • exclude_from_update
    + Contains a space separated list of file which will be excluded by an update. + This Attribute is used by the updatefhem command.
    + Example:
    +
      + attr global exclude_from_update 21_OWTEMP.pm temp4hum4.gplot FS20.on.png FS20.off.png +
    +

  • +
  • holiday2we
    If this attribute is set, then the $we variable diff --git a/fhem/fhem.pl b/fhem/fhem.pl index c1836af14..c52f74b1a 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -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" },