[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 226 - (download) (as text) (annotate)
Mon Oct 1 15:42:19 2001 UTC (18 years, 2 months ago) by apizer
File size: 9775 byte(s)
Now the main program will exit if there any child exits with an error

    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) {
  130       waitpid($pid,0);
  131       exit 1 if $?; ## exit main program if there was an error in the child process
  132     }
  133         else {
  134 
  135       my $pt = new PGtranslator;  #pt stands for problem translator;
  136       $pt->environment(\%envir);
  137       $pt->initialize();
  138       $pt-> set_mask();
  139       # $pt -> evaluate_modules(qw( Exporter DynaLoader GD WWPlot Fun Circle Label PGrandom Units ) );
  140       # The modules to be loaded are now defined in PG_modules_list.pl
  141       $pt->source_string($source);
  142         $pt -> unrestricted_load("${courseScriptsDirectory}PG.pl");
  143         $pt -> unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
  144         $pt ->translate();
  145         &createDisplayedProblem($setNumber,$ii,$psvn,$pt->ra_text(), $pt->rh_flags());
  146 
  147             undef($pt);
  148           ## remove any links to gifs. These are not needed and when created by a script run from
  149           ## the command, they are invalid if the webserver is in a chroot enviroment
  150           unlink(<$tempDirectory/gif/*${psvn}-set${setNumber}-prob${ii}-*>);
  151       ############## New Code ########################
  152             exit(0);
  153     }
  154   }
  155 }
  156 
  157 
  158 
  159 
  160 my $endtime = time;
  161 my $totaltime = ($endtime - $starttime)/60;
  162 
  163 print "\n\nThis took $totaltime minutes to precreate $fileName \n\n";
  164 
  165 
  166 
  167 sub defineProblemEnvir {
  168     my ($mode,$probNum,$psvn,$courseName,$refSubmittedAnswers)      =   @_;
  169     my %envir=();
  170     my $loginName = &getStudentLogin($psvn);
  171     ##how to put an array submittedAnswers in a hash??
  172     $envir{'refSubmittedAnswers'}   =   $refSubmittedAnswers if defined($refSubmittedAnswers);
  173     $envir{'psvnNumber'}        =   $psvn;
  174     $envir{'psvn'}            =   $psvn;
  175     $envir{'studentName'}       =   &CL_getStudentName($loginName);
  176   $envir{'studentID'}         = &CL_getStudentID($loginName);
  177   $envir{'studentLogin'}        = $loginName;
  178   $envir{'sectionName'}       = &CL_getClassSection($loginName);
  179   $envir{'sectionNumber'}       = &CL_getClassSection($loginName);
  180   $envir{'recitationName'}      = &CL_getClassRecitation($loginName);
  181   $envir{'recitationNumber'}      = &CL_getClassRecitation($loginName);
  182   $envir{'setNumber'}         = &getSetNumber($psvn);
  183   $envir{'questionNumber'}        = $probNum;
  184   $envir{'probNum'}           = $probNum;
  185   $envir{'openDate'}          = &getOpenDate($psvn);
  186   $envir{'formattedOpenDate'}     = &formatDateAndTime(&getOpenDate($psvn));
  187   $envir{'dueDate'}           = &getDueDate($psvn);
  188   $envir{'formattedDueDate'}      = &formatDateAndTime(&getDueDate($psvn));
  189   $envir{'answerDate'}        = &getAnswerDate($psvn);
  190   $envir{'formattedAnswerDate'}   = &formatDateAndTime(&getAnswerDate($psvn));
  191   $envir{'problemValue'}        = &getProblemValue($probNum,$psvn);
  192   $envir{'fileName'}          = &getProblemFileName($probNum,$psvn);
  193   $envir{'probFileName'}        = &getProblemFileName($probNum,$psvn );
  194   $envir{'displayMode'}       = $mode;
  195   $envir{'languageMode'}        = $mode;
  196   $envir{'outputMode'}        = $mode;
  197   $envir{'courseName'}        = $courseName;
  198   $envir{'sessionKey'}        = ( defined($main::in{'key'}) ) ?$main::in{'key'} : " ";
  199 
  200 
  201   # initialize constants for PGanswermacros.pl
  202   $envir{'numRelPercentTolDefault'}   =     getNumRelPercentTolDefault();
  203   $envir{'numZeroLevelDefault'}   =     getNumZeroLevelDefault();
  204   $envir{'numZeroLevelTolDefault'}  =     getNumZeroLevelTolDefault();
  205   $envir{'numAbsTolDefault'}      =     getNumAbsTolDefault();
  206   $envir{'numFormatDefault'}      =     getNumFormatDefault();
  207   $envir{'functRelPercentTolDefault'} =     getFunctRelPercentTolDefault();
  208   $envir{'functZeroLevelDefault'}   =     getFunctZeroLevelDefault();
  209   $envir{'functZeroLevelTolDefault'}  =     getFunctZeroLevelTolDefault();
  210   $envir{'functAbsTolDefault'}    =     getFunctAbsTolDefault();
  211   $envir{'functNumOfPoints'}      =     getFunctNumOfPoints();
  212   $envir{'functVarDefault'}       =     getFunctVarDefault();
  213   $envir{'functLLimitDefault'}    =     getFunctLLimitDefault();
  214   $envir{'functULimitDefault'}    =     getFunctULimitDefault();
  215   $envir{'functMaxConstantOfIntegration'} = getFunctMaxConstantOfIntegration();
  216   $envir{'numOfAttempts'}             =     undef;
  217 
  218   # defining directorys and URLs
  219   $envir{'templateDirectory'}       = &getCourseTemplateDirectory();
  220   $envir{'classDirectory'}        = $Global::classDirectory;
  221   $envir{'cgiDirectory'}        = $Global::cgiDirectory;
  222   $envir{'cgiURL'}                    =   getWebworkCgiURL();
  223   $envir{'macroDirectory'}        = getCourseMacroDirectory();
  224   $envir{'courseScriptsDirectory'}    = getCourseScriptsDirectory();
  225   $envir{'htmlDirectory'}             =   getCourseHtmlDirectory();
  226   $envir{'htmlURL'}           = getCourseHtmlURL();
  227   $envir{'tempDirectory'}             =   getCourseTempDirectory();
  228   $envir{'tempURL'}                   =   getCourseTempURL();
  229   $envir{'scriptDirectory'}       = $Global::scriptDirectory;
  230   $envir{'webworkDocsURL'}        = $Global::webworkDocsURL;
  231   $envir{'externalTTHPath'}       = $Global::externalTTHPath;
  232 
  233   $envir{'inputs_ref'}        = {user => 'practice1',course => 'demoCourse', key => ' '};
  234     # no inputs when in this mode
  235   $seed = &getProblemSeed($probNum, $psvn);
  236   $seed = 0 unless defined($seed);
  237 
  238   $envir{'problemSeed'}     =   $seed if defined($seed);
  239 
  240   my $k;
  241   foreach $k (keys %Global::PG_environment ) {
  242     $envir{$k} = $Global::PG_environment{$k};
  243   }
  244   %envir;
  245 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9