From 3d00692341aef0c935e4073036df04bb8cb18cb8 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 18 Mar 2012 13:30:52 +0000 Subject: [PATCH] New version with additional fhemupdate2 structured directory git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@1359 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- contrib/fhemupdate.pl | 95 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/contrib/fhemupdate.pl b/contrib/fhemupdate.pl index f77a16f88..803ce1fd9 100755 --- a/contrib/fhemupdate.pl +++ b/contrib/fhemupdate.pl @@ -8,9 +8,13 @@ $ENV{CVS_RSH}="/usr/bin/ssh"; print "\n\n"; print localtime() . "\n"; -chdir("/home/rudi/fhemupdate/culfw"); +#my $homedir="/Users/rudi/Projects/fhem/fhemupdate"; +my $homedir="/home/rudi/fhemupdate"; +#goto NEWSTYLE; + +chdir("$homedir/culfw"); system("svn update ."); -chdir("/home/rudi/fhemupdate/fhem"); +chdir("$homedir/fhem"); system("mkdir -p UPLOAD"); system("svn update ."); die "SVN failed, exiting\n" if($?); @@ -24,6 +28,8 @@ if($ndiff != 4) { # more than the standard stuff is different } +################################# +# Old style my @filelist = ( "./fhem.pl.txt", "FHEM/.*.pm", @@ -66,7 +72,7 @@ if(open FH, "UPLOAD/filetimes.txt") { close(FH); } -chdir("UPLOAD"); +chdir("$homedir/fhem/UPLOAD"); open FH, ">filetimes.txt" || die "Can't open filetimes.txt: $!\n"; open FTP, ">script.txt" || die "Can't open script.txt: $!\n"; print FTP "cd fhem/fhemupdate\n"; @@ -92,3 +98,86 @@ if($cnt) { print "FTP Upload needed for $cnt files\n"; system("ftp -e fhem.de < script.txt"); } + + +NEWSTYLE: + +################################# +# new Style +chdir("$homedir/fhem"); +my $uploaddir2="UPLOAD2"; +system("mkdir -p $uploaddir2"); + +my %filelist2 = ( + "./fhem.pl.txt" => ".", + "FHEM/.*.pm" => "FHEM", + "../culfw/Devices/CUL/.*.hex" => "FHEM", + "webfrontend/pgm2/.*" => "www/pgm2", + "docs/commandref.html" => "www/pgm2", + "docs/faq.html" => "www/pgm2", + "docs/HOWTO.html" => "www/pgm2", + "docs/fhem.*.png" => "www/pgm2", + "docs/.*.jpg" => "www/pgm2", +); + +# Read in the file timestamps +my %filetime2; +my %filesize2; +my %filedir2; +chdir("$homedir/fhem"); +foreach my $fspec (keys %filelist2) { + $fspec =~ m,^(.+)/([^/]+)$,; + my ($dir,$pattern) = ($1, $2); + my $tdir = $filelist2{$fspec}; + opendir DH, $dir || die("Can't open $dir: $!\n"); + foreach my $file (grep { /$pattern/ && -f "$dir/$_" } readdir(DH)) { + my @st = stat("$dir/$file"); + my @mt = localtime($st[9]); + $filetime2{"$tdir/$file"} = sprintf "%04d-%02d-%02d_%02d:%02d:%02d", + $mt[5]+1900, $mt[4]+1, $mt[3], $mt[2], $mt[1], $mt[0]; + $filesize2{"$tdir/$file"} = $st[7]; + $filedir2{"$tdir/$file"} = $dir; + } + closedir(DH); +} + +chdir("$homedir/fhem/$uploaddir2"); +my %oldtime; +if(open FH, "filetimes.txt") { + while(my $l = ) { + chomp($l); + my ($ts, $fs, $file) = split(" ", $l, 3); + $oldtime{"$file.txt"} = $ts if($file =~ m/fhem.pl/); + $oldtime{$file} = $ts; + } + close(FH); +} + +open FH, ">filetimes.txt" || die "Can't open filetimes.txt: $!\n"; +open FTP, ">script.txt" || die "Can't open script.txt: $!\n"; +print FTP "cd fhem/fhemupdate2\n"; +print FTP "put filetimes.txt\n"; +print FTP "pas\n"; # Without passive only 28 files can be transferred +my $cnt; +foreach my $f (sort keys %filetime2) { + my $fn = $f; + $fn =~ s/.txt$// if($fn =~ m/.pl.txt$/); + print FH "$filetime2{$f} $filesize2{$f} $fn\n"; + + my $newfname = $f; + if(!$oldtime{$f} || $oldtime{$f} ne $filetime2{$f}) { + $f =~ m,^(.*)/([^/]*)$,; + my ($tdir, $file) = ($1, $2); + system("mkdir -p $tdir") unless(-d $tdir); + print FTP "put $tdir/$file $tdir/$file\n"; + system("cp ../$filedir2{$f}/$file $tdir/$file"); + $cnt++; + } +} +close FH; +close FTP; + +if($cnt) { + print "FTP Upload needed for $cnt files\n"; + system("ftp -e fhem.de < script.txt"); +}