Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/annex.sh
Apparence
français: Avant d'utiliser cette commande en mode exécutable,
- la structure des répertoires du programme doit être correctement installée ou mise à jour avec la commande: ~/Tmp/users_install_annex.sh,
- les livres doivent avoir été initialisés avec la commande: bin/pre-annex du répertoire de travail de l'application Annexer ou Add_appendix.
anglais: To use this annex command,
- you must have initialized the program directories with: ~/Tmp/users_install_annex.sh or reset with sbin/users_install_annex.sh,
- the books must have been initialized with the command: bin/pre-annex from the working directory of the Add_appendix application
Annex.sh
[modifier | modifier le wikicode]#!/bin/bash
#H ****
#H Header documentation of annex.sh
#H --------------------------------
#H File : annex and-or annex.sh
#H Version : 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 ****
#P Programmers documentation of file annex.sh
#P ------------------------------------------
#P header.inc is included in each module for its individual test and
#P permanently in this command file 'annex'.
#P
#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 onl
#P
#T ****
#T Tests documentation of annex.sh
#T -------------------------------
#T export PATH=$PATH:~/Add_appendix/bin
#T env | grep Add_appendix
#T
#D ****
#D Documentation for file annex
#D ----------------------------
#D addappendix with pre-annex are the main programs to create directories
#D needed to run the annex script.
#D annex is the main program to find the books contents of wikibooks and
#D of Commons to create appendix of book
#D ****
#P . gettext for translation
. gettext.sh
VERSION=211004
if [ "$1" = "--v" ]; then echo "Annex version $VERSION"; exit 0; echo; fi
TEXTDOMAIN=annex
TEXTDOMAINDIR="/usr/share/locale"
#P If first param is empty print the syntax and exit
if [ -z $1 ]
then
echo "$(gettext ' No Parameter ')"
echo "$(gettext ' Syntax : 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 $Workdir/vars/installdir.var ];
then
source $Workdir/vars/installdir.var
echo "$Workdir/vars/installdir.var is found in annex command"; echo
Bindir=$Installdir/bin
Testsdir=$Workdir/tests
else
echo -n "current directory in $0 "
pwd
echo "$Workdir/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 echo " Project directory = $Projectdirdir"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 $Projectdir
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 $Projectdir
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 $1
else
$Bindir/add_sclic $1 > $Workdir/temp/Report-silent-mode/add_sclic-cmd.txt
fi
cat $Projectdir/$1.sclic > $Projectdir/$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 $Workdir/temp/Report-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/add_sclipco $1; else $Bindir/add_sclipco $1 > $Workdir/temp/Report-silent-mode/add_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 $Workdir/temp/Report-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/add_sclipwb $1; else $Bindir/add_sclipwb $1 > $Workdir/temp/Report-silent-mode/add_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 $Workdir/temp/Report-silent-mode/scliwb-cmd.txt ')"
exit 1
fi
#P Flush article, source license ant text to project.appendix
cd $Projectdir
cat $1.sclt > $1.appendix
#P sclip.inc
if [ $Personalwb = "true" ]
then cat $Projectdir/$1.sclipwb >> $Projectdir/$1.appendix; echo "$(gettext ' $1.sclipwb is added to $1.appendix ')";
elif [ $Personalco = "true" ]
then cat $Projectdir/$1.sclipco >> $Projectdir/$1.appendix; echo "$(gettext ' $1.sclipco is added to $1.appendix ')";
else
cat $Projectdir/$1.sclic >> $Projectdir/$1.appendix; echo "$(gettext ' $1.sclic is added to $1.appendix ')";
fi
echo "$(gettext '== License == ')" >> $Projectdir/$1.appendix
cat $Projectdir/$1/$1.license >> $Projectdir/$1.appendix
echo "" >> $Projectdir/$1.appendix
#P echo "{{Nouvelle page imprimée}}" >> $Projectdir/$1.appendix
#P echo "$(gettext '{{Page-break/end}} ')"" on en:wikibooks >> $Projectdir/$1.appendix
echo "<br style=\"page-break-after: always\">" >> $Projectdir/$1.appendix
echo ""
echo ""
echo ""
echo -n "$(gettext ' Copy the contents of the file ')"$Projectdir/$1.appendix
echo "$(gettext ' to the Appendix page of the book ')"$1.
exit 0
#P ****
#T ****
# End annex command
Global test
[modifier | modifier le wikicode]#! /bin/bash
#P file : tests_annex.sh
#P Syntax ./tests_annex.sh
clear
VERSION=210822
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; ./annex.sh LivreTest -v -pc; ./annex.sh LivreTest -v -pb
elif [ "$Inkey" = "2" ]; then ./annex.sh Hélices_de_navires_à_déplacement; ./annex.sh Hélices_de_navires_à_déplacement -v -pc; ./annex.sh Hélices_de_navires_à_déplacement -v -pb
elif [ "$Inkey" = "3" ]; then ./annex.sh TestBook; ./annex.sh TestBook -v -pc; ./annex.sh TestBook-v -pb
elif [ "$Inkey" = "4" ]; then ./annex.sh Mkd_\(Extracteur_de_documents\); ./annex.sh Mkd_\(Extracteur_de_documents\) -v -pc; ./annex.sh Mkd_\(Extracteur_de_documents\) -v -pb
elif [ "$Inkey" = "5" ]; then ./annex.sh Faire_fleurir_le_sel; ./annex.sh Faire_fleurir_le_sel -v -pc; ./annex.sh Faire_fleurir_le_sel -v -pb
elif [ "$Inkey" = "6" ]; then ./annex.sh Faire_sa_fleur_de_sel; ./annex.sh Faire_sa_fleur_de_sel -v -pc; ./annex.sh Faire_sa_fleur_de_sel -v -pb
elif [ "$Inkey" = "7" ]; then ./annex.sh Guide_to_Unix; ./annex.sh Guide_to_Unix -v -pc; ./annex.sh Guide_to_Unix -v -pb
elif [ "$Inkey" = "8" ]; then ./annex.sh Tests_de_la_capacité_des_batteries_d%27accumulateurs; ./annex.sh Tests_de_la_capacité_des_batteries_d%27accumulateurs -v -pc; ./annex.sh Tests_de_la_capacité_des_batteries_d%27accumulateurs -v -pb
elif [ "$Inkey" = "9" ]; then ./annex.sh LivreTest; ./annex.sh LivreTest -v -pc; ./annex.sh LivreTest -v -pb
else echo "$inkey local url of site not found"; exit 0
fi
done
#O End tests_annex.bash