Subversion Repositories wimsdev

Rev

Rev 16352 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/bin/sh

########################################################################
########################################################################
# script pour reperer des erreurs html dans les modules pedagogiques
########################################################################
#tidy=/usr/local/bin/tidy            # not used any more ?
OUTDIR=result
## Execute from $wimshome/wimstest/validation
## The validator w3c-validator.py should be in this directory
## as well as the cleaning script validator_clean.pl if needed (C=1 below)
##
## usage (results will be in validation/result ) :
##./checkhtmlwims C XXX
## where C is 0 (no cleaning) or 1 (erases uninteresting errors)
##   and XXX may be a module (ex. U1/analysis/oefderint.fr)
##             or a category of modules (ex. U1/analysis)
##             or a comma-separated list of zones (ex. U1,E5,Lang,devel)
##             or empty : in this case all "level"-zones (E1..U4) and Lang are treated.
##
## Example : ./checkhtmlwims 1 U1/analysis/oefderint.fr
##
## ATTENTION = etre en mode non debug (sinon la recuperation des sessions ne fonctionne pas)
## il faudrait faire autrement pour les detruire.

wimsdir=`pwd`
### modify if one prefer to launch from wims directory
moddir="$wimsdir/../../public_html/modules"
configdir=.
zone=$2
if [ $zone ]; then
  echo $zone;
else
  zone='E1 E2 E3 E4 E5 E6 H1 H2 H3 H4 H5 H6 U1 U2 U3 U4 Lang'
fi;

## level of second argument under the directory public_html/modules = number of non terminal "/" characters
## used to know if argument is a zone, a category or a module.
level=`echo $2 | grep -o '/.' | wc -l`

clean=$1;
wordtosearch="missing"
searchmathml="ERROR"
searchmathml2="Unknown"

#tidy=$tidy -qe --doctype html5 -latin1 -config $config/config.txt
##https://github.com/srackham/w3c-validator/blob/master/w3c-validator.py
validator="$configdir/w3c-validator.py"
cleanup="$configdir/validator_clean.pl --option=$clean"
mkdir -p $OUTDIR
#rm -f html.log;rm -f scorelog ;rm -f htmldoclog ;rm -f pari.log;rm -f maxima.log;rm -f gap.log;rm -f octave.log;rm -r mathml.log

## chain to look for in Exindex : here is the list of oef exercises of the module
mot='!set exolist  =!char 1 to -2 of'
forsession='The server is under debug mode. Your session: '
### chercher la liste des exos
###!set exolist  =!char 1 to -2 of mult1,mult2,mult3,mult4,mult5,mult6,mult7,mult8,division1,division2,division3,
###dans Exindex
check ( ) {
  mod=$2
  outputdir=$OUTDIR/$3/$4$5
  clean=$1
  mkdir -p $outputdir
  rm -f $outputdir/html.log $outputdir/scorelog $outputdir/pari.log $outputdir/maxima.log $outputdir/gap.log $outputdir/octave.log $output/mathml.log $output/htmlintro.log

  author=`grep "author" $moddir/$mod/INDEX | sed -e "s/author=//g"`
  email=`grep "\baddress" $moddir/$mod/INDEX | sed -e "s/address=//g"`
  category=`grep category $moddir/$mod/INDEX | sed -e "s/category=//g"`
  message=`wget "http://127.0.0.1/wims/wims.cgi?module=$mod" -nv -O  test_intro.html ; $validator test_intro.html  2>&1; `
  if [ "$message" ] ; then
    echo -e "BEGIN $author\t$email\tmodule=$mod\tintro\n$message END\n" > $outputdir/html.log ;
  fi
  if [ "$category" = "document" ] ; then
    lblock=`ls $moddir/$mod/doc/1/*.def` ;
    for bl in $lblock ; do
#####doc=1
      block=`basename $bl .def`
      message=`wget "http://127.0.0.1/wims/wims.cgi?module=$mod&doc=1&block=$block&job=read" -nv -O  test.html ; $validator test.html  2>&1; `
     # session=`grep -e "$forsession\s*[[:alnum:]]" test.html | sed -e "s/The server is under debug mode. Your session: //g" | sed -e "s|. <br />||g" sed -e "s| ||g"` ;
      if [ "$message" ] ; then
       echo -e "BEGIN $author\t$email\tmodule=$mod block=$block\n$message END\n" >> $outputdir/html.log ;
      fi ;
      mathml=`grep "$searchmathml" test.html` ;
      if [ "$mathml" ] ; then
       echo -e "$author\t$email\tmodule=$mod block=$block\t$mathml\n" >> $outputdir/mathml.log
      fi
      mathml=`grep "$searchmathml2" test.html` ;
      if [ "$mathml" ] ; then
       echo -e "$author\t$email\tmodule=$mod block=$block\t$mathml\n" >> $outputdir/mathml.log
      fi
      pari=`grep -A4 'ERROR from pari' test.html`
      if [ "$pari" ] ; then
       echo -e "$author\t$email\tmodule=$mod&block=$block\t$pari\n" >> $outputdir/pari.log ;
      fi ;
      maxima=`grep -A4 'ERROR from maxima' test.html`
      if [ "$maxima" ] ; then
       echo -e "$author\t$email\tmodule=$mod&block=$block\t$maxima\n" >> $outputdir/maxima.log ;
      fi ;
      octave=`grep -A4 'ERROR from octave' test.html`
      if [ "$octave" ] ; then
       echo -e "$author\t$email\tmodule=$mod&block=$block\t$octave\n" >> $outputdir/octave.log ;
      fi ;
      gap=`grep -A4 'ERROR from gap' test.html`
      if [ "$gap" ] ; then
       echo -e "$author\t$email\tmodule=$mod&block=$block\t$gap\n" >> $outputdir/gap.log ;
      fi ;
     if [ "$session" ] ; then
      # rm -rf $wimsdir/tmp/sessions/$session
      # rm -rf $wimsdir/sessions/$session
      echo $session
     fi ;
    done ;

    $cleanup --dir=$outputdir
  else
    if [ -f $moddir/$mod/Exindex ]; then
      lexo=`grep "$mot" "$moddir/$mod/Exindex" | sed -e "s/$mot//g"| sed -e "s/,/ /g" 2>&1` ;
    fi;
    if [ "$lexo" ]; then motexo="exo";
    else
      ## Here no Exindex was found. If module by Joke Evers, there is usually an "exos" subdirectory
      ## in which the exercises files are named exoxxx and the url is wims.cgi?module=...&subject=xxx
      ## This case is treated by the following. Others (some modules by Xiao) just generate an error message.
      lexo=`ls "$moddir/$mod/exos" | grep exo | sed -e "s/exo//g"`;
      motexo="subject";
    fi;

    scoring=`grep scoring $moddir/$mod/INDEX`
    pari='' ;
    for exo in $lexo ; do
     message=`wget "http://127.0.0.1/wims/wims.cgi?module=$mod&$motexo=$exo&cmd=new" -nv -O  test.html ; $validator test.html  2>&1 ;`
     session=`grep -e "$forsession\s*[[:alnum:]]" test.html | sed -e "s/The server is under debug mode. Your session: //g" | sed -e "s|. <br />||g" | sed -e "s| ||g"` ;

     if [ "$message" ] ; then
       echo -e "BEGIN $author\t$email\tmodule=$mod&$motexo=$exo\n$message END\n" >> $outputdir/html.log ;
     fi ;
     ## inutile d'utiliser tidy
     mathml=`grep "$searchmathml" test.html` ;
      if [ "$mathml" ] ; then
       echo -e "$author\t$email\tmodule=$mod&$motexo=$exo\t$mathml\n" >> $outputdir/mathml.log
      fi
     mathml=`grep "$searchmathml2" test.html` ;
      if [ "$mathml" ] ; then
       echo -e "$author\t$email\tmodule=$mod&$motexo=$exo\t$mathml\n" >> $outputdir/mathml.log
      fi
     pari=`grep -A4 'ERROR from pari' test.html`
     if [ "$pari" ] ; then
       echo -e "$author\t$email\tmodule=$mod&$motexo=$exo\t$pari\n" >> $outputdir/pari.log ;
     fi ;
     maxima=`grep -A4 'ERROR from maxima' test.html`
     if [ "$maxima" ] ; then
       echo -e "$author\t$email\tmodule=$mod&$motexo=$exo\t$maxima"  >> $outputdir/maxima.log ;
     fi ;
     octave=`grep -A4 'ERROR from octave' test.html`
     if [ "$octave" ] ; then
       echo -e "$author\t$email\tmodule=$mod&$motexo=$exo\t$octave"  >> $outputdir/octave.log ;
     fi ;
     gap=`grep -A4 'ERROR from gap' test.html`
     if [ "$gap" ] ; then
       echo -e "$author\t$email\tmodule=$mod&$motexo=$exo\t$gap"  >> $outputdir/gap.log ;
     fi ;
     if [ "$session" ] ; then
      # rm -rf $wimsdir/tmp/sessions/$session
      # rm -rf $wimsdir/sessions/$session
      echo $session
     fi;
    done ;
    #echo "$scoring\t$author\t$email\tmodule=$mod"  >> $outputdir/scorelog ;
    $cleanup --dir=$outputdir ;
  fi
  find $OUTDIR -type d -exec rmdir -p '{}' \;   2> /dev/null
}

if [ $2 ] ; then
  if [ "$level" -eq 2 ] ; then      # ex. E5/francais/oeflecture.fr
    check $clean "$2" one
  elif [ "$level" -eq 1 ] ; then    # ex. E5/francais
    z=`echo $2 | sed -e 's!\/.*!!g'`
    c=`echo $2 | sed -e 's!.*\/!!g'`
    for a in `ls "$moddir/$z/$c"` ; do
      check $clean $z/$c/$a $z $c $a
    done ;
  else                           # ex. Lang,E5
    zone=`echo $2 | sed -e 's!,! !g'`
    for z in $zone; do
      for c in `ls "$moddir/$z"` ; do
        for a in `ls "$moddir/$z/$c"` ; do
          check $clean $z/$c/$a $z $c $a
        done ;
      done ;
    done ;
  fi
else                             # no argument
  for z in $zone; do
    for c in `ls "$moddir/$z"` ; do
      for a in `ls "$moddir/$z/$c"` ; do
        check $clean $z/$c/$a $z $c $a
      done ;
    done ;
  done;
fi