From dd130c693cfb1fdf8fc58446b8489b3fe9031802 Mon Sep 17 00:00:00 2001 From: KRKeegan Date: Wed, 9 Oct 2013 18:30:21 -0700 Subject: [PATCH] Change Referenced to Web Cache Directory to html_alias_cache html_alias_cache is defined as data_dir/cache by default. Most installations will only require the data_dir to be defined, only those with special installations would need the cache dir to be outside the data_dir. Closes #229 --- bin/mh | 4 ++-- code/common/mh_control.pl | 8 +++----- code/public/whole_house_audio_speech.pl | 4 ++-- lib/Voice_Text.pm | 2 +- web/bin/ListManager.pl | 2 +- web/bin/button.pl | 18 +++++++++--------- web/bin/button2.pl | 18 +++++++++--------- web/bin/resizephoto.pl | 2 +- web/cache/empty_file.txt | 5 ----- 9 files changed, 28 insertions(+), 35 deletions(-) delete mode 100644 web/cache/empty_file.txt diff --git a/bin/mh b/bin/mh index 40fe04342..e85103685 100755 --- a/bin/mh +++ b/bin/mh @@ -736,7 +736,7 @@ sub setup { # Make various directories, if missing mkdir ("$config_parms{data_dir}/logs", 0777) unless -d "$config_parms{data_dir}/logs"; mkdir ("$config_parms{data_dir}/web", 0777) unless -d "$config_parms{data_dir}/web"; - mkdir ("$config_parms{data_dir}/cache", 0777) unless -d "$config_parms{data_dir}/cache"; + mkdir ("$config_parms{html_alias_cache}", 0777) unless -d "$config_parms{html_alias_cache}"; mkdir ("$config_parms{html_dir}/tv", 0777) unless -d "$config_parms{html_dir}/tv"; mkdir ("$config_parms{html_dir}/tv/clicktv", 0777) unless -d "$config_parms{html_dir}/tv/clicktv"; @@ -3819,7 +3819,7 @@ sub play { # Let the speak code push the wav file # For speak (TTS), this gets done in Voice_Text.pm if ($parms{address}) { - copy $file, "$config_parms{data_dir}/cache/speak_address.$Second.wav"; + copy $file, "$config_parms{html_alias_cache}/speak_address.$Second.wav"; for my $address (split ',', $parms{address}) { my $address_code = $config_parms{voice_text_address_code}; $address_code =~ s|\$address|$address|; diff --git a/code/common/mh_control.pl b/code/common/mh_control.pl index 6117eea36..211f6430f 100644 --- a/code/common/mh_control.pl +++ b/code/common/mh_control.pl @@ -529,14 +529,12 @@ () # Clear the web cache directory $v_clear_cache = new Voice_Cmd 'Clear the web cache directory', ''; $v_clear_cache->set_info( - 'Delete all the auto-generated .jpg files in mh/web/cache'); + 'Delete all the auto-generated .jpg files in html_alias_cache directory'); $v_clear_cache->tie_event('&handle_clear_cache_state()'); # noloop sub handle_clear_cache_state() { my $cmd = ($OS_win) ? 'del' : 'rm'; - $cmd .= " $config_parms{html_dir}/cache/*.jpg"; - $cmd =~ s|/|\\|g if $OS_win; - system $cmd; - $cmd .= " $config_parms{html_dir}/cache/*.wav"; + $cmd .= " $config_parms{html_alias_cache}/*.jpg"; + $cmd .= " $config_parms{html_alias_cache}/*.wav"; $cmd =~ s|/|\\|g if $OS_win; system $cmd; print_log "Ran: $cmd"; diff --git a/code/public/whole_house_audio_speech.pl b/code/public/whole_house_audio_speech.pl index 64b24e00c..638a872db 100644 --- a/code/public/whole_house_audio_speech.pl +++ b/code/public/whole_house_audio_speech.pl @@ -254,7 +254,7 @@ sub pre_speak_hook { print_log "Speech: player string is: $player_str"; if ($player_str) { $SpeechCount++; - $parms->{'to_file'} = "$config_parms{data_dir}/cache/speak_festival.${Hour}.${Minute}.${Second}.${SpeechCount}.wav"; + $parms->{'to_file'} = "$config_parms{html_alias_cache}/speak_festival.${Hour}.${Minute}.${Second}.${SpeechCount}.wav"; $parms->{'use_players'} = $player_str; } else { $parms->{'no_speak'} = 1; @@ -282,7 +282,7 @@ sub post_speak_hook { ##################################################################### if ($New_Hour) { - system('find', "$config_parms{data_dir}/cache", '-mmin', '+5', '-exec', 'rm', '-f', '{}', ';'); + system('find', "$config_parms{html_alias_cache}", '-mmin', '+5', '-exec', 'rm', '-f', '{}', ';'); } if ($Reload) { diff --git a/lib/Voice_Text.pm b/lib/Voice_Text.pm index bf515a4b1..8c1002e73 100644 --- a/lib/Voice_Text.pm +++ b/lib/Voice_Text.pm @@ -134,7 +134,7 @@ sub speak_text { if ($parms{address}) { my @address = split ',', $parms{address}; delete $parms{address}; - $parms{to_file} = "$main::config_parms{html_dir}/cache/speak_address.$main::Second.wav"; + $parms{to_file} = "$main::config_parms{html_alias_cache}/speak_address.$main::Second.wav"; &speak_text(%parms); package main; # So the we do not have to use $main:: diff --git a/web/bin/ListManager.pl b/web/bin/ListManager.pl index 51961b2df..0b61d38b9 100644 --- a/web/bin/ListManager.pl +++ b/web/bin/ListManager.pl @@ -1298,7 +1298,7 @@ =head1 Credits and contact information # ======================== POD END ================================== ]; - open DOC, "echo \"$POD\" | pod2html --cachedir=$config_parms{data_dir}/cache --flush 2>/dev/null |"; + open DOC, "echo \"$POD\" | pod2html --cachedir=$config_parms{html_alias_cache} --flush 2>/dev/null |"; my $content = 0; while () { $content = 1 if /transparent($white); # Write out a copy to the cache -print "Writing image to cache: $config_parms{data_dir}$image_file\n"; +print "Writing image to cache: $config_parms{html_alias_cache}$image_file\n"; my $jpeg = $image->jpeg; -file_write "$config_parms{data_dir}$image_file", $jpeg; +file_write "$config_parms{html_alias_cache}$image_file", $jpeg; -return $image_file if $file_name_only; -return &mime_header($image_file, 1, length $jpeg) . $jpeg; +return "/cache".$image_file if $file_name_only; +return &mime_header("/cache".$image_file, 1, length $jpeg) . $jpeg; diff --git a/web/bin/button2.pl b/web/bin/button2.pl index da5cda189..270125887 100644 --- a/web/bin/button2.pl +++ b/web/bin/button2.pl @@ -78,15 +78,15 @@ $ImageFile =~ s/^\$//; # Drop leading blank on object name $ImageFile =~ s/ *$//; # Drop trailing blanks $ImageFile =~ s/ /_/g; # Blanks in file names are nasty -$ImageFile = "/cache/$ImageFile.$ButtonType"; +$ImageFile = "/$ImageFile.$ButtonType"; print "$ScriptName: Cache file should be $config_parms{data_dir}/$ImageFile\n" if $Debug{$ScriptName}; # We hit the cache, so we give back the image and exit -if ( -f "$config_parms{data_dir}/$ImageFile" ) { - print "$ScriptName: Hit cached file $config_parms{data_dir}/$ImageFile\n" if $Debug{$ScriptName}; - my $data = file_read("$config_parms{data_dir}$ImageFile"); - return &mime_header( $ImageFile, 1, length $data ) . $data; +if ( -f "$config_parms{html_alias_cache}/$ImageFile" ) { + print "$ScriptName: Hit cached file $config_parms{html_alias_cache}/$ImageFile\n" if $Debug{$ScriptName}; + my $data = file_read("$config_parms{html_alias_cache}$ImageFile"); + return &mime_header( "/cache".$ImageFile, 1, length $data ) . $data; } print "$ScriptName: Cache file not found\n" if $Debug{$ScriptName}; @@ -306,13 +306,13 @@ } my $ButtonFile = $GDTemplate->$ButtonType(); if ( $ButtonOK ) { - print "$ScriptName: Writing button to cache: $config_parms{data_dir}/$ImageFile\n" if $Debug{$ScriptName}; - file_write( "$config_parms{data_dir}/$ImageFile", $ButtonFile ); + print "$ScriptName: Writing button to cache: $config_parms{html_alias_cache}/$ImageFile\n" if $Debug{$ScriptName}; + file_write( "$config_parms{html_alias_cache}/$ImageFile", $ButtonFile ); } else { - print "$ScriptName: Button $config_parms{data_dir}/$ImageFile not written to cache\n"; + print "$ScriptName: Button $config_parms{html_alias_cache}/$ImageFile not written to cache\n"; } - return &mime_header( $ImageFile, 1, length $ButtonFile ) . $ButtonFile; + return &mime_header( "/cache".$ImageFile, 1, length $ButtonFile ) . $ButtonFile; } else { print "$ScriptName: Error generating image\n"; diff --git a/web/bin/resizephoto.pl b/web/bin/resizephoto.pl index 8f81c03fb..dc5c97492 100644 --- a/web/bin/resizephoto.pl +++ b/web/bin/resizephoto.pl @@ -20,7 +20,7 @@ my $img; my $nocache = 0; #$nocache = 1; -$image_file = "$config_parms{data_dir}/cache/$image_file.jpg"; +$image_file = "$config_parms{html_alias_cache}/$image_file.jpg"; unless (-e "$image_file" or $nocache) { $url = $config_parms{html_alias_photos} .$url; my $image = Image::Resize->new($url); diff --git a/web/cache/empty_file.txt b/web/cache/empty_file.txt deleted file mode 100644 index ef89395af..000000000 --- a/web/cache/empty_file.txt +++ /dev/null @@ -1,5 +0,0 @@ - -This is an empty file :) - -Put here to make sure unzip programs will re-created this directory. -