From 93739d13b3266742f8cc911cacbd38f05b810e36 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Thu, 6 Jun 2013 16:31:29 +0000 Subject: [PATCH] SVGcache added git-svn-id: https://svn.fhem.de/fhem/trunk@3250 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 5 +-- fhem/FHEM/01_FHEMWEB.pm | 79 +++++++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index f2916c352..0d93e6582 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII - SVN + - feature: FHEMWEB: SVGcache attribute & clearSvgCache set command added - feature: SYSSTAT: allow (remote) monitoring raspberry pi on cpu frequency - feature: MANTAINER.txt added - feature: PRESENCE: new mode "shellscript" to use own @@ -8,7 +9,7 @@ - feature: PRESENCE: new attribute ping_count - feature: userReadings may have a filter - feature: HUEBridge: allow starting of bridge firmware update - - change: EnOcean: profil PM101 changed, old profiles FAH, FBH, FTF, SR04 + - change: EnOcean: profile PM101 changed, old profiles FAH, FBH, FTF, SR04 removed - feature: TCM: new attr blockSenderID: Block receiving telegrams with a TCM SenderID sent by repeaters @@ -16,7 +17,7 @@ commands supported - feature: EnOcean: Now all RPS / 1BS profiles, more than 90 4BS profiles and some manufacturer specific profiles are supported - - feature: EnOcean: profiles (subType) are updated from EEP 2.1 to EEP 2.5 + - feature: EnOcean: profiles (subType) are updated from EEP 2.1 to EEP 2.5 - feature: FHEMWEB attribute roomIcons added - feature: SYSSTAT: optionaly calculate geometric average of last 4 temperature values diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index d0215cb40..77a5263fa 100755 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -119,7 +119,7 @@ FHEMWEB_Initialize($) "stylesheetPrefix touchpad:deprecated smallscreen:deprecated ". "basicAuth basicAuthMsg hiddenroom hiddengroup HTTPS allowfrom CORS:0,1 ". "refresh longpoll:1,0 redirectCmds:0,1 reverseLogs:0,1 menuEntries ". - "roomIcons"; + "roomIcons SVGcache"; ############### # Initialize internal structures @@ -1519,12 +1519,31 @@ FW_showLog($) Log 1, $ret if($ret); } Log 5, "plotcommand: get $d $file INT $f $t " . join(" ", @{$flog}); - $ret = FW_fC("get $d $file INT $f $t " . join(" ", @{$flog})); - ($cfg, $plot) = FW_substcfg(1, $wl, $cfg, $plot, $file, ""); - FW_pO SVG_render($wl, $f, $t, $cfg, - $internal_data, $plot, $FW_wname, $FW_cssdir); + $FW_RETTYPE = "image/svg+xml"; + my $SVGcache = (AttrVal($FW_wname, "SVGcache", undef) && $t lt TimeNow()); + my $cDir = "$FW_dir/SVGcache"; + my $cName = "$cDir/$wl-$f-$t.svg"; + if($SVGcache && open(CFH, $cName)) { + FW_pO join("", ); + close(CFH); + + } else { + FW_fC("get $d $file INT $f $t " . join(" ", @{$flog})); + ($cfg, $plot) = FW_substcfg(1, $wl, $cfg, $plot, $file, ""); + $ret = SVG_render($wl, $f, $t, $cfg, + $internal_data, $plot, $FW_wname, $FW_cssdir); + FW_pO $ret; + if($SVGcache) { + mkdir($cDir) if(! -d $cDir); + if(open(CFH, ">$cName")) { + print CFH $ret; + close(CFH); + } + } + } + } } @@ -2434,15 +2453,27 @@ sub FW_Set($@) { my ($hash, @a) = @_; + my %cmd = ("rereadicons" => 1, "clearSvgCache" => 1); return "no set value specified" if(@a < 2); - return "Unknown argument $a[1], choose one of " . "rereadicons" - unless($a[1] eq "rereadicons"); + return ("Unknown argument $a[1], choose one of ".join(" ", sort keys %cmd)) + if(!$cmd{$a[1]}); - my @dirs = keys %FW_icons; - %FW_icons = (); - foreach my $d (@dirs) { - FW_readIcons($d); + if($a[1] eq "rereadicons") { + my @dirs = keys %FW_icons; + %FW_icons = (); + foreach my $d (@dirs) { + FW_readIcons($d); + } + } + if($a[1] eq "clearSvgCache") { + my $cDir = "$FW_dir/SVGcache"; + if(opendir(DH, $cDir)) { + map { my $n="$cDir/$_"; unlink($n) if(-f $n); } readdir(DH);; + closedir(DH); + } else { + return "Can't open $cDir: $!"; + } } return undef; } @@ -2585,13 +2616,16 @@ FW_dropdownFn() Set
    - set <name> rereadicons -

    - Rereads the icons in the icon path and updates the mapping from logical icons to physical files. - Use after adding, deleting or changing icons. -

    - +
  • rereadicons
    + Rereads the icons in the icon path and updates the mapping from logical + icons to physical files. Use after adding, deleting or changing icons. +
  • +
  • clearSvgCache
    + Delete all files found in the www/SVGcache directory, which is used to + cache SVG data, if the SVGcache attribute is set. +
+
Get @@ -2605,7 +2639,8 @@ FW_dropdownFn()
  • pathlist
    - return FHEMWEB specific directories, where files for given types are located + return FHEMWEB specific directories, where files for given types are + located

    @@ -2664,6 +2699,14 @@ FW_dropdownFn() smallscreen.

  • + +
  • SVGcache
    + if set, cache plots which won't change any more (the end-date is prior + to the current timestamp). The files are written to the www/SVGcache + directory. Default is off.
    + See also the clearSvgCache command for clearing the cache. +

  • +
  • fixedrange
    Can be applied to weblink devices (FHEMWEB).