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

Un livre de Wikilivres.
Contenu supprimé Contenu ajouté
m →‎text list for test : Correction de coquille
m →‎src/header.inc.sh : Correction de coquilles
Ligne 224 : Ligne 224 :
ls -al $Booksdir/$1
ls -al $Booksdir/$1
fi
fi
#O cat Book variables
#O Cat Book variables
echo; echo -n -e "$(gettext ' \033[33mVariables in the project directory : ')"; echo -e "$Booksdir/$1 \033[0m"
echo; echo -n -e "$(gettext ' \033[33mVariables in the project directory : ')"; echo -e "$Booksdir/$1 \033[0m"
source $Varsdir/$1.var
source $Varsdir/$1.var
cat $Varsdir/$1.var
cat $Varsdir/$1.var
#O list the content of local book
#O List the content of local book
echo; echo -n -e "$(gettext ' \033[33mLink to the local html book : ')"; echo -e "$Booksdir/$1 \033[0m"
echo; echo -n -e "$(gettext ' \033[33mLink to the local html book : ')"; echo -e "$Booksdir/$1 \033[0m"
ls -1R $Booksdir/$1/$Site | tail -n 2 | sed "s/:/\//g" | tr -d "\n"; echo; echo
ls -1R $Booksdir/$1/$Site | tail -n 2 | sed "s/:/\//g" | tr -d "\n"; echo; echo

Version du 20 mai 2021 à 08:32

Remarquelink={{{link}}}

Ce fichier d'entête doit être inclus dans tous les modules par la commande 'source' :
source $Bindir/header.inc
Dans ses dernières versions :
- header.inc.sh est un fichier source et header.inc est un script exécutable dont les commentaires d'organigramme #O #P et #T pour les programmeurs sont supprimés. Les commentaires de structure #S ont été réduits au minimum.
- Les messages en anglais sont introduits pour l'internalisation avec gettext.
En deuxième partie: exemple de fichier de commande d'un test tests/header.inc/test_header.inc.bash

src/header.inc.sh

#!/bin/bash
#H File    : bin/header.inc or src/header.inc.sh
#H Version : 2020-05-24
#H Syntax  : header.inc [ <book-name> | ? ] [ -v ] [ -pb | -pc ]
#H Example : ./header.inc LivreTest (on the terminal for unit tests)
#H Creation: 2020-03-24 
#H           see https://fr.wikibooks.org/wiki/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 : 2020-06-15 by GC to update for translations and tests
#H Update on fr:Wikibooks : 2020-06-17
#H Last update : 2021-05-19
#H
#w NEW 17/05/2021: The books are now in the Book directory
#
#F Documentation en français
#F Le langage shell bash a été choisi plutôt d'autres shells pour son 
#F   universalité, c'est le langage de base pour apprendre. On trouve
#F   la documentation dans toutes les langues et c'est aussi le plus
#F   rapide à l'exécution, ce n'est pas un langage interprété, c'est du
#F   code quasi binaire en dehors du temps consacré au contrôle de la
#F   syntaxe à chaque exécution.
#F Le fichier de commandes header.sh doit être inclus dans tous les
#F   modules de test du programme principal. Il initialise le
#F   répertoire des commandes, le répertoire de travail du projet;
#F   le répertoire du projet est le nom du livre, de
#F   l'article ou de la page. Si ces répertoires n'existent pas ils 
#F   seront créés.
#F
#F Ce projet éducatif et de tests est destiné à être utilisé en liens 
#F   avec wikilivres en langue anglaise et caractères UTF8. 
#F Les langues supportées pour les messages sont obtenues par édition 
#F   des fichiers .pot avec poedit pour produire les fichiers .po 
#F   d’interprétation dans des langues différentes. Les fichiers .pot 
#F   et .po sont enregistrés dans le répertoire ‘resource’ avant d’être 
#F   copiés dans le système unix ou linux.
#F Les manuels sont écrits en anglais et français et peuvent être 
#F   traduits dans d'autres langues.
#F
#w Les variables Site et SitePrefix se rapportent à "fr.wikibooks.org"
#w    des anciennes versions sont supprimés depuis les versions 210501
#w
#F Le programme est prévu pour fonctionner à l'initiative du 
#F   contributeur qui doit copier la page "Contenus" ou la page de  
#F   compilation dans le répertoire des livres :
#F    "~/Add_appendix/books/<nom du livre>"
#F   Depuis les versions de mai 2021 ce travail peut être facilité avec
#F   le programme pre-annex.sh
#F Les modules de programmes sont indépendants pour les tests, 
#F   cependant ils doivent  être exécutés dans l'ordre 
#F    ./header.sh <livre>, ./lister <livre>, ./télécharger <livre>
#F    ./ajouter_sclt <livre>, ./ajouter_sclic, ./ajouter_sclip <livre>
#F La liste des pages à analyser est indispensable dans tous les 
#F   modules en tests. Ils auront été copiés par vous-même ou par
#F   le programme pre-annex et seront listés par le module lister.
#F   L'absence de la liste des pages à analyser est signalée à chaque
#F   lancement des modules du programme principal "Annexer" par
#F   l'exécution de header.inc inclus dans chaque module en test.
#F

#E English documentation
#E

#O . gettext for message internationalization
. gettext.sh

VERSION=210519
#O Clean messages on terminal
    clear
#O Create the function tests_header_syntax
    function tests_header_syntax
    {
      echo
      echo "$(gettext ' Syntax of the header.inc command in test mode if the book is already created : '$0' <bookname> --t ')"
      echo "$(gettext ' Example : '$O' TestBook --t ')"
      echo "$(gettext ' Second syntax command in test mode if the book is not created : '$0' - --t ')"
      echo "$(gettext ' Example : '$0' --v or '$0' ? --t ')"
	  echo 
      exit 0
    }
#O If first parmeter is empty, print the error and suggest the help syntax
    if test -z $1; then echo "$(gettext ' Error: input parameter is empty, see  the command : header.inc ? ')"; exit -1; fi
#O If help is requested
    if [ "$1" = '?' ]; then
      if [ "$2" = "--t" ]; then tests_header_syntax; else echo "Syntax : header.inc bookame"; exit 0; fi
    fi
#O Display header.inc version on demand with option -v for first parameter
    if [ "$1" = "--v" ]; then echo " header.inc version $VERSION"; exit 0; echo; fi
#O If the test mode is validated, initialize the Testmode variable to true
    if [ "$2" = "--t" ]; then echo -n "Tests mode $2; "; Testsmode="true"; echo "Testmode = $Testsmode"; fi
#O Directories initialization, install, working, binaries, tests directories
#O If the file 'installdir.var exist in vars dir, include installdir.var 
    if [ -e ~/Add_appendix/vars/installdir.var ]
    then 
      source ~/Add_appendix/vars/installdir.var
#O Else, print the problem and offer to reinstall Add_appendix directories 
    else
      echo -n "Current directory in $0 "; pwd
      echo "~/Add_appendix/vars/installdir.var not found in $0 command"
      echo -e "\033[47m\033[1;30m Re-install Add_Appendix ? \033[0m"
      read -s -n1 -p "inkey y/n: " Inkey; echo "$Inkey"
      if [ "$Inkey" = 'y' ]; then
        ~/Add_appendix/sbin/users_install_annex.sh Add_appendix
        #xdg-open https://fr.wikibooks.org/wiki/Auto-éditer_un_wikilivre/Annexer_\(Version_internationalisée\)/users_install_annex.sh
        exit 0
      else exit -1
      fi
    fi
#O Initialize all global directories
#P In Install directories :
    Bindir=$Installdir/bin
    Libdir=$Installdir/lib
    Mandir=$Installdir/man
    Sharedir=$Installdir/share
    Sbindir=$Installdir/sbin
#P In working directory :
    Booksdir=$Workdir/books
    Datasdir=$Workdir/datas 
    Resources=$Workdir/resources
    Testsdir=$Workdir/tests
    Varsdir=$Workdir/vars
#O If testmode is true (--t), print global directories variables
    if [ "$Testsmode" = "true" ]; then
      echo "* Install directory = $Installdir"
      echo -e "\033[47m\033[1;30m In install directories \033[0m"
      echo "  Executables directory = $Bindir"
      echo "- Library directory = $Libdir"
      echo "- Manuals directory = $Mandir"
      echo "- Share directory = $Sharedir"
      echo "- Admin directory = $Sbindir"
      echo
      echo "* Working directory = $Workdir"
      echo -e "\033[47m\033[1;30m In Working directory \033[0m"
      echo "- Books directory = $Booksdir"
      echo "- Datas directoy = $Datasdir"
      echo "- Resources directory = $Resources"
      echo "- Tests directory = $Testsdir"
      echo "- Variables directory = $Varsdir"
    fi 
#O Check for the presence of the annex.lib file
    if test -e $Libdir/annex.lib  
    then if [ "$Testsdmode" = "true" ]; then echo; echo " $Libdir/annex.lib is found"; fi
    else
      echo "To continue, copy annex.lib to $Libdir"
      exit -1
    fi
#O Initialize $Conversions variable
    Conversions="$Datasdir/conversions.dat"    
#O If the command is local for tests, clean the old file and create a new conversions file
    if [ "$Testsdmode" = "true" ] 
    then 
      echo; echo "$(gettext ' When the command tests is $Testsdir, then conversion file is recreated to ')"$Conversions
      rm $Conversions
    fi
#O Create or recreate the conversions.dat file in datas directory
    if test -e "$Conversions"
    then echo "$(gettext ' The conversion file is present ')"
    else 
    {
      echo "s/%24/\$/g;s/%21/\!/g;s/%25/%/g;s/%2B/+/g;s/%3C/\\\&lt\;/g;s/%3E/\&gt\;/g;" >> $Conversions
      echo "s/%5C/\\\/g;s/%B0/°/g" >> $Conversions
      echo "s/%E0/à/g;s/%E2/â/g" >> $Conversions
      echo "s/%E8/è/g;s/%E9/é/g;s/%EA/ê/g;s/%EB/ë/g" >> $Conversions
      echo "s/%EE/î/g;s/%EF/ï/g" >> $Conversions
      echo "s/%F4/ô/g" >> $Conversions
      echo "s/%F9/ù/g;s/%FB/û/g" >> $Conversions
      echo "s/%25/%/g;" >> $Conversions
      echo "s/%28/(/g;s/%29/)/g;" >> $Conversions
      echo "s/%2B/+/g;" >> $Conversions
      echo "s/%3A/:/g;" >> $Conversions
      echo "s/%3D/=/g;" >> $Conversions
      echo "s/%5B/[/g;" >> $Conversions
      echo "s/%5D/]/g" >> $Conversions
      echo "s/%3B/;/g;s/%2F/\//g;s/%27/''/g" >> $Conversions
      echo 's/%22/"/g' >> $Conversions
      echo "s/%C3%A7/ç/g;s/%E7/ç/g" >> $Conversions
      echo "s/%C3%A0/à/g;s/%C3%A2/â/g" >> $Conversions
      echo "s/%C3%A9/é/g;s/%C3%A8/è/g;s/%C3%AA/ê/g" >> $Conversions
      echo "s/%C3%AE/î/g;s/%C3%AF/ï/g" >> $Conversions
      echo "s/%C3%B4/ô/g" >> $Conversions
      echo "s/%C3%B9/ù/g;s/%C3%BB/û/g" >> $Conversions
      echo "s/%C2%B7/-/g;s/%C2%AB/«/g;s/%C2%BB/»/g" >> $Conversions
    }
      echo "$(gettext ' The file conversions.dat is created or updated in file : ')" $Conversions
    fi
#O If the first parameter is a project in the books directory
    if test -d $Booksdir/$1; then
#O   Initialize Books variables
      if test -e "$Varsdir/$1.var"; then source $Varsdir/$1.var; 
      else 
        echo -e "$(gettext ' \033[31m'$1' variables not found in '$Varsdir'.\033[0m ')";
        echo -n "Site=" > $Varsdir/$1.var; ls $Booksdir/$1 | grep wikibooks >> $Varsdir/$1.var
        echo "Bookname=$1" >> $Varsdir/$1.var 
#O     Get suffix in Project directory and intialize Suffix
        echo "$(gettext ' Get the suffix in project directory and put it in vars/$1.var : ')"
        if test -e "$Booksdir/$1/$1.contents"; then cat $Booksdir/$1/$1.contents; echo "Suffix=contents" >> $Varsdir/$1.var
        elif test -e "$Booksdir/$1/$1.summary"; then cat $Booksdir/$1/$1.summary; echo "Suffix=summary" >> $Varsdir/$1.var
        elif test -e "$Booksdir/$1/$1.compiled"; then cat $Booksdir/$1/$1.compiled; echo "Suffix=compiled" >> $Varsdir/$1.var
        else echo "$(gettext ' List of links to articles to be analyzed : not found ')"
        fi
      fi
    fi      
#O Print articles to be analyzed and if list-file exist
    echo
    echo -n "$(gettext ' Test if the file $Project/$1.list, exists : ')"; echo "$Booksdir/$1/$1.list"
   if test -e "$Booksdir/$1/$1.list"
    then 
      echo "$(gettext ' Yes, the file exists. ')" 
    else 
      echo -e "$(gettext ' \033[31mNo, '$Booksdir/$1/$1.list' is not yet created.\033[0m ')"
    fi
#O Test if the .prj file exist and print the result
    echo -n "$(gettext ' Test if the file $Project/$1.prj, exists: ')"; echo "$Booksdir/$1/$1.prj"
    if test -e "$Booksdir/$1/$1.prj"
    then echo "$(gettext ' Yes, the file exists. ')" 
    else echo -e "$(gettext ' \033[31mNo, '$Booksdir/$1/$1.prj' is not yet created.\033[0m ')"
    fi
#O If the first parameter is not empty, print the file list in the project diretory
    if test -n $1 
    then echo; echo -e -n "$(gettext ' \033[33mContents in the project directory : ')"; echo -e "$Booksdir/$1 \033[0m"
      ls -al $Booksdir/$1 
    fi
#O Cat Book variables 
    echo; echo -n -e "$(gettext ' \033[33mVariables in the project directory : ')"; echo -e "$Booksdir/$1 \033[0m"
    source $Varsdir/$1.var
    cat $Varsdir/$1.var
#O List the content of local book
    echo; echo -n -e "$(gettext ' \033[33mLink to the local html book : ')"; echo -e "$Booksdir/$1 \033[0m"
    ls -1R $Booksdir/$1/$Site | tail -n 2 | sed "s/:/\//g" | tr -d "\n"; echo; echo
# End header.inc.sh

tests/header.inc/tests_header.inc.bash

Exemple de fichier de commande d'un test dans le répertoire ~/Add_appendix/tests/header.inc/.
#! /bin/bash
#P file : tests_header.inc.bash
#P Syntax ./tests_header.inc.bash

VERSION=210519

#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 directory not found"; exit -1;fi
    rm pwd.txt
    
#O Download global variables
    source $Workdir/vars/installdir.var
    
#P Print test_header.inc.bash version
    echo " test-header.inc.bash version = $VERSION"
    sleep 2
#T    echo "----"
    
#P Print command header.inc.sh version
#T    echo "Command header.inc.sh --v to veriy header.inc version"
    ./header.inc.sh --v
    echo;echo " wait for 2 sec"
    sleep 2; echo "----"
    
#O Control if the test header.inc.sh file is clean
    echo -e "\033[1;33m Control header.inc.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" header.inc.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

#T test header.inc.sh in test-mode
echo "Command ./header.inc.sh - --t to verify environnement variables"
echo "  in test mode with first param empty"
./header.inc.sh - --t
echo;echo " wait for 2 sec"
sleep 5; echo "----"

#T test with first param empty
echo "Command ./header.inc.sh without parameter"
./header.inc.sh
echo;echo " wait for 2 sec"
sleep 2; echo "----"

#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 ./header.inc.sh LivreTest --t
      elif [ "$Inkey" = "2" ]; then ./header.inc.sh Hélices_de_navires_à_déplacement --t
      elif [ "$Inkey" = "3" ]; then ./header.inc.sh TestBook --t
      elif [ "$Inkey" = "4" ]; then ./header.inc.sh Mkd_\(Extracteur_de_documents\) --t
      elif [ "$Inkey" = "5" ]; then ./header.inc.sh Faire_fleurir_le_sel --t
      elif [ "$Inkey" = "6" ]; then ./header.inc.sh Faire_sa_fleur_de_sel --t      
      elif [ "$Inkey" = "7" ]; then ./header.inc.sh Guide_to_Unix --t
      elif [ "$Inkey" = "8" ]; then ./header.inc.sh Tests_de_la_capacité_des_batteries_d%27accumulateurs
      elif [ "$Inkey" = "9" ]; then ./header.inc.sh LivreTest --t
      else echo "$inkey full url of site not found"; exit 0
      fi
    done
#O End tests_header.inc.bash

List to tests header.inc

sitelist.sh

#!/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"
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"

text list for tests

Sitelist.txt

sitelist to test annex programs
�[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