Annotation of doc/loncapafiles/mimetex_version_check.piml, revision 1.2

1.1       raeburn     1: <!DOCTYPE piml PUBLIC "-//TUX/DTD piml 1.0 Final//EN" 
                      2: 	"http://lpml.sourceforge.net/DTD/piml.dtd">
                      3: <!-- mimetex_version_check.piml -->
                      4: <!-- Stuart Raeburn -->
                      5: 
1.2     ! raeburn     6: <!-- $Id: mimetex_version_check.piml,v 1.1 2008/12/18 22:30:24 raeburn Exp $ -->
1.1       raeburn     7: 
                      8: <!--
                      9: 
                     10: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     11: 
                     12: LON-CAPA is free software; you can redistribute it and/or modify
                     13: it under the terms of the GNU General Public License as published by
                     14: the Free Software Foundation; either version 2 of the License, or
                     15: (at your option) any later version.
                     16: 
                     17: LON-CAPA is distributed in the hope that it will be useful,
                     18: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     19: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     20: GNU General Public License for more details.
                     21: 
                     22: You should have received a copy of the GNU General Public License
                     23: along with LON-CAPA; if not, write to the Free Software
                     24: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     25: 
                     26: /home/httpd/html/adm/gpl.txt
                     27: 
                     28: http://www.lon-capa.org/
                     29: 
                     30: -->
                     31: 
                     32: <piml>
                     33: <files>
                     34: <file>
                     35: <target dist="default">/</target>
                     36: <perlscript mode="fg">
                     37:     my $currversionfile = '/home/httpd/lonTabs/mimetex-version';
                     38:     my $newversionfile = '../cgi/mimeTeX/VERSION';
                     39:     my $fh;
                     40:     if (-e $newversionfile) {
                     41:         if (open($fh, "&lt;$newversionfile")) {
                     42:             my $newversion = &lt;$fh&gt;;
                     43:             close($fh);
                     44:             chomp($newversion);
                     45:             if ($newversion=~ /^\d+\.\d+$/) { 
                     46:                 if (-e $currversionfile) {
                     47:                     if (open($fh, "&lt;$currversionfile")) {
                     48:                         my $currversion = &lt;$fh&gt;;
                     49:                         close($fh);
                     50:                         chomp($version);
                     51:                         if ($currversion=~ /^\d+\.\d+$/) {
                     52:                             if ($currversion ne $newversion) {
1.2     ! raeburn    53:                                 &clear_mimetex_cache(); 
1.1       raeburn    54:                                 if (open($fh, "&gt;$currversionfile")) {
                     55:                                     print $fh "$newversion";
                     56:                                     close($fh);
                     57:                                     print "mimetex-version file in /home/httpd/lonTabs set to version: $newversion.\n";
                     58:                                 }
                     59:                             }
                     60:                         }
                     61:                     }
                     62:                 } else {
1.2     ! raeburn    63:                     &clear_mimetex_cache();
1.1       raeburn    64:                     if (open($fh, "&gt;$currversionfile")) {
                     65:                         print $fh "$newversion";
                     66:                         close($fh);
1.2     ! raeburn    67:                         print "mimetex-version file in /home/httpd/lonTabs set to version: $newversion.\n";
1.1       raeburn    68:                     }
                     69:                 }
                     70:             }
                     71:         }
1.2     ! raeburn    72:     } else {
        !            73:         print "Couldn't find the mimetex version file: $newversionfile\n";
        !            74:     }
        !            75: 
        !            76:     sub clear_mimetex_cache {
        !            77:         my $mimetexcache = '/home/httpd/cgi-bin/mimetexcache';
        !            78:         if (opendir(my $dir,$mimetexcache)) {
        !            79:             my @gifs = grep(/^[^\/]+\.gif$/,readdir($dir));
        !            80:             if (@gifs &gt; 0) {
        !            81:                 my $counter = 0;
        !            82:                 foreach my $gif (@gifs) {
        !            83:                     unlink("$mimetexcache/$gif");
        !            84:                     $counter ++;
        !            85:                 }
        !            86:                 if ($counter) {
        !            87:                     print "$counter .gif file(s) cached by previous mimeTeX version have been removed from the mimetexcache directory\n";
        !            88:                 }
        !            89:             }
        !            90:             closedir($dir);
        !            91:         } else {
        !            92:             print "An error occurred opening the directory: $mimetexcache\n";
        !            93:         }
1.1       raeburn    94:     }
                     95: </perlscript>
                     96: </file>
                     97: </files>
                     98: </piml>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>