Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/annex.lib
- Cette librairie est à mettre à jour dans les répertoires :
~/Annexer/lib/
et/ou
~/Add_appendix/lib/
et/ou
/usr/local/lib/
Tester le code source de la fonction findbook avec test_findbook.bash
Tester le code source de la fonction ecfpb avec ecfpb.sh (extract contents from printable book)
Tester le code source de la fonction ecfpc avec ecfpc.sh (extract contents from compiled book)
Tester le code source de la fonction cpcleaned2bin avec test_cpcleaned2bin
Tester le code source des fonctions de killalldoc avec test_killalldoc.bash
#!bin/bash
#H File : findbook.sh, source for test the findbook function to insert in
#H annex.lib file. Copy this content in file $Workdir/lib/src/findbook.sh
#H Last Update on fr:Wikibooks : 2021-04-26 by GC
#H Tested : by GC 2021-04-26
#H Updated : 2021-04-28 by user GC For layout
#H Revision: by JPL 2021-10-06 mise en commentaire de .gettext lestraductions ne sont pas encore prévues pour ce fichier.
#H
#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
VERSION=211019
#. gettext.sh
function findbook ()
{
if [ "$1" = "--v" ]; then echo "findbook version : $VERSION";return 0;fi
if [ -z $1 ]; then
echo " -- Suffix availables in function findbook() version $VERSION : "
echo " <book-name>/Contenus or Contenu or Contents, "
echo " <book-name>/Sommaire or Summary, "
echo " Compilations/<book-name> or Collections/<book-name>. "
fi
echo $1 | awk -F "/" '{for (i=1;i<=NF;i++) print $i}' > bookname.txt
cat bookname.txt | grep wikibooks > sitename.txt
read Site < sitename.txt
wc -l bookname.txt | cut -d" " -f1 > N.txt; read N < N.txt
let n=N
let local m=N-1
echo $1 | cut -d '/' -f5-$m > mwbookurl.txt
read "MWbookurl" < mwbookurl.txt
#let n-=1
echo $1 | cut -d '/' -f$n > lastfield.txt
read Lastfield < lastfield.txt
unset Suffix
if [ "$Lastfield" = "Contenus" ] || [ "$Lastfield" = "Contenu" ] || [ "$Lastfield" = "Contents" ] || [ "$Lastfield" = "Content" ]
then Suffix=contents
fi
if [ "$Lastfield" = "Sommaire" ] || [ "$Lastfield" = "Sommaire_du_livre" ] || [ "$Lastfield" = "Summary" ];
then Suffix=summary
else Bookname=$Lastfield
fi
if [ "$Suffix" = "contents" ] || [ "$Suffix" = "summary" ]
then
let local m=N-1
echo $1 | cut -d '/' -f1-$m > bookurl.txt
read Bookfullurl < bookurl.txt
fi
let n-=1; echo $1 | cut -d '/' -f$n > penultimatefield.txt
read Penultimatefield < penultimatefield.txt
if [ "$Penultimatefield" = "Compilations" ] \
|| [ "$Penultimatefield" = "Collections" ] \
|| [ "$Penultimatefield" = "Wikilivres:Compilations" ] \
|| [ "$Penultimatefield" = "Wikibooks:Collections" ]
then
Suffix=compiled
else Bookname=$Penultimatefield
fi
rm bookname.txt sitename.txt lastfield.txt penultimatefield.txt N.txt
}
#!/bin/bash
#H File : ecfpb.sh, source for test the function ecfpb to insert in
#H annex.lib file. Copy this content in file $Workdir/lib/src/ecfpb.sh
#H Last Update on fr:Wikibooks : 2021-04-28 by GC
#H Tested : by GC 2021-04-28
#H Updated : 2021-04-26 by user GC For layout
#H
#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
VERSION=210429
function ecfpb ()
{
source $HOME/Add_appendix/datas/installdir.var
if [ "$1" = "--v" ]; then echo "ecfpb version : $VERSION";return 0;fi
if [ "$2" = "--t" ]; then
source ~/Add_appendix/tests/1-annex.lib/11-findbook.sh/findbook.sh
echo "Finbook in tests version"
else source $Installdir/lib/annex.lib
fi
findbook $1
Projectdir=$Workdir/$Bookname
if [ -n $Site ] && [ "$Suffix" = "contents" ] || [ "$Suffix" = "Summary" ]
then
echo "url is a printable version."
#wget https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Sandbox/LivreTest/Contenu
wget -Nq $1
#cat Contenu | grep /wiki/Utilisateur:Goelette_Cardabela/Sandbox/LivreTest/ | grep -v -i Contenu > $Lastfield.txt
cat $Lastfield | grep /$MWbookurl/ | grep -v -i $Lastfield > beforelastfield.txt
cat beforelastfield.txt | awk -F "/" '{for (i=1;i<=NF;i++) print $i}' > fieldlist.txt
cat fieldlist.txt | sed -e "s/\"/\n/g" | sed -e "s/ /\n/g" > fieldlist2.txt
wc -l fieldlist.txt | cut -d" " -f1 > N.txt; read N < N.txt
let n=N; i=0 ; j=0; article=1; flag0=0; #flag1=1
#rm article.*.txt
while read line
do
let i+=1;
if [ "$line" = "wiki" ]; then echo -n "[[$MWbookurl/" > article.$article.txt; let flag0=1; fi
if [ $flag0 = "1" ] && [ "$line" = "$Bookname" ]; then let j=i+1; fi
if [ $flag0 = "1" ] && [ "$i" = "$j" ]; then echo "$line]]" >> article.$article.txt; let article+=1; let flag0=0; fi
done < fieldlist2.txt
fi
let i=1; #rm $Bookname.$Suffix
echo "[[$MWbookurl]]" > $Bookname.$Suffix
while (( i < 10 ))
do
#echo "article.$i.txt ="; cat article.$i.txt
if [ -r article.$i.txt ]; then cat article.$i.txt >> $Bookname.$Suffix; let i+=1 ; else break; fi
done
if test -n $Projectdir && ! test -d $Projectdir; then mkdir "$Projectdir"; fi
if test -d $Projectdir
then
echo "Project directory = $Projectdir"
if [ -r "$Projectdir/$Bookname.$Suffix" ]
then
echo
echo "Bookname.Suffix Contents :"; cat $Bookname.$Suffix; echo
#echo "Bookname.Suffix = $Bookname.$Suffix"
echo -n -e "$(gettext ' \033[31mUpdate Bookname.Suffix ? y/n :\033[0m ')"; read -s -n1 -p "inkey" Inkey; echo;
if [ "$Inkey" = "y" ]
then chmod 755 "$Projectdir/$Bookname.$Suffix"; cp "$Bookname.$Suffix" $Projectdir/.; chmod 555 "$Projectdir/$Bookname.$Suffix";
else echo "$(gettext ' file is not updated ! ... Go forward ... ')"
fi
else cp "$Bookname.$Suffix" $Projectdir/.
fi
fi
}
# End function ecfpb ()
#!/bin/bash
#H File : ecfpc.sh, source for test the function ecfpc to insert in
#H annex.lib file. Copy this content in file $Workdir/lib/src/ecfpc.sh
#H Last Update on fr:Wikibooks : 2021-04-28 by GC
#H Tested : by GC 2021-04-28
#H Updated : 2021-04-26 by user GC For layout
#H
#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
VERSION=210429
function ecfpc ()
{
source $HOME/Add_appendix/datas/installdir.var
if [ "$1" = "--v" ]; then echo "* ecfpc version : $VERSION";return 0;fi
if [ "$2" = "--t" ]; then
source ~/Add_appendix/tests/1-annex.lib/11-findbook.sh/findbook.sh
echo "* Finbook in tests version"
else source $Installdir/lib/annex.lib
fi
findbook $1
#if [ "$2" = "--t" ]; then
echo "* Site name :"$Site
echo "* Bookname : "$Bookname
echo "* Suffix : "$Suffix
echo "* Bookname.Suffix = "$Bookname.$Suffix
echo "*----"; echo
#fi
echo "* Bookname : "$Bookname
Projectdir=~/Add_appendix/$Bookname
echo "* Project directory = $Projectdir"
if test -d $Projectdir; then echo "* Project directory exist"; else mkdir $Projectdir; echo "* $Projectdir is created"; fi
if [ -n $Site ] && [ "$Suffix" = "compiled" ] || [ "$Suffix" = "Collection" ]
then
echo "* url is a compiled version (Collection)."
#wget https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel
#wget -Nq $1
rm lastfield.txt
cat $Bookname | grep /$Bookname/ > lastfield.txt
cat lastfield.txt | awk -F " " '{for (i=1;i<=NF;i++) print $i}' | grep "href=" > fieldlist.txt
cat fieldlist.txt | sed -e "s/href=\"\/wiki\//[[/g" | sed -e "s/\"/]]/g" > fieldlist2.txt
cat fieldlist2.txt | sed -f ~/Add_appendix/datas/conversions.dat > $Bookname.$Suffix
fi
if test -d $Projectdir
then
if [ -r "$Projectdir/$Bookname.$Suffix" ] && [ -s "$Bookname.$Suffix" ]
then
echo -n -e "$(gettext ' \033[31mUpdate $Bookname.$Suffix ? y/n :\033[0m ')"; read -s -n1 -p "inkey : " Inkey;echo " ";
if [ "$Inkey" = "y" ];
then chmod 755 "$Projectdir/$Bookname.$Suffix"; cp "$Bookname.$Suffix" $Projectdir/.; chmod 555 "$Projectdir/$Bookname.$Suffix";
else echo "*$(gettext ' file is not updated ! ... Continue ... ')"
fi
elif [ -s "$Bookname.$Suffix" ]; then cp $Bookname.$Suffix $Projectdir/.
fi
fi
}
#!/bin/bash
#H File cpcleaned2bin.sh cpcleand2bin in annex.lib
#H Bindir Resourcesdir Srcdir Verbose variables are defined in the calling program
VERSION=211020
function cpcleaned2bin ()
{
if [ "$1" = "--v" ]; then echo "cpcleaned2bin version : $VERSION";return 0;fi
mkdir -p ./tmp
if test -e $Srcdir/$1; then echo; else echo "$Srcdir/$1 not found by function cpcleaned2bin."; return -1;fi
awk '{
if ($1=="#D" || $1=="#M" || $1=="#O" || $1=="#P" || $1=="#T") {;} # do not replace with an empty line
else {print $0}
}' $Srcdir/$1 > ./tmp/$1.cleaned-1
cat ./tmp/$1.cleaned-1 | sed "s/eval_gettext /echo \$/g" | sed "s/; echo//g" > ./tmp/$1.cleaned-2
cat ./tmp/$1.cleaned-2 | sed "s/\"\$(gettext '/\$\"/g" | sed "s/' )//g" | sed "s/')//g" > ./tmp/$1.cleaned-3
echo $1 | sed "s/.sh//g" | sed "s/.bash//g" > ./tmp/first.txt
read First < ./tmp/first.txt
cat ./tmp/$1.cleaned-3 > $Bindir/$First
if echo $Bindir/$First | grep ".inc"; then chmod 644 $Bindir/$First; else chmod 755 $Bindir/$First; fi
if cat $Bindir/$First | grep -e '$\"'
then
xgettext -L shell -o $Resourcesdir/lang/po/$First.pot --from-code=UTF-8 $Bindir/$First
if test -z $Resourcesdir/lang/po/fr/$First.po
then
cp $Resourcesdir/lang/po/$First.pot $Resourcesdir/lang/po/fr/$First.po
else
msgmerge --update $Resourcesdir/lang/po/fr/$First.po $Resourcesdir/lang/po/$First.pot
fi
msgfmt $Resourcesdir/lang/po/fr/$First.po -o $Resourcesdir/lang/po/fr/$First.mo
echo -e "\033[1;33m### Only if you are edit and update $First.po with Poedit: ###\033[0m"
echo "copy $Resourcesdir/lang/po/fr/$First.mo to /usr/share/locale/fr/LC_MESSAGES/$First.mo"
if test -z $Resourcesdir/lang/po/es/$First.po
then
cp $Resourcesdir/lang/po/$First.pot $Resourcesdir/lang/po/es/$First.po
else
msgmerge --update $Resourcesdir/lang/po/es/$First.po $Resourcesdir/lang/po/$First.pot
fi
msgfmt $Resourcesdir/lang/po/es/$First.po -o $Resourcesdir/lang/po/es/$First.mo
echo -e "\033[1;33m### Only if you are edit and update $First.po with Poedit: ###\033[0m"
echo "copy $Resourcesdir/lang/po/es/$First.mo to /usr/share/locale/es/LC_MESSAGES/$First.mo"
fi
rm -r ./tmp
if [ "$Verbose" = "true" ];then echo "$Bindir/$First is updated:"; ls -l $Bindir/$First; fi
}
#!/bin/bash
#H File killalldoc.sh
VERSION=211019
if [ "$1" = "--v" ];then echo "killalldoc.sh version: $VERSION"; exit 0;fi
function killOPT ()
{
if test -z $1; then return -1; fi
awk '{
if ($1=="#O" || $1=="#P" || $1=="#T") {print " "} # replace with blank line
else {print $0}
}' $1
}
function killDMOPT ()
{
if test -z $1; then return -1; fi
awk '{
if ($1=="#D" || $1=="#M" || $1=="#O" || $1=="#P" || $1=="#T") {print " "} # replace with blank line
else {print $0}
}' $1
}
function killALLDOC ()
{
if test -z $1; then return -1; fi
awk '{
if ($1=="#D" || $1=="#M" || $1=="#O" || $1=="#P" || $1=="#T") {;} # do not replace with an empty line
else {print $0}
}' $1
}