« Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/header.inc.sh » : différence entre les versions
Contenu supprimé Contenu ajouté
m →tests/header.inc/test_header.inc.sh : suppression d'une coquille |
→src/header.inc.sh : Nouvelle version |
||
Ligne 1 : | Ligne 1 : | ||
{{Remarqueampoule|Ce fichier d'entête doit être inclus dans tous les modules par la commande 'source' : <br />'''''source $Bindir/header.inc'''''<br />Dans ses dernières versions : <br />- ''header.inc.sh'' est un fichier source et ''header.inc'' est un bichier exécutable<br />- Les commentaires d'oganigramme #O sont supprimés. Les commentaires #P pour les programmeurs sont en anglais, les commentaires de structure #S ont été réduits au minimum.<br />- Les messages en anglais sont introduits pour l'internalisation avec gettext.<br />{{Orange|En deuxième partie: exemple de fichier de commande d'un test '''''tests/header.inc/test_header.inc.sh'''''}}}} |
{{Remarqueampoule|Ce fichier d'entête doit être inclus dans tous les modules par la commande 'source' : <br />'''''source $Bindir/header.inc'''''<br />Dans ses dernières versions : <br />- ''header.inc.sh'' est un fichier source et ''header.inc'' est un bichier exécutable<br />- Les commentaires d'oganigramme #O sont supprimés. Les commentaires #P pour les programmeurs sont en anglais, les commentaires de structure #S ont été réduits au minimum.<br />- Les messages en anglais sont introduits pour l'internalisation avec gettext.<br />{{Orange|En deuxième partie: exemple de fichier de commande d'un test '''''tests/header.inc/test_header.inc.sh'''''}}}} |
||
== src/header.inc.sh == |
== src/header.inc.sh == |
||
<syntaxhighlight lang="bash"> |
|||
#!/bin/bash |
#!/bin/bash |
||
#H File : bin/header.inc or src/header.inc.sh |
#H File : bin/header.inc or src/header.inc.sh |
||
Ligne 13 : | Ligne 13 : | ||
#H Updated : 2020-06-15 by GC to update for translations and tests |
#H Updated : 2020-06-15 by GC to update for translations and tests |
||
#H Update on fr:Wikibooks : 2020-06-17 |
#H Update on fr:Wikibooks : 2020-06-17 |
||
#H Last update : 2021- |
#H Last update : 2021-05-19 |
||
#H |
#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 |
. gettext.sh |
||
VERSION=210519 |
|||
Version=210421 |
|||
#O Clean messages on terminal |
|||
Bookname= |
|||
clear |
|||
Suffix= |
|||
#O Create the function tests_header_syntax |
|||
Site= |
|||
function tests_header_syntax |
|||
{ |
|||
clear |
|||
echo |
|||
echo "$(gettext ' Syntax of the header.inc command in test mode if the book is already created : '$0' <bookname> --t ')" |
|||
#P Initializes Bindir |
|||
echo "$(gettext ' Example : '$O' TestBook --t ')" |
|||
if [ "$0" = "./header.inc" ]; |
|||
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 |
then |
||
source ~/Add_appendix/vars/installdir.var |
|||
pwd > pwd.txt |
|||
#O Else, print the problem and offer to reinstall Add_appendix directories |
|||
else |
|||
echo $0 | awk -F"/" '{ for (i=1;i<NF;i++) print $i}' | tr '\n' '/' | sed "s/bin\//bin/g" > pwd.txt |
|||
fi |
|||
read Bindir < pwd.txt |
|||
rm pwd.txt |
|||
#P Tests suite in header.inc |
|||
echo "$(gettext ' Directories in header.inc test environment ')" |
|||
#P Test and print $Bindir if exist or if it's not found |
|||
if test -d $Bindir |
|||
then echo "$(gettext ' The commands directory : ')"$Bindir"$(gettext ' is OK ! ')" |
|||
else echo "$(gettext ' The commands directory ')"$Bindir"$(gettext ' is not found ! ')" |
|||
fi |
|||
echo $Bindir | awk -F"/" '{ for (i=1;i<=NF;i++) print $i}' | tr '\n' '/' | sed s/"\/bin\/"//g > tmp.txt |
|||
read Installdir < tmp.txt |
|||
rm tmp.txt |
|||
if test -d $Installdir |
|||
then echo "$(gettext ' The Installdir : ')"$Installdir"$(gettext ' is OK ! ')" |
|||
else echo "$(gettext ' The Installdir : ')"$Installdir"$(gettext ' is not found ! ')" |
|||
fi |
|||
Libdir="$Installdir/lib" |
|||
if test -d "$Libdir" |
|||
then echo "$(gettext ' The lib directory : ')"$Libdir"$(gettext ' is OK ! ')" |
|||
else echo "$(gettext ' The lib directory ')"$Libdir"$(gettext ' is not OK ! ')" |
|||
fi |
|||
Sharedir="$Installdir/share" |
|||
if test -d "$Sharedir" |
|||
then echo "$(gettext ' The Share directory ')"$Sharedir"$(gettext ' is OK ! ')" |
|||
else |
else |
||
echo -n "Current directory in $0 "; pwd |
|||
mkdir $Sharedir |
|||
echo "~/Add_appendix/vars/installdir.var not found in $0 command" |
|||
echo "$(gettext ' The Share directory ')"$Sharedir"$(gettext ' is created ! ')"; |
|||
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 |
fi |
||
#O Initialize all global directories |
|||
#P In Install directories : |
|||
echo $Bindir > $Sharedir/bindir.txt |
|||
Bindir=$Installdir/bin |
|||
Libdir=$Installdir/lib |
|||
Mandir=$Installdir/man |
|||
Sharedir=$Installdir/share |
|||
Sbindir=$Installdir/sbin |
|||
Workdir=~/Add_appendix |
|||
#P In working directory : |
|||
Booksdir=$Workdir/books |
|||
Datasdir=$Workdir/datas |
|||
then |
|||
Resources=$Workdir/resources |
|||
echo "$(gettext ' The working directory : ')"$Workdir"$(gettext ' is OK ! ')" |
|||
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 |
else |
||
echo "To continue, copy annex.lib to $Libdir" |
|||
mkdir $Workdir |
|||
exit -1 |
|||
echo "$(gettext ' The working directory ')"$Workdir"$(gettext ' is created ! ')"; |
|||
fi |
fi |
||
#O Initialize $Conversions variable |
|||
echo $Sharedir > $Workdir/sharedir.txt |
|||
Conversions="$Datasdir/conversions.dat" |
|||
#O If the command is local for tests, clean the old file and create a new conversions file |
|||
#P Initialyze $Conversions file |
|||
if [ "$Testsdmode" = "true" ] |
|||
Conversions="$Workdir/datas/conversions.dat" |
|||
#P If the command is local for tests, clean the old file and create a new conversions file |
|||
if [ $0 = "./header.inc" ] |
|||
then |
then |
||
echo "$(gettext ' When the command is |
echo; echo "$(gettext ' When the command tests is $Testsdir, then conversion file is recreated to ')"$Conversions |
||
rm |
rm $Conversions |
||
fi |
fi |
||
#O Create or recreate the conversions.dat file in datas directory |
|||
if test -e "$Conversions" |
if test -e "$Conversions" |
||
then echo "$(gettext ' The conversion file is present ')" |
then echo "$(gettext ' The conversion file is present ')" |
||
Ligne 122 : | Ligne 185 : | ||
echo "s/%C2%B7/-/g;s/%C2%AB/«/g;s/%C2%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 |
echo "$(gettext ' The file conversions.dat is created or updated in file : ')" $Conversions |
||
fi |
fi |
||
#O If the first parameter is a project in the books directory |
|||
if test -d $Booksdir/$1; then |
|||
#P Include the header syntax function for individual test |
|||
#O Initialize Books variables |
|||
function header_syntax |
|||
if test -e "$Varsdir/$1.var"; then source $Varsdir/$1.var; |
|||
{ |
|||
else |
|||
echo "$(gettext ' Syntax of the header.inc command in test mode: ./header.inc <book> ')" |
|||
echo "$(gettext ' |
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 "" |
|||
echo "Bookname=$1" >> $Varsdir/$1.var |
|||
exit 0 |
|||
#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 |
|||
#P For a first parameter empty print syntax else print Bookname |
|||
elif test -e "$Booksdir/$1/$1.summary"; then cat $Booksdir/$1/$1.summary; echo "Suffix=summary" >> $Varsdir/$1.var |
|||
if test -z "$1" #S1 |
|||
elif test -e "$Booksdir/$1/$1.compiled"; then cat $Booksdir/$1/$1.compiled; echo "Suffix=compiled" >> $Varsdir/$1.var |
|||
then |
|||
else echo "$(gettext ' List of links to articles to be analyzed : not found ')" |
|||
echo "-----" |
|||
fi |
|||
echo "$(gettext ' Error: no input parameter, see the command : annex ? ')" |
|||
if [ $0 = "./header.inc" ]; #S2 |
|||
then header_syntax; |
|||
else echo "$(gettext ' Syntax : $0 [ <book-name> | ? ] [ -v ] [ -pb | -pc ] ')"; |
|||
exit 1 |
|||
fi #S-2 |
|||
else |
|||
if [ "$1" != "?" ] #S3 |
|||
then |
|||
echo $1 | awk -F "/" '{for (i=0;i<=NF;i++) print $i}' > bookname.txt |
|||
cat bookname.txt | grep wikibooks > sitename.txt |
|||
read Site < sitename.txt |
|||
if test $Site #S4 |
|||
#w ATTENTION: These are strings, perhaps, without content. |
|||
then |
|||
if test -e "$Libdir/annex.lib"; #S5 |
|||
then findbook $1; |
|||
echo $Site > "$Workdir/site.txt"; #T echo "Site name :"$Site |
|||
mkdir $Bookname; echo "Bookname : "$Bookname |
|||
#T Test if variable $Suffix is OK echo "Suffix : "$Suffix |
|||
echo "Bookname.Suffix" > $Workdir/$Bookname; #T echo "Bookname.Suffix = "$Bookname.$Suffix |
|||
else echo "$Libdir/annex not fount"; |
|||
fi #S-5 |
|||
fi #S-4 |
|||
fi #S-3 |
|||
fi #S-1 |
|||
#T Breakpoint exit 0 |
|||
#P If first parameter is the char '?' |
|||
if test $1; |
|||
then |
|||
if [ "$1" = "?" ] |
|||
then |
|||
clear |
|||
header_syntax |
|||
fi |
fi |
||
fi |
fi |
||
#O Print articles to be analyzed and if list-file exist |
|||
echo |
|||
#P Initialize the cariable Project directory |
|||
echo -n "$(gettext ' Test if the file $Project/$1.list, exists : ')"; echo "$Booksdir/$1/$1.list" |
|||
Project=$Workdir/$1 |
|||
if test -e "$Booksdir/$1/$1.list" |
|||
echo "$(gettext ' Project directory : ')"$Project |
|||
echo "----------" |
|||
#P Test if the project diretory exist |
|||
if test -d $Project |
|||
then |
|||
echo "$(gettext ' The project directory : ')"$Project"$(gettext ' is found ! ')" |
|||
echo $Project > $Sharedir/project.txt |
|||
echo "$(gettext ' Default Site name is fr.wikibooks.org, when your book is in another site please modify site.txt ')" > $Workdir/README |
|||
fi |
|||
#P Test the existing file site.txt exist in working directory |
|||
if test -a $Workdir/site.txt |
|||
then |
|||
read Site < "$Workdir/site.txt" |
|||
SitePrefix="https:\/\/$Site\/wiki\/" |
|||
else |
|||
Site="fr.wikibooks.org" |
|||
SitePrefix="https:\/\/fr.wikibooks.org\/wiki\/" |
|||
fi |
|||
echo "----------" |
|||
#P Print Project name, site url, SitePrefix variable |
|||
echo "$(gettext ' Project name: ')"$1 |
|||
echo "$(gettext ' Site: ')"$Site |
|||
echo "$(gettext ' SitePrefix for the shell command sed. ')"$SitePrefix |
|||
echo "----------" |
|||
#P Print the contents variable if exist |
|||
echo "$(gettext ' File contents presence test in header.inc')" |
|||
if test -e $Project/$1.contenu; then echo "$(gettext ' Found : ') $Project/$1.contenu"; |
|||
elif test -e $Project/$1.Contenus; then echo "$(gettext ' Found : ') $Project/$1.Contenus"; |
|||
elif test -e $Project/$1.compilé; then echo "$(gettext ' Found : ') $Project/$1.compilé"; |
|||
elif test -e $Project/$1.Contents; then echo "$(gettext ' Found : ') $Project/$1.Contents"; |
|||
elif test -e $Project/$1.compile; then echo "$(gettext ' Found : ') $Project/$1.compile"; |
|||
elif test -e $Project/$1.compiled; then echo "$(gettext ' Found : ') $Project/$1.compiled"; |
|||
elif test -e $Project/$1.Sommaire; then echo "$(gettext ' Found : ') $Project/$1.Sommaire"; |
|||
elif test -e $Project/$1.Summary; then echo "$(gettext ' Found : ') $Project/$1.Summary"; |
|||
elif test -e $Project/$1.Sommaire_du_livre; then echo "$(gettext ' Found : ') $Project/$1.Sommaire_du_livre"; |
|||
else echo -e "$(gettext ' \033[31mContents file not found : ')$Project/$1.Contents\033[0m"; echo -e "\033[0m"; exit 2; |
|||
fi |
|||
echo "----------" |
|||
#P Print articles to be analyzed and if list-file exist |
|||
echo "$(gettext ' List of links to articles to be analyzed bye header.inc: ')" |
|||
echo "$(gettext ' Test if the file $Project/$1.list, exists: ')$Project/$1.list" |
|||
if test -e $Project/$1.list |
|||
then |
then |
||
echo "$(gettext ' Yes, the file exists. ')" |
echo "$(gettext ' Yes, the file exists. ')" |
||
else |
else |
||
echo -e "$(gettext ' \033[31mNo, ' |
echo -e "$(gettext ' \033[31mNo, '$Booksdir/$1/$1.list' is not yet created.\033[0m ')" |
||
fi |
fi |
||
#O Test if the .prj file exist and print the result |
|||
echo "----------" |
|||
echo -n "$(gettext ' Test if the file $Project/$1.prj, exists: ')"; echo "$Booksdir/$1/$1.prj" |
|||
if test -e "$Booksdir/$1/$1.prj" |
|||
#P Test if the .prj file exist and print the result |
|||
echo "$(gettext ' |
then echo "$(gettext ' Yes, the file exists. ')" |
||
else echo -e "$(gettext ' \033[31mNo, '$Booksdir/$1/$1.prj' is not yet created.\033[0m ')" |
|||
if test -e $Project/$1.prj; |
|||
then echo "$(gettext ' Yes, the file exists. ')"; |
|||
else echo -e "$(gettext ' \033[31mNo, ')"$Project/$1.prj"$(gettext ' is not yet created.\033[0m ')"; |
|||
fi |
fi |
||
#O If the first parameter is not empty, print the file list in the project diretory |
|||
echo "----------" |
|||
if test -n $1 |
|||
then echo; echo -e -n "$(gettext ' \033[33mContents in the project directory : ')"; echo -e "$Booksdir/$1 \033[0m" |
|||
#P If the first parameter is not empty, print the file list in the project diretory |
|||
ls -al $Booksdir/$1 |
|||
then echo "$(gettext ' Contents in the project directory: ')$Project"; |
|||
ls -al $Project |
|||
fi |
fi |
||
#O cat Book variables |
|||
echo "----------" |
|||
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 |
# End header.inc.sh |
||
</syntaxhighlight> |
</syntaxhighlight> |
Version du 19 mai 2021 à 18:29
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/\\\<\;/g;s/%3E/\>\;/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/test_header.inc.sh
- Exemple de fichier de commande d'un test dans le répertoire ~/Add_appendix/tests/header.inc/.
#!/bin/bash # File test_header.inc.sh in ~/Add_appendix/tests/header.inc/. #D Version=210401 #O nettoyer l'écran clear #O Initialisation de la variable Workdir Workdir=~/Add_appendix echo "Espace de travail = $Workdir" #O Vérifier que la syntaxe est respectée : echo "Syntax : header.inc [ <book-name> | ? ] [ -v ] [ -pb | -pc ]" echo "----" $Workdir/bin/header.inc echo "Test sans paramètre. Code de retour = $?" sleep 5 echo "----" $Workdir/bin/header.inc ? echo "Test avec le paramètre '?'. Code de retour = $?" sleep 5 echo "----" $Workdir/bin/header.inc LivreTestInexistant echo "Test avec paramètre avec paramètre 'LivreTestInexistant'. Code de retour = $?" sleep 5 echo "----" if [ -d "$Workdir/LivreTest" ] then $Workdir/bin/header.inc LivreTest echo "Test avec le paramètre 'LivreTest'. Code de retour = $?" else echo "Test avec le paramètre 'LivreTest' :" echo "Le répertoire de projet LivreTest n'est pas trouvé" echo "La commande n'a pas été exécutée." fi