[LON-CAPA-cvs] cvs: doc /loncapafiles mimetex_version_check.piml

raeburn raeburn@source.lon-capa.org
Sat, 27 Dec 2008 01:21:48 -0000


raeburn		Sat Dec 27 01:21:48 2008 EDT

  Modified files:              
    /doc/loncapafiles	mimetex_version_check.piml 
  Log:
  - Typo - unwanted `
  - Code to remove gif files from mimetexcache moved to sub: &clear_mimetex_cache().
  - print warning if VERSION file could not be found in cgi/mimeTeX.
  
  
Index: doc/loncapafiles/mimetex_version_check.piml
diff -u doc/loncapafiles/mimetex_version_check.piml:1.1 doc/loncapafiles/mimetex_version_check.piml:1.2
--- doc/loncapafiles/mimetex_version_check.piml:1.1	Thu Dec 18 22:30:24 2008
+++ doc/loncapafiles/mimetex_version_check.piml	Sat Dec 27 01:21:48 2008
@@ -3,7 +3,7 @@
 <!-- mimetex_version_check.piml -->
 <!-- Stuart Raeburn -->
 
-<!-- $Id: mimetex_version_check.piml,v 1.1 2008/12/18 22:30:24 raeburn Exp $ -->
+<!-- $Id: mimetex_version_check.piml,v 1.2 2008/12/27 01:21:48 raeburn Exp $ -->
 
 <!--
 
@@ -50,8 +50,7 @@
                         chomp($version);
                         if ($currversion=~ /^\d+\.\d+$/) {
                             if ($currversion ne $newversion) {
-                                unlink('/home/httpd/cgi/mimetexcache/*.gif');
-                                print "All .gif files cached by previous mimeTeX version have been removed from the mimetexcache directory\n";
+                                &clear_mimetex_cache(); 
                                 if (open($fh, "&gt;$currversionfile")) {
                                     print $fh "$newversion";
                                     close($fh);
@@ -61,16 +60,37 @@
                         }
                     }
                 } else {
-                    unlink('/home/httpd/cgi/mimetexcache/*.gif');
-                    print "All .gif files cached by previous mimeTeX version have been removed from the mimetexcache directory\n";
+                    &clear_mimetex_cache();
                     if (open($fh, "&gt;$currversionfile")) {
                         print $fh "$newversion";
                         close($fh);
-                        print "mimetex-version file in /home/httpd/lonTabs set to version: $newversion.\n";`
+                        print "mimetex-version file in /home/httpd/lonTabs set to version: $newversion.\n";
                     }
                 }
             }
         }
+    } else {
+        print "Couldn't find the mimetex version file: $newversionfile\n";
+    }
+
+    sub clear_mimetex_cache {
+        my $mimetexcache = '/home/httpd/cgi-bin/mimetexcache';
+        if (opendir(my $dir,$mimetexcache)) {
+            my @gifs = grep(/^[^\/]+\.gif$/,readdir($dir));
+            if (@gifs &gt; 0) {
+                my $counter = 0;
+                foreach my $gif (@gifs) {
+                    unlink("$mimetexcache/$gif");
+                    $counter ++;
+                }
+                if ($counter) {
+                    print "$counter .gif file(s) cached by previous mimeTeX version have been removed from the mimetexcache directory\n";
+                }
+            }
+            closedir($dir);
+        } else {
+            print "An error occurred opening the directory: $mimetexcache\n";
+        }
     }
 </perlscript>
 </file>