[system] / trunk / webwork / system / scripts / l2hPrecreateSet.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/scripts/l2hPrecreateSet.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (download) (as text) (annotate)
Tue Aug 7 18:33:14 2001 UTC (18 years, 4 months ago) by sam
File size: 9614 byte(s)
Added $envir{'externalTTHPath'} to defineProblemEnvir in each file. This
will work with dangerousMacros.pl to specify the path to TTH.

    1 #!/usr/local/bin/webwork-perl
    2 
    3 use strict;
    4 ## $Id$
    5 
    6 
    7 ################################################################
    8 #  Copyright @1995-1998 by Michael E. Gage, Arnold K. Pizer and
    9 #  WeBWorK at the University of Rochester. All rights reserved.
   10 ################################################################
   11 
   12 BEGIN {
   13   my $useLibDir = '.';
   14   if    ($0 =~ m|^(/.*)/|)  { $useLibDir = $1; }
   15   elsif ($0 =~ m|^(\..*)/|) { $useLibDir = $1; }
   16   elsif ($0 =~ m|^(.+)/|)   { $useLibDir = "./$1"; }
   17   unshift @INC, $useLibDir;
   18 }
   19 
   20 use webworkInit; # WeBWorKInitLine
   21 
   22 ## l2hPrecreateSet.pl
   23 ##
   24 ## pre-creates latex2html output for each student for a problem set
   25 ## so that WeBWorK doesn't have to run latex2html in processProblems
   26 
   27 ## NOTE: problem set has to be built before precreating...
   28 
   29 ## this is called with arguments classID setdefinitionfile...
   30 ## e.g. l2hPrecreateSet.pl demoCourse set1.def
   31 
   32 use CGI;
   33 use Global;
   34 use TimeLocal;
   35 use PGtranslator;
   36 my($courseID, $fileName, $lowerLimit, $upperLimit) = @ARGV;
   37 
   38 
   39 
   40 
   41 if( (@ARGV < 2) or (@ARGV > 4) ) {
   42   print "\nSyntax is: l2hPrecreateSet.pl course_name set_definition_filename    or\n";
   43   print "           l2hPrecreateSet.pl course_name set_definition_filename lowerLimit   or\n";
   44   print "           l2hPrecreateSet.pl course_name set_definition_filename lowerLimit upperLimit\n\n";
   45   print "       (e.g. l2hPrecreateSet.pl demoCourse set1.def    or\n";
   46   print "       (e.g. l2hPrecreateSet.pl demoCourse set1.def  30000  or\n";
   47   print "       (e.g. l2hPrecreateSet.pl demoCourse set1.def  30000   60000\n\n";
   48 
   49   print "Problems are pre created for all psvn's between lower and upper limits if the limits\n";
   50   print "  are given.\n\n";
   51   exit(0);
   52   }
   53 
   54 &Global::getCourseEnvironment($courseID);
   55 
   56     my $databaseDirectory       = getCourseDatabaseDirectory();
   57     my $htmlDirectory           = getCourseHtmlDirectory();
   58     my $htmlURL                 = getCourseHtmlURL();
   59     my $scriptDirectory         = getWebworkScriptDirectory();
   60     my $templateDirectory       = getCourseTemplateDirectory();
   61     my $courseScriptsDirectory  = getCourseScriptsDirectory();
   62     my $tempDirectory           = getCourseTempDirectory();
   63 
   64 require "${courseScriptsDirectory}$Global::displayMacros_pl";
   65 require "${scriptDirectory}$Global::DBglue_pl";
   66 require "${scriptDirectory}$Global::classlist_DBglue_pl";
   67 require "${scriptDirectory}$Global::FILE_pl";
   68 require "${scriptDirectory}$Global::HTMLglue_pl";
   69 
   70 ####################################################################
   71 # load the modules to be used in PGtranslator
   72   require "${courseScriptsDirectory}PG_module_list.pl";
   73 ####################################################################
   74 
   75 $fileName = ${templateDirectory} . $fileName;
   76 
   77 my  $starttime = time;
   78 my  ($name);
   79 my  ($setNumber,$setHeaderFileName,$probHeaderFileName,$dueDate,$openDate,$answerDate,$problemListref,$problemValueListref,$problemAttemptLimitListref)
   80         = &readSetDef($fileName);
   81 my  @problemList = @$problemListref;
   82 my  @problemValueList = @$problemValueListref;
   83 my  @problemAttemptLimitList = @$problemAttemptLimitListref;
   84 
   85 
   86 my $numProbs=0;
   87 foreach $name (@problemList)
   88     {$numProbs++;}
   89 
   90 my @setProbSetKeys = &getAllProbSetKeysForSet($setNumber);
   91 #sort the ProbSetKeys to make it easier to keep track of what's happening
   92 @setProbSetKeys = sort {$a <=> $b} @setProbSetKeys;
   93 
   94 my $mode = 'Latex2HTML';
   95 my ($ii,$psvn);
   96 my @saveSubmittedAnswerList = ();
   97 my ($seed, $login_name_for_psvn);
   98 
   99 foreach $psvn (@setProbSetKeys) {
  100   next if ((defined $lowerLimit) and ($psvn < $lowerLimit));
  101   next if ((defined $upperLimit) and ($psvn > $upperLimit));
  102 
  103   &attachProbSetRecord($psvn);
  104   $login_name_for_psvn = &getStudentLogin($psvn);
  105   attachCLRecord($login_name_for_psvn);
  106 
  107     print "In foreach: key = $psvn\n";
  108     for($ii=1; $ii<=$numProbs; $ii++) {
  109         print "In for key = $psvn .... i = $ii\n";
  110 
  111       my $source;
  112         my $probFileName    =   &getProblemFileName($ii,$psvn);;
  113     if (-e "${templateDirectory}$probFileName" ) {
  114       unless (-r "${templateDirectory}$probFileName") {
  115         wwerror($0, "Can't read ${templateDirectory}$probFileName");
  116         }
  117         open(PROB,"<${templateDirectory}$probFileName");
  118         $source = join("",<PROB>);
  119         close(PROB);
  120       }
  121       ###############################################
  122       # Create problem text
  123       ###############################################
  124       my %envir=defineProblemEnvir($mode,$ii,$psvn,$courseID,\@saveSubmittedAnswerList);
  125 
  126     ###### New Code contributed by Bill Wheeler ############
  127     ####### to fix memory leak
  128     my $pid=fork();
  129     if ($pid) {wait ;}
  130         else {
  131 
  132       my $pt = new PGtranslator;  #pt stands for problem translator;
  133       $pt->environment(\%envir);
  134       $pt->initialize();
  135       $pt-> set_mask();
  136       # $pt -> evaluate_modules(qw( Exporter DynaLoader GD WWPlot Fun Circle Label PGrandom Units ) );
  137       # The modules to be loaded are now defined in PG_modules_list.pl
  138       $pt->source_string($source);
  139         $pt -> unrestricted_load("${courseScriptsDirectory}PG.pl");
  140         $pt -> unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
  141         $pt ->translate();
  142         &createDisplayedProblem($setNumber,$ii,$psvn,$pt->ra_text(), $pt->rh_flags());
  143 
  144             undef($pt);
  145           ## remove any links to gifs. These are not needed and when created by a script run from
  146           ## the command, they are invalid if the webserver is in a chroot enviroment
  147           unlink(<$tempDirectory/gif/*${psvn}-set${setNumber}-prob${ii}-*>);
  148       ############## New Code ########################
  149             exit(0);
  150     }
  151   }
  152 }
  153 
  154 
  155 
  156 
  157 my $endtime = time;
  158 my $totaltime = ($endtime - $starttime)/60;
  159 
  160 print "\n\nThis took $totaltime minutes to precreate $fileName \n\n";
  161 
  162 
  163 
  164 sub defineProblemEnvir {
  165     my ($mode,$probNum,$psvn,$courseName,$refSubmittedAnswers)      =   @_;
  166     my %envir=();
  167     my $loginName = &getStudentLogin($psvn);
  168     ##how to put an array submittedAnswers in a hash??
  169     $envir{'refSubmittedAnswers'}   =   $refSubmittedAnswers if defined($refSubmittedAnswers);
  170     $envir{'psvnNumber'}        =   $psvn;
  171     $envir{'psvn'}            =   $psvn;
  172     $envir{'studentName'}       =   &CL_getStudentName($loginName);
  173   $envir{'studentLogin'}        = $loginName;
  174   $envir{'sectionName'}       = &CL_getClassSection($loginName);
  175   $envir{'sectionNumber'}       = &CL_getClassSection($loginName);
  176   $envir{'recitationName'}      = &CL_getClassRecitation($loginName);
  177   $envir{'recitationNumber'}      = &CL_getClassRecitation($loginName);
  178   $envir{'setNumber'}         = &getSetNumber($psvn);
  179   $envir{'questionNumber'}        = $probNum;
  180   $envir{'probNum'}           = $probNum;
  181   $envir{'openDate'}          = &getOpenDate($psvn);
  182   $envir{'formattedOpenDate'}     = &formatDateAndTime(&getOpenDate($psvn));
  183   $envir{'dueDate'}           = &getDueDate($psvn);
  184   $envir{'formattedDueDate'}      = &formatDateAndTime(&getDueDate($psvn));
  185   $envir{'answerDate'}        = &getAnswerDate($psvn);
  186   $envir{'formattedAnswerDate'}   = &formatDateAndTime(&getAnswerDate($psvn));
  187   $envir{'problemValue'}        = &getProblemValue($probNum,$psvn);
  188   $envir{'fileName'}          = &getProblemFileName($probNum,$psvn);
  189   $envir{'probFileName'}        = &getProblemFileName($probNum,$psvn );
  190   $envir{'displayMode'}       = $mode;
  191   $envir{'languageMode'}        = $mode;
  192   $envir{'outputMode'}        = $mode;
  193   $envir{'courseName'}        = $courseName;
  194   $envir{'sessionKey'}        = ( defined($main::in{'key'}) ) ?$main::in{'key'} : " ";
  195 
  196 
  197   # initialize constants for PGanswermacros.pl
  198   $envir{'numRelPercentTolDefault'}   =     getNumRelPercentTolDefault();
  199   $envir{'numZeroLevelDefault'}   =     getNumZeroLevelDefault();
  200   $envir{'numZeroLevelTolDefault'}  =     getNumZeroLevelTolDefault();
  201   $envir{'numAbsTolDefault'}      =     getNumAbsTolDefault();
  202   $envir{'numFormatDefault'}      =     getNumFormatDefault();
  203   $envir{'functRelPercentTolDefault'} =     getFunctRelPercentTolDefault();
  204   $envir{'functZeroLevelDefault'}   =     getFunctZeroLevelDefault();
  205   $envir{'functZeroLevelTolDefault'}  =     getFunctZeroLevelTolDefault();
  206   $envir{'functAbsTolDefault'}    =     getFunctAbsTolDefault();
  207   $envir{'functNumOfPoints'}      =     getFunctNumOfPoints();
  208   $envir{'functVarDefault'}       =     getFunctVarDefault();
  209   $envir{'functLLimitDefault'}    =     getFunctLLimitDefault();
  210   $envir{'functULimitDefault'}    =     getFunctULimitDefault();
  211   $envir{'functMaxConstantOfIntegration'} = getFunctMaxConstantOfIntegration();
  212   $envir{'numOfAttempts'}             =     undef;
  213 
  214   # defining directorys and URLs
  215   $envir{'templateDirectory'}       = &getCourseTemplateDirectory();
  216   $envir{'classDirectory'}        = $Global::classDirectory;
  217   $envir{'cgiDirectory'}        = $Global::cgiDirectory;
  218   $envir{'cgiURL'}                    =   getWebworkCgiURL();
  219   $envir{'macroDirectory'}        = getCourseMacroDirectory();
  220   $envir{'courseScriptsDirectory'}    = getCourseScriptsDirectory();
  221   $envir{'htmlDirectory'}             =   getCourseHtmlDirectory();
  222   $envir{'htmlURL'}           = getCourseHtmlURL();
  223   $envir{'tempDirectory'}             =   getCourseTempDirectory();
  224   $envir{'tempURL'}                   =   getCourseTempURL();
  225   $envir{'scriptDirectory'}       = $Global::scriptDirectory;
  226   $envir{'webworkDocsURL'}        = $Global::webworkDocsURL;
  227   $envir{'externalTTHPath'}       = $Global::externalTTHPath;
  228 
  229   $envir{'inputs_ref'}        = {user => 'practice1',course => 'demoCourse', key => ' '};
  230     # no inputs when in this mode
  231   $seed = &getProblemSeed($probNum, $psvn);
  232   $seed = 0 unless defined($seed);
  233 
  234   $envir{'problemSeed'}     =   $seed if defined($seed);
  235 
  236   my $k;
  237   foreach $k (keys %Global::PG_environment ) {
  238     $envir{$k} = $Global::PG_environment{$k};
  239   }
  240   %envir;
  241 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9