« Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/annex.sh » : différence entre les versions

Un livre de Wikilivres.
Contenu supprimé Contenu ajouté
m Mise à jour
Ajout de la section "Global test"
Ligne 1 : Ligne 1 :
{{remarqueampoule|{{rouge|incomplet en raison de l'absence des commandes compose.}}<br />testabble jusqu'à la commande sclt.sh inclue.}}
{{remarqueampoule|{{rouge|incomplet en raison de l'absence des commandes compose.}}<br />testabble jusqu'à la commande sclt.sh inclue.}}
== Annex.sh ==
# <syntaxhighlight lang="bash">
# <syntaxhighlight lang="bash">
#!/bin/bash
#!/bin/bash
Ligne 283 : Ligne 284 :
exit 0
exit 0
# End annex command
# End annex command
</syntaxhighlight>

== Global test ==
<syntaxhighlight lang="bash">
#! /bin/bash
#P file : tests_annex.sh
#P Syntax ./tests_annex.sh

clear
VERSION=210616
echo "test_annex.bash VERSION = $VERSION"

Workdir=~/Add_appendix

./annex.sh --v
echo;echo " wait for 2 sec"
sleep 2

#T test with $1 empty
./annex.sh
echo;echo " wait for 2 sec"
sleep 2

clear
./annex.sh ?
echo;echo " wait for 5 sec"
sleep 3

clear
#./annex.sh LivreTest
#echo;echo " wait for 3 sec"
#sleep 3

#O annex local books for tests
Inkey=1
cat $Workdir/tests/sitelist.txt; echo
for i in 'seq 1 9'
do
#cat $Workdir/tests/sitelist.txt; echo
echo -e "\033[47m\033[1;30m Choose the site number to test \033[0m"
read -s -n1 -p "inkey number 1 to 9 : " Inkey; echo;
if [ "$Inkey" = "1" ]; then ./annex.sh LivreTest
elif [ "$Inkey" = "2" ]; then ./annex.sh Hélices_de_navires_à_déplacement
elif [ "$Inkey" = "3" ]; then ./annex.sh TestBook
elif [ "$Inkey" = "4" ]; then ./annex.sh Mkd_\(Extracteur_de_documents\)
elif [ "$Inkey" = "5" ]; then ./annex.sh Faire_fleurir_le_sel
elif [ "$Inkey" = "6" ]; then ./annex.sh Faire_sa_fleur_de_sel
elif [ "$Inkey" = "7" ]; then ./annex.sh Guide_to_Unix
elif [ "$Inkey" = "8" ]; then ./annex.sh Tests_de_la_capacité_des_batteries_d%27accumulateurs
elif [ "$Inkey" = "9" ]; then ./annex.sh LivreTest
else echo "$inkey local url of site not found"; exit 0
fi
done
#O End tests_add_sclt.bash
</syntaxhighlight>
</syntaxhighlight>



Version du 17 juin 2021 à 15:37

Remarquelink={{{link}}}

incomplet en raison de l'absence des commandes compose.
testabble jusqu'à la commande sclt.sh inclue.

Annex.sh

  1. #!/bin/bash
    #H File    : annex and-or annex.sh
    #H Version initiale : 2020-05-24
    #H Syntax  : annex [ <book-name> || ? ] [ -v ] [ -pb || -pc ]
    #H Example : ./annex TestBook (on the terminal for unit tests)
    #H Creation: 2020-03-24 by GC
    #H           see https://fr.wikibooks.org/w/index.php?title=Auto-éditer_un_wikilivre/Auto-référencer#Entête_des_modules
    #H Updated : 2020-05-15 by GC
    #H Updated : 2020-05-24 by GC to translate
    #H Updated : 2021-04-02 by User GC
    #H Last update : 2021-04-22 for tests in tests dir 2-annex.sh
    #H Update on fr:Wikibooks : 2021-03-26 incomplet
    #H
    
    #P header.inc is included in each module for its individual test and 
    #P   permanently in this command file 'annex'.
    
    #P export permanently ~/Add_appendix/bin in ~/.bashrc file : www is not recommended 
    #P echo "export PATH=$PATH:/home/user/mes_prog" >> /home/user/.bashrc 
    #P
    #P export ~/Add_appendix/bin for this session only
    #T export PATH=$PATH:~/Add_appendix/bin 
    #T env | grep Add_appendix
    
    #P . gettext for translation
    . gettext.sh
    
        VERSION=210616
        if [ "$1" = "--v" ]; then echo "Annex version $VERSION"; exit 0; echo; fi
    
        ADD_APPENDIX=$HOME/Add_appendix
    
    #P If first param is empty print the syntax and exit
        if [ -z $1 ]
        then
          echo "$(gettext ' No Parameter ')"
          echo "$(gettext ' Syntax : ~/Add-appendix/bin/annex [ <book/contents url> | <Collections/book url> | ? ] [ -v ] [ -pb | -pc ] ')"; 
          exit 0;
        fi 
            
    #P If help whis the '?' character
        if [ "$1" = "?" ]
        then 
        {
          clear
          echo "$(gettext ' Syntax : ')"
          echo "$(gettext '   annex [ <book/contents url> | <collections/book url> | ? ] [ -v ] [ -pb | -pc ] ')"
          echo "$(gettext '   Options : ')"
          echo "$(gettext '     annex ?, to display the command syntax. ')"
          echo "$(gettext '     -pb for personal version with illustrations on Wikibooks. ')"
          echo "$(gettext '     -pc for personal version with illustrations on Commons. ')"
          echo "$(gettext '     -v  verbose mode. ')"
          exit 0
        }
        fi
    
        if [ -e ~/Add_appendix/vars/installdir.var ]; 
        then 
          source ~/Add_appendix/vars/installdir.var
          echo "datas/installdir.var is found in annex command"; echo
          Bindir=$Installdir/bin
          Testsdir=$Workdir/tests
        else
          echo -n "current directory in $0 "
          pwd
          echo "~/Add_appendix/vars/installdir.var not found in $0 command"
          exit -1
        fi
    
    #T echo "Install directory = $Installdir"
    #T echo "Working directory = $Workdir"
    #T echo "Bin directory = $Bindir"
    #T echo "Tests directory = $Testsdir"
    #T Test break exit 0
    
    #P Include header.inc in binary environnment ~/Add_appendix/bin
        if test -e "$Bindir/header.inc"
        then
          echo "header.inc found in $Bindir"
          source $Bindir/header.inc
        else echo "copy header.inc to $Bindir to continue"; exit -1
        fi
        
    #T Spotting
        echo "*** 'annex' command ***"
        
    #T Test env | grep Add_appendix
        #T echo "Installdir : "$Installdir
    
    #P Initializing modes 
        Verbose="false"
        Personal="false"
        Personalwb="false"
        Personalco="false"   
    #T Breakpoint exit 0
        if (("$#" > "1"))    
        then
          if [ "$2" = "-v" ]
          then
            Verbose="true";
          fi
          if [ "$2" = "-pb" ]
          then
            Personalwb="true"; Personal="true";
          fi
          if [ "$2" = "-pc" ]
          then
            Personalco="true"; Personal="true";
          fi
        fi
        if (("$#" == "3"))
        then
          if [ "$3" = "-v" ]
          then
            Verbose="true";
          fi
          if [ "$3" = "-pb" ]
          then 
            if test "$Personalco" = "false" 
            then 
              Personalwb="true"; Personal="true" 
            else 
              echo "$(gettext ' -annex- Error at command line, parameter three :$3 incompatible with parameter two :$2 ')" 
              exit 1 
            fi;
          fi
          if [ "$3" = "-pc" ]
          then if test "$Personalwb" = "false"; then Personalco="true"; Personal="true"; 
          else echo "$(gettext ' Error at command line, parameter three :$3 incompatible with parameter two :$2 ')"; exit 1; fi;
          fi
        fi
        if (("$#" > "3"))    
        then  
          echo "$(gettext ' -annex- Error : too many parameters ! ')"
          echo "$(gettext ' ./annex ? to display the syntax. ')"
          exit 1
        fi
    
    #P Print variables from the command line
        echo "$(gettext ' The variable Verbose is  initialised at : ')"$Verbose
        echo "$(gettext ' The variable Personalwb is initialised at : ')"$Personalwb
        echo "$(gettext ' The variable Personalco is initialised at : ')"$Personalco
        echo "$(gettext ' The variable Personal is initialised at : ')"$Personal
        echo ""
    #T Test break exit 0  
    
    #P Print files in project directorie, and delete the files according to the answer
        echo "$(gettext ' -Command annex- Files in project directory : ')"
        ls $Project
        echo "$(gettext ' Delete in the project directory : *.html *.str *.img *.lnk tmp temp *.tmp *.temp *.list ? ')"
        echo -e "$(gettext ' \033[31m 'y' to approve the deletion. \033[0m  ')" 
        echo "$(gettext '  Return to continue, Ctrl-C to exit. ')"
        read -n1 -p -s Inkey
        echo "$(gettext ' Inkey = ')"$Inkey
        if [ "$Inkey" = "y" ]
        then 
        {
          cd $Project
          echo -e "$(gettext ' \033[31mDeleting files.\033[0m  ')"
          rm -R *.html *.str *.img *.lnk tmp temp *.tmp *.temp *.list
        }
        else echo "$(gettext ' No file deletion ! ... Continue ... ')"
        fi
         echo "WAIT ..."
        
        if test -d $Workdir/temp/Report-verbose-mode; then rm $Workdir/temp/Report-verbose-mode/*.txt; echo -n "" ; else mkdir $Workdir/temp//Report-verbose-mode; fi;
        if test -d $Workdir/temp/Report-silent-mode; then rm $Workdir/temp/Report-silent-mode/*.txt; echo -n "" ; else mkdir $Workdir/temp/Report-silent-mode; fi;
        
    #T Print Install directory echo "Installdir : in annex command : $Installdir"
    
    #P Running list
        if [ $Verbose = "true" ]
        then $Bindir/list $1
        else $Bindir/list $1 > $Workdir/temp/Report-silent-mode/list-cmd.txt
        fi     
    #P Return value from list
        Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module list in silent mode. See $Workdir/temp/Report-silent-mode/list-cmd.txt ')"
          exit 1
        fi
    #T Breakpoint exit 0
    
    #P Running downloads
        if [ $Verbose = "true" ]
        then $Bindir/download $1
        else $Bindir/download $1 > $Workdir/temp/Report-silent-mode/download-cmd.txt      
        fi  
    #P Return value from downloads
        Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module download in silent mode. See $Workdir/temp/Report-silent-mode/download-cmd.txt ')"
          exit 1
        fi
    
    #P Running add_sclt
        if [ $Verbose = "true" ]
        then   
          $Bindir/add_sclt $1
        else
          $Bindir/add_sclt $1 > $Workdir/temp/Report-silent-mode/add_sclt-cmd.txt
        fi       
    #P Return value from add_sclt        
        Return=$?
        if [ $Return -gt '0' ]
        then
          echo "$(gettext ' Error in shell module add-sclt in silent mode. See $Workdir/temp/Report-silent-mode/add_sclt-cmd.txt ')"
          exit 1
        fi
    #T test break
    exit 0
    #P Running add_sclic
        if [ $Personal = "false" ]
        then
          if [ $Verbose = "true" ]
          then
            $Bindir/add_sclic
          else
            $Bindir/add_sclic $1 > $Workdir/Report-silent-mode/add_sclic-cmd.txt
          fi 
          cat $Project/$1.sclic > $Project/$1.scli
        fi
    #P Return value from add_sclic     
        Return=$?
        if [ $Return -gt '0' ] && [ $Personal = "false" ];
        then
          echo "$(gettext ' Error in shell module add_sclic in silent mode. See Silent-mode/add_sclic-cmd.txt ')"
          exit 1
        fi        
          
    #P If option -pc is validated, running sclipco.sh
        if [ "$Personalco" == "true" ]
        then
          if [ "$Verbose" == "true" ]; then $Bindir/sclipco $1; else $Bindir/sclipco $1 > $Workdir/Report-silent-mode/sclipco-cmd.txt; fi;
          echo "$(gettext ' sclipco has been executed ')";
        fi
    #P Return value from slipco
        Return=$?
        if [ $Return -gt '0' ] && [ $Personalpc = "true" ];
        then
          echo "$(gettext ' Error in shell module slipco. See Silent-mode/sclipco-cmd.txt ')"
          exit 1
        fi     
        
    #P If option -pb is validated, running sclipw
        if [ "$Personalwb" == "true" ]
        then
          if [ "$Verbose" == "true" ]; then $Bindir/sclipwb.inc $1; else $Bindir/sclipwb.inc $1 > $Workdir/Report-silent-mode/scliwb-cmd.txt; fi;
          echo "$(gettext ' sclipwb has been executed ')";
        fi
        if [ $Return -gt '0' ] && [ $Personalwb = "true" ];
        then
          echo "$(gettext ' Error in shell module slipwb. See See Silent-mode/scliwb-cmd.txt ')"
          exit 1
        fi  
    
    #P Flush article, source lisence ant text to project.appendix
        cd $Project
        cat $1.sclt > $1.appendix
    
    #P ? sclip.inc ...?
    #    if [ $Personal == "true" ]
    #    then cat $Project/$1.sclip >> $Project/$1.appendix; echo "$(gettext ' $1.sclip is added to $1.appendix ')";
    #    else
    #      cat $1.sclic >> $1.appendix; echo "$(gettext ' $1.sclic is copied to $1.appendix ')";
    #    fi
    
          echo "$(gettext ' == License == ')" >> $1.appendix
          cat $1/$1.license >> $1.appendix
          echo "" >> $1.appendix
          #P echo "{{Nouvelle page imprimée}}" >> $1.appendix
          #P echo "{{Page-break/end}}" on en:wikibooks >> $1.appendix
          echo "$(gettext ' <br style=\"page-break-after: always\"> ')" >> $1.appendix
          
    echo ""
    echo ""
    echo ""
    echo "$(gettext ' Copy the contents of the file "$1/appendix" to the 'appendix' page of the book  ')"$1.
    exit 0
    # End annex command
    

Global test

#! /bin/bash
#P file : tests_annex.sh
#P Syntax ./tests_annex.sh

clear
VERSION=210616
echo "test_annex.bash VERSION = $VERSION"

Workdir=~/Add_appendix

./annex.sh --v
echo;echo " wait for 2 sec"
sleep 2

#T test with $1 empty
./annex.sh
echo;echo " wait for 2 sec"
sleep 2

clear
./annex.sh ?
echo;echo " wait for 5 sec"
sleep 3

clear
#./annex.sh LivreTest
#echo;echo " wait for 3 sec"
#sleep 3

#O annex local books for tests
    Inkey=1
    cat $Workdir/tests/sitelist.txt; echo
    for i in 'seq 1 9'
    do 
      #cat $Workdir/tests/sitelist.txt; echo
      echo -e "\033[47m\033[1;30m Choose the site number to test \033[0m"
      read -s -n1 -p "inkey number 1 to 9 : " Inkey; echo;
      if [ "$Inkey" = "1" ]; then ./annex.sh LivreTest
      elif [ "$Inkey" = "2" ]; then ./annex.sh Hélices_de_navires_à_déplacement
      elif [ "$Inkey" = "3" ]; then ./annex.sh TestBook
      elif [ "$Inkey" = "4" ]; then ./annex.sh Mkd_\(Extracteur_de_documents\)
      elif [ "$Inkey" = "5" ]; then ./annex.sh Faire_fleurir_le_sel
      elif [ "$Inkey" = "6" ]; then ./annex.sh Faire_sa_fleur_de_sel     
      elif [ "$Inkey" = "7" ]; then ./annex.sh Guide_to_Unix
      elif [ "$Inkey" = "8" ]; then ./annex.sh Tests_de_la_capacité_des_batteries_d%27accumulateurs
      elif [ "$Inkey" = "9" ]; then ./annex.sh LivreTest
      else echo "$inkey local url of site not found"; exit 0
      fi
    done
#O End tests_add_sclt.bash