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

Contenu supprimé Contenu ajouté
Création
 
→‎pre-annex.sh : Mise àjur
Ligne 19 :
#F Il est également proposé d'afficher le livre local dans le navigateur
</pre>
; Program pre-annex code
<syntaxhighlight lang="Bash">
#!/bin/bash
Ligne 49 :
 
 
VERSION=210512210516
 
#O If first parameter is "--v", print pre-annex version
Ligne 56 :
if test -z $1
then
echo "Syntax : pre-annex [ --v | Full-url-of-book |] --v |[ --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
Ligne 68 :
rm pwd.txt
source $Workdir/datas/installdir.var
if [ "$1" = "--t" ] || [ "$2" = "--t" ] ; then echo; echo "Global install variables :"; cat $Workdir/datas/installdir.var; fi
#T Test break exit 0
#O Find function findbook
Libdir=$Workdir/lib
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
Ligne 79 ⟶ 80 :
then
echo
echo -n "Global--t variables: after"; findbook execution : " --v
echo "Site--t name: Global variables after findbook execution : "$Site
echo "Bookname--t : Site name :"$Bookname Site
echo "Suffix--t : Bookname : "$SuffixBookname
echo "Bookname.--t : Suffix =: "$Bookname.$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
Ligne 95 ⟶ 111 :
#O Create the project directory
Projectdir=$Workdir/$Bookname
if ! test -d "$Projectdir"; then mkdir $Projectdir; fi
#O Create the file bookname.suffix
echoif ";test $Bookname" >-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 ), \
Ligne 105 ⟶ 144 :
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
Book=https://$Site/wiki/$Bookname
elif test -n "$Compilfullurl"; then echo "Dowload $Compilfullurl"; wget -r -linf -k -p -E "$Compilfullurl" -o $Workdir/temp/wget-log-télécharger.txt
#T echo $Book
else echo " book full url not found to download"
#T exit 0
fi
wget -r -linf -k -p -E $Book -o $Workdir/temp/wget-log-télécharger.txtl
 
#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 : CompleteSee and possibly complete the result$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 ? y/n\033[0m"
read -s -n1 -p "inkey y/n" Inkey; echo; "$Inkey"
if [ "$Inkey" = "'y"' ]
then
gedit $Workdir/$Bookname/$Bookname.$Suffix&
xdg-open $1
fi
Ligne 125 ⟶ 164 :
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
Localbook=$Projectdir/$Site/wiki/$Bookname.html
echo -n "$Projectdir/" > localbook.txt
if test -e $Localbook;
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 "do\033[47m\033[1;30m Do you want to see the local html book ? y/n\033[0m"
read -s -n1 -p "inkey y/n :" Inkey; echo "$Inkey"; echo
if [ "$Inkey" = "'y"' ]; then xdg-open file://$LocalbookHtmlbook ; fi
else echo "$LocalbookHtmlbook not found"
fi
</syntaxhighlight>
 
== test_pre-annex.bash ==
Install this code in ~/Add_appendix/tests/prannex.sh to test preannex.sh
<syntaxhighlight lang = "Bash">
#!/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=210513
 
#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
</syntaxhighlight>
 
== sitelist.sh ==
Install this code in /Add_appendix/tests, to product sitelist.txt
<syntaxhighlight lang = "Bash">
#!/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"
</syntaxhighlight>
 
== sitelist.txt ==
; sitelist.txt to test program annex sub-programs
<pre>
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
</pre>
 
 
 
{{AutoCat}}