[LON-CAPA-cvs] cvs: loncom /interface printout.pl

foxr lon-capa-cvs-allow@mail.lon-capa.org
Tue, 18 Mar 2008 10:29:56 -0000


foxr		Tue Mar 18 06:29:56 2008 EDT

  Modified files:              
    /loncom/interface	printout.pl 
  Log:
  - Interal refactoring of convert_image's final filename generation.
  - Simplification of path generation so it's easier to understand
   (replace a regsub with call to dirname).
  
  
  
  
Index: loncom/interface/printout.pl
diff -u loncom/interface/printout.pl:1.133 loncom/interface/printout.pl:1.134
--- loncom/interface/printout.pl:1.133	Tue Mar 18 05:48:11 2008
+++ loncom/interface/printout.pl	Tue Mar 18 06:29:56 2008
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
 #
-# $Id: printout.pl,v 1.133 2008/03/18 09:48:11 foxr Exp $
+# $Id: printout.pl,v 1.134 2008/03/18 10:29:56 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -977,34 +977,37 @@
 sub convert_figure {
     my ($not_eps) = @_;
 
-
     my $status_statement='EPS picture for '.$not_eps;
     my $eps_f = $not_eps;
+
     if ($eps_f=~/\/home\/([^\/]+)\/public_html\//) {
 	$eps_f=~s/\/home\/([^\/]+)\/public_html/$1/;
-	$eps_f = $perlvar{'lonPrtDir'}.'/'.$eps_f;
     } elsif ($eps_f=~/$perlvar{'lonDocRoot'}\/res\//) {
-	$eps_f=~m/$perlvar{'lonDocRoot'}\/res\/(.+)/;
-	$eps_f = $perlvar{'lonPrtDir'}.'/'.$1;
+	$eps_f=~ s/$perlvar{'lonDocRoot'}\/res\/(.+)/$1/;
     } elsif ($eps_f=~/$perlvar{'lonUsersDir'}\//) {
-	$eps_f=~/$perlvar{'lonUsersDir'}\/([^\/]+)\/\w\/\w\/\w\/(.+)/;
-	$eps_f = $perlvar{'lonPrtDir'}.'/'.$1.'/'.$2;
+	$eps_f=~ s/$perlvar{'lonUsersDir'}\/([^\/]+)\/\w\/\w\/\w\/(.+)/$1\/$2/;
     }
-    $eps_f  =~ s/ /\_/g; # Spaces are problematic for system commands and LaTeX.
+
+    $eps_f = $perlvar{'lonPrtDir'}.'/'.$eps_f;
+
+    # Spaces are problematic for system commands and LaTeX, replace with _
+
+    $eps_f  =~ s/ /\_/g; 
+
     # 
-    # If the file is already an .eps or .ps file,
+    # If the file is already an .eps or .ps file (eps_f still has the original
+    # file type),
     # We really just need to copy it from where it was to prtspool
     # but with the spaces substituted to _'s.
     #
-    my ($nsname,$path, $sext) = &fileparse($not_eps, qr/\.(ps|eps)/i);
+    my ($nsname,$path, $sext) = &fileparse($eps_f, qr/\.(ps|eps)/i);
     if ($sext =~/ps$/i) {
 	&File::Path::mkpath($path,0,0777);
 	copy("$not_eps", "$eps_f"); 
     } else {
 	
 	$eps_f .= '.eps';	# Just append the eps ext.
-	my $path=$eps_f;
-	$path =~ s/\/([^\/]+)\.eps$//;
+	my $path= &dirname($eps_f);
 	&File::Path::mkpath($path,0,0777);
 	$not_eps =~ s/^\s+//;
 	$not_eps =~ s/\s+$//;
@@ -1017,6 +1020,7 @@
 						  'Converting to EPS '.$prettyname);
 	}
 	system("convert $not_eps $eps_f");
+
 	if (not -e $eps_f) {
 	    # converting an animated gif creates either:
 	    # anim.gif.eps.0