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

Un livre de Wikilivres.
Contenu supprimé Contenu ajouté
→‎pre-annex.sh : Mise à jour de version
m →‎test_pre-annex.bash : Mise à jour des dates de version
Ligne 202 : Ligne 202 :
#H : ./test_pre-annex.bash [ --v | <full-url-book-name> ] --t
#H : ./test_pre-annex.bash [ --v | <full-url-book-name> ] --t
VERSION=210513
VERSION=210520


#O Clean screen
#O Clean screen

Version du 20 mai 2021 à 10:01

pre-annex.sh

Documentation
#D pre-annex program documentation
#D This program use findbook to analyse the link to the book
#D If the result is correct, create the project directory, pre-create the
#D - file project.suffix and create a local html book in project directory.
#D If everything is correct, edit a collection file or a book contents file
#D - to manually copy the content to the project/project.suffix file
#D It is also proposed to display the local book in the navigator
#D
#F Documentation du programme pre-annex 
#F Ce programme pré-annexe la construction de l'annexe du livre
#F Si ce programme s'est bien exécuté, le répertoire de projet aura été créé
#F - le fichier projet.suffixe et un livre local auront été créés dans le
#F - répertoire projet
#F Si tout est correct il est proposé d'éditer la compilation ou la page de
#F - contenu afin d'être recopiée manuellement dans le fichier projet.suffixe
#F Il est également proposé d'afficher le livre local dans le navigateur
Program pre-annex code
#!/bin/bash
#H Workdir is ~/Add_appendix or ~/Annexer
#H Source file     : Workdir/src/pre-annex.sh
#H Executable file : Workdir/bin/pre-annex
#H Syntax : pre-annex [ Full-url-of-book || --v ]
#H Example : ./pre-annex.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
#P  https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
#P  https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel
#H Created : 12/05/2021 by GC
#H Last Update on fr:Wikibooks :
#H Tested  : by GC 12/05/2021
#H Updated :  by user GC For layout
#H
#D pre-annex program documentation
#D This program use findbook to analyse the link to the book
#D If the result is correct, create the project directory, pre-create the
#D   file project.suffix and create a local html book in project directory.
#D If everything is correct, edit a collection file or a book contents file
#D   to manually copy the content to the project/project.suffix file
#D
#w Install Add_appendix or Annexer with the program executable users_install_annex.sh
#W https://fr.wikibooks.org/wiki/Auto-éditer_un_wikilivre/Annexer_(Version_internationalisée)/users_install_annex.sh
#w Attention, the character ';' at the end of the line is equal to '\' before NL
#w   if the following line is a comment, it will concatenate it at the end of
#w   the previous line and the command with grep -v deletes the whole line
#w


VERSION=210520

#O If first parameter is "--v", print pre-annex version
    if [ "$1" = "--v" ]; then echo " pre-annex version $VERSION"; exit 0; fi
#O If first parameter is empty, print the syntax
    if test -z $1
    then 
      echo "Syntax : pre-annex [ --v | Full-url-of-book ] [ --t ] (with bin directory in environment variables)"
      echo "  Example in tests directory tests/pre-annex.sh/ :"
      echo "  ./pre-annex.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel --t"
      exit -1
    fi
#O Else, the first parameter is not empty
#P Include install variables
    pwd > pwd.txt
    if cat pwd.txt | grep ~/Annexer; then Workdir=~/Annexer; elif cat pwd.txt | grep ~/Add_appendix; \
    then Workdir=~/Add_appendix; else echo "Workind directory not found"; exit -1;fi
    rm pwd.txt
    source $Workdir/vars/installdir.var
    if [ "$1" = "--t" ] || [ "$2" = "--t" ] ; then echo; echo "Global install variables :"; cat $Workdir/vars/installdir.var; fi
#T Test break exit 0
#O Find function findbook 
    Libdir=$Workdir/lib
    Booksdir=$Workdir/books
    if test -e $Libdir/annex.lib; then source $Libdir/annex.lib; elif test -e $Libdir/src/findbook.sh; \
    then source $Libdir/src/findbook.sh; else echo "Function findbook not found"; exit-1; fi
#O Find book parameter
    findbook $1
#O If option --t, print the book parameter
    if [ "$2" = "--t" ]
    then
      echo
      echo -n "--t : "; findbook --v
      echo "--t : Global variables after findbook execution : " 
      echo "--t : Site name :"$Site
      echo "--t : Bookname : "$Bookname 
      echo "--t : Suffix : "$Suffix 
      echo "--t : Bookname.Suffix = "$Bookname.$Suffix
      if [ "$Suffix" = "compiled" ]
      then 
        if test -n $MWcompilurl; then
        echo "Compil mw url : "--t : $MWcompilurl
        echo -n "--t :   Compil mw syntax = [[ "$MWcompilurl; echo " ]] on $Site"
        echo "--t : Compil full url : "$Compilfullurl
        fi
      else
        if test -n $MWbookurl; then
        echo "--t : mw book url = "$MWbookurl
        echo -n "--t :   mw book syntax = [[ "$MWbookurl/$Bookname; echo " ]] on $Site"
        echo "--t : Book full url = "$Bookfullurl
        fi
      fi 
      echo " ----"
    fi
#O If all parameter are found carry continue otherwise print the error
    if ! test $Site || ! test $Bookname || ! test $Suffix
    then
      if ! test $Site; then echo "Site not found";fi
      if ! test $Bookname; then echo "Bookname not found";fi
      if ! test $Suffix; then echo "Suffix not found";fi
    fi
#O Create the project directory
    Projectdir=$Booksdir/$Bookname
    if ! test -d "$Projectdir"; then mkdir $Projectdir; fi 
#O Create the file bookname.suffix
    if test -e $Projectdir/$Bookname.$Suffix
    then
      echo "$Bookname.$Suffix : "
      cat $Projectdir/$Bookname.$Suffix
      echo -e "\033[47m\033[1;30m  Want you update $Projectdir/$Bookname.$Suffix ? \033[0m"
      read -s -n1 -p "inkey y/n : " Inkey; echo $Inkey
      if [ "$Inkey" = "y" ]
      then 
        echo; chmod 755 $Projectdir/$Bookname.$Suffix
        if [ "$Suffix" = "compiled" ]
        then 
          if test -n $MWcompilurl; then echo "[[$MWcompilurl]]" > $Projectdir/$Bookname.$Suffix; fi 
        else
          if test -n $MWbookurl; then echo "[[$MWbookurl]]" > $Projectdir/$Bookname.$Suffix; fi
        fi
      fi
    else 
      if [ "$Suffix" = "compiled" ]
      then 
        if test -n $MWcompilurl; then echo "[[$MWcompilurl]]" > $Projectdir/$Bookname.$Suffix; fi
      else
        if test -n $MWbookurl; then echo "[[$MWbookurl]]" > $Projectdir/$Bookname.$Suffix; fi 
      fi 
    fi
#O Download the book in html form
#O Télécharger le site récursivement avec une profondeur infinie ( -linf ), \
#O convertit les liens pour une consultation en local ( -k ), \
#O rapatrie tous les fichiers nécessaires à l'affichage convenable d'une page HTML ( -p ) \
#O et renomme toutes les pages HTML avec l'extension .html ( -E ) 
   if ! test -d "$Workdir/temp"; then mkdir $Workdir/temp; fi
   cd $Projectdir
   if test -n "$Bookfullurl"; then echo "Dowload $Bookfullurl"; wget -r -linf -k -p -E "$Bookfullurl" -o $Workdir/temp/wget-log-télécharger.txt
   elif test -n "$Compilfullurl"; then echo "Dowload $Compilfullurl"; wget -r -linf -k -p -E "$Compilfullurl" -o $Workdir/temp/wget-log-télécharger.txt
   else echo " book full url not found to download"
   fi
#O If everything is correct, edit a collection file or a book contents file
#O   to manually copy the content to the project/project.suffix file
   if test $Site || test $Bookname || test $Suffix
   then
     echo -e "\033[31mAttention : See and possibly complete the $Bookname.$Suffix "; echo -e "Edit and copy the wiki-code in $Workdir/$Bookname/$Bookname.$Suffix :\033[0m"
     echo -e "\033[47m\033[1;30m  Go forward to edit the book and copy wiki-code to $Bookname.$Suffix ? \033[0m"
     read -s -n1 -p "inkey y/n" Inkey; echo "$Inkey"
     if [ "$Inkey" = 'y' ] 
     then
       gedit $Workdir/$Book/$Bookname/$Bookname.$Suffix&
       xdg-open $1
     fi
   else 
     echo -e "\033[31m Non-compliant result \033[0m"
   fi
   #T xdg-open file:///home/jpl/Annexer/Faire_fleurir_le_sel/fr.wikibooks.org/wiki/Faire_fleurir_le_sel.html
   #T xdg-open https://fr.wikibooks.org/w/index.php?title=Auto-%C3%A9diter_un_wikilivre/Auto-r%C3%A9f%C3%A9rencer/LivreTest/LivreTest.compil%C3%A9&action=edit
   echo -n "$Projectdir/" > localbook.txt
   echo "$Bookfullurl" | cut -d '/' -f3-  >> localbook.txt
#T
cat localbook.txt
   read Localbook < localbook.txt
   Htmlbook=$Localbook.html
   echo "Htmlbook = $Htmlbook"
#T Test break exit 0
   if test -e $Htmlbook; 
   then 
     echo -e "\033[47m\033[1;30m  Do you want to see the local html book ? \033[0m"
     read -s -n1 -p "inkey y/n :" Inkey; echo "$Inkey"; echo
     if [ "$Inkey" = 'y' ]; then xdg-open file://$Htmlbook ; fi
   else echo "$Htmlbook not found" 
   fi
   Varsdir=$Workdir/vars
#O Copy the variables from the book to 'vars/$Bookname.var'
   if test -n "$Site"; then echo "Site=$Site" > $Varsdir/$Bookname.var; fi
   if test -n "$Bookname"; then echo "Bookname=$Bookname" >> $Varsdir/$Bookname.var; fi
   if test -n "$Suffix"; then echo "Suffix=$Suffix" >> $Varsdir/$Bookname.var; fi
   if test -n "$Projectdir"; then echo "Projectdir=$Projectdir" >> $Varsdir/$Bookname.var; fi
   if test -n "$Bookfullurl"; then echo "Bookfullurl=$Bookfullurl" >> $Varsdir/$Bookname.var; fi
   if test -n "$Compilfullurl"; then echo "Compilfullurl=$Compilfullurl" >> $Varsdir/$Bookname.var; fi
   if test -n "$Htmlbook"; then echo "Htmlbook=$Htmlbook" >> $Varsdir/$Bookname.var; fi
#O End pre-annex.sh

test_pre-annex.bash

Install this code in ~/Add_appendix/tests/prannex.sh to test preannex.sh

#!/bin/bash
#H File    : test_pre-annex.bash  executable for testing the program pre-annex
#H Syntax  : ./test_pre-annex.bash <full-url-book-name>  (on the terminal for testing)
#H Example : ./test_pre-annex.bash https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Sandbox/LivreTest/Contenus --t
#H         : ./test_pre-annex.bash [ --v | <full-url-book-name> ] --t
    
VERSION=210520

#O Clean screen
clear

#P Include install variables
    pwd > pwd.txt
    if cat pwd.txt | grep ~/Annexer; then Workdir=~/Annexer; elif cat pwd.txt | grep ~/Add_appendix; \
    then Workdir=~/Add_appendix; else echo "Workind drectory not found"; exit -1;fi
    rm pwd.txt#O Download global variables
    source $Workdir/datas/installdir.var

#O Print prog, version and Why
    if [ "$1" = "--v" ]; 
    then 
      echo "Command 'test_pre-annex.bash' is $VERSION for testing pre-annex function";
      echo "  Options : [ --v | <full-url-book-name> ] --t"
      exit 0;
    fi
    
#O Control if the test pre-annex.sh file is clean
    echo -e "\033[1;33m Control pre-annex.sh in the local test directory \033[0m" > text-control.txt 
    echo -e "\033[1;33m Please check that the comment line does not contain an command \033[0m" >> text-control.txt
    echo -e "\033[1;33m ----  \033[0m"
    grep -n -e "#T\|#O\|#P" pre-annex.sh >> text-control.txt
    more text-control.txt
    echo; echo -e "\033[47m\033[1;30m Continue ? \033[0m"
    read -s -e -n 1 -t 60 -p "y/n ? : " Inkey;echo
#T     echo "Inkey = $Inkey"
    if [ "$Inkey" != 'y' ]; then echo " Inkey is not yes, or time out after 60 sec, exit from $0"; exit 0;fi
    

   echo " Beginning tests without parameter"
   ./pre-annex.sh 
   echo "----"; echo
   sleep 2
   echo " Test whith parameter --v"
   ./pre-annex.sh --v     
   echo "----"; echo
   sleep 2
   
#T Test, all with option --t 
   echo " All tests whith parameter --t"
   
#P List fullurl books for tests
    Inkey=1
    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 ./pre-annex.sh https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Sandbox/LivreTest/Contenu --t
      elif [ "$Inkey" = "2" ]; then ./pre-annex.sh https://fr.wikibooks.org/wiki/Hélices_de_navires_à_déplacement/Sommaire --t
      elif [ "$Inkey" = "3" ]; then ./pre-annex.sh https://en.wikibooks.org/wiki/User:Goelette_Cardabela/sandbox/TestBook/Content --t
      elif [ "$Inkey" = "4" ]; then ./pre-annex.sh https://fr.wikibooks.org/wiki/Mkd_\(Extracteur_de_documents\)/Sommaire --t
      elif [ "$Inkey" = "5" ]; then ./pre-annex.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel --t
      elif [ "$Inkey" = "6" ]; then ./pre-annex.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel --t      
      elif [ "$Inkey" = "7" ]; then ./pre-annex.sh https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix --t
      elif [ "$Inkey" = "8" ]; then ./pre-annex.sh https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/Tests_de_la_capacité_des_batteries_d%27accumulateurs
      elif [ "$Inkey" = "9" ]; then ./pre-annex.sh https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/LivreTest --t
      else echo "$inkey full url of site not found"; exit 0
      fi
    done

sitelist.sh

Install this code in /Add_appendix/tests, to product sitelist.txt

#!/bin/bash
#H File sitelist to test with 'test_preannex.bash in preannex.sh tests directory
#H Application for source ~/Add_appendix/datas/sitelist in 'test_preannex.bash'
#H   or ./sitelist in datas directory in executable mode
#H Create 14/05/2021 by GC
#H Updated 16/05/2021 by GC
#P Make sitelist.txt : ./sitelist > sitelist.txt in datas directory
#
echo "sitelist to test annex programs, version 210516"
echo -e "\033[47m \033[1;32m   Books with Contents or Summary   \033[0m"
echo " 1 - https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Sandbox/LivreTest/Contenu --t"
echo " 2 - https://fr.wikibooks.org/wiki/Hélices_de_navires_à_déplacement/Sommaire --t"
echo " 3 - https://en.wikibooks.org/wiki/User:Goelette_Cardabela/sandbox/TestBook/Content --t"
echo " 4 - https://fr.wikibooks.org/wiki/Mkd_\(Extracteur_de_documents\)/Sommaire --t"
# echo -e "\033[47m \033[1;32m   Books with Contents or Summary   \033[0m"
echo -e "\033[47m \033[1;32m             Collections            \033[0m"
echo " 5 - https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel --t"
echo -e "\033[1;31m  Same book second title \033[0m"
echo " 6 - https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel --t"
echo " 7 - https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix --t"
echo " 8 - https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/Tests_de_la_capacit%C3%A9_des_batteries_d%27accumulateurs"
echo " 9 - https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/LivreTest --t"
# echo -e "\033[47m \033[1;32m   Books with Contents or Summary   \033[0m"
echo -e "\033[47m \033[1;32m          Atypical variants         \033[0m"
echo -e "\033[1;31m  Copy the line (Ctrl-Shift-C) and execute in terminal (Ctrl-Shift-V) \033[0m"
echo " xdg-open https://fr.wikibooks.org/wiki/Auto-éditer_un_wikilivre/Auto-référencer/LivreTest/LivreTest.compilé"
echo " xdg-open https://fr.wikibooks.org/w/index.php?title=Auto-éditer_un_wikilivre/Auto-référencer/LivreTest/LivreTest.compilé&action=edit"

sitelist.txt

sitelist.txt to test program annex sub-programs
sitelist to test annex programs, version 210516
�[47m �[1;32m   Books with Contents or Summary   �[0m
 1 - https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Sandbox/LivreTest/Contenu --t
 2 - https://fr.wikibooks.org/wiki/Hélices_de_navires_à_déplacement/Sommaire --t
 3 - https://en.wikibooks.org/wiki/User:Goelette_Cardabela/sandbox/TestBook/Content --t
 4 - https://fr.wikibooks.org/wiki/Mkd_\(Extracteur_de_documents\)/Sommaire --t
�[47m �[1;32m             Collections            �[0m
 5 - https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel --t
�[1;31m  Same book second title �[0m
 6 - https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel --t
 7 - https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix --t
 8 - https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/Tests_de_la_capacit%C3%A9_des_batteries_d%27accumulateurs
 9 - https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/LivreTest --t
�[47m �[1;32m          Atypical variants         �[0m
�[1;31m  Copy the line (Ctrl-Shift-C) and execute in terminal (Ctrl-Shift-V) �[0m
 xdg-open https://fr.wikibooks.org/wiki/Auto-éditer_un_wikilivre/Auto-référencer/LivreTest/LivreTest.compilé
 xdg-open https://fr.wikibooks.org/w/index.php?title=Auto-éditer_un_wikilivre/Auto-référencer/LivreTest/LivreTest.compilé&action=edit