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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (download) (as text) (annotate)
Mon Oct 1 15:42:19 2001 UTC (18 years, 2 months ago) by apizer
File size: 9824 byte(s)
Now the main program will exit if there any child exits with an error

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9