« Auto-éditer un wikilivre/addappendix/reconstruction et tests du script addappendix » : différence entre les versions
Contenu supprimé Contenu ajouté
→script tests_addappendix.bash : WL:RD : ! mise en page |
WL:RD : ! mise en page |
||
Ligne 1 : | Ligne 1 : | ||
{{en cours}} |
{{en cours}} |
||
* '''Cette page concerne le logiciel addappendix mis en paquet''' |
* '''Cette page concerne le logiciel addappendix mis en paquet''' |
||
== preinstall-usr-local.bash == |
|||
<syntaxhighlight> |
|||
#!/bin/bash |
|||
#H Header doc |
|||
#H ------------------------------- |
|||
#H File : tests/preinstall-usr-local.bash |
|||
#H Syntax : ./preinstall-usr-local.bash./ [ ? | -v ] |
|||
#H Created : 220118 by <wikibooks user> |
|||
#H Updated : 220118 by ... for |
|||
#O Organizational chart |
|||
#O ------------------------------- |
|||
#P Programmers notes |
|||
#P ------------------------------- |
|||
VERSION=220118 |
|||
#O Script begin here |
|||
sudo install -d /usr/local/datas |
|||
sudo cp /home/cardabela/addappendix-211219/datas/*.dat /usr/local/datas/. |
|||
ls /usr/local/datas |
|||
#O Script end |
|||
</syntaxhighlight> |
|||
== script addapendix.sh == |
== script addapendix.sh == |
||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
Version du 26 janvier 2022 à 12:55
- Cette page concerne le logiciel addappendix mis en paquet
preinstall-usr-local.bash
#!/bin/bash
#H Header doc
#H -------------------------------
#H File : tests/preinstall-usr-local.bash
#H Syntax : ./preinstall-usr-local.bash./ [ ? | -v ]
#H Created : 220118 by <wikibooks user>
#H Updated : 220118 by ... for
#O Organizational chart
#O -------------------------------
#P Programmers notes
#P -------------------------------
VERSION=220118
#O Script begin here
sudo install -d /usr/local/datas
sudo cp /home/cardabela/addappendix-211219/datas/*.dat /usr/local/datas/.
ls /usr/local/datas
#O Script end
script addapendix.sh
#!/bin/bash
#H Header doc
#H -------------------------------
#H File : tests/addappendix/addapendix.sh
#H Syntax : addapendix [ ? | --v ]
#H Created : 220113 by GC
#H Updated : 220113 by ... for
#O Organizational chart
#O -------------------------------
#P Programmers notes
#P -------------------------------
VERSION=220126
TEXTDOMAIN=addappendix
TEXTDOMAINDIR="/usr/share/locale"
export TEXTDOMAINDIR
#P . gettext for translation
. gettext.sh
#O Script begin here
#O If parameters is empty
if test -z $1
#O Then print the short syntax ant exit -1
then
echo -n -e "\033[31m"
echo -n $"No parameter. addappendix [ <full url of book> | ? | --v ]"
echo -e "\033[0m"
exit -1
fi
#O If firt parameter is '?'
if [ "$1" = "?" ]
#O Then print syntax whih examples and exit 0
then
echo -n -e "\033[32m"
echo $"Syntax: addappendix [ <full url of book> | --v ]"
echo $" Example 1 : addappendix https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix"
echo $" Example 2 : addappendix https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel"
echo -e "\033[0m"
exit 0
fi
#O IF first parameter is "--v"
if [ "$1" = "--v" ]
#O Then print addapendix version
then
echo -n -e "\033[32m"
echo -n $"addapendix version : $VERSION"
echo -e "\033[0m"
exit 0
fi
#O *** First parameter analysis ***
#T echo "$1"
#O Test if the first parameter points to wikibooks.org/wiki
if echo $1 | grep wikibooks.org/wiki
then
echo -n -e "\033[32m"
echo -n $" is a wiki-book"
echo -e "\033[0m"
else
echo -n -e "\033[31m"
echo -n $"$1 is not a wiki-book on wikibooks.org"
echo -e "\033[0m"
exit -1
fi
#O Check if $1 file exist
if wget --spider $1 2>/dev/null; then
echo -n -e "\033[32m"
echo -n $"File $1 is found"
echo -e "\033[0m"
else
echo -n -e "\033[31m"
echo -n $"File $1 is not found"
echo -e "\033[0m"
exit -1
fi
#O Find the bookname
echo $1 | awk -F"/" ' { print $NF }' > bookname.txt
read Bookname<bookname.txt
echo; echo -n -e "\033[1;32m"
echo -n $"Book name : $Bookname"
echo -e "\033[0m"
echo $1 | awk -F"/" ' { print $3 }' > site.txt
read Site<site.txt
echo; echo -n -e "\033[1;32m"
echo -n $"Site name : $Site"
echo -e "\033[0m"
echo $1 | awk -F"/" ' { print $5 }' > compilations.txt
read Compilations<compilations.txt
echo -n -e "\033[1;32m"
echo -n $"Compilations name: $Compilations"
echo -e "\033[0m"
if [ "$Compilations" = "Wikilivres:Compilations" ]; then Suffix=compiled; fi
if [ "$Compilations" = "Wikibooks:Collections" ]; then Suffix=compiled; fi
if test -z $Suffix; then Suffix=compiled; fi
echo -n -e "\033[1;32m"
echo "Suffix = $Suffix"
echo -e "\033[0m"
#O Create Bookname directory
install -d ~/Add_appendix/books/$Bookname
Projectdir=~/Add_appendix/books/$Bookname
#O Create temp directory in Wordir
Workdir=~/Add_appendix
mkdir -p $Workdir/temp
##O Create the file bookname.suffix
#T ***********************
#O Create $Projectdir/resources/TMP to download
mkdir -p $Projectdir/resources/TMP
#O Download $1
cd $Projectdir/resources/TMP
rm -Rf $Projectdir/resources/TMP/* 2> /dev/null
wget -N $1 -o $Workdir/temp/wget-log-télécharger.txt
ls -1 > ../filename.txt
read Filename<../filename.txt
if [ "$Filename" = "filename.txt" ]; then echo $"line 113: \$Filename = filename.txt error, exit -1"; exit -1; fi
rm ../filename.txt
#O go up in the directory resources and rename 'TMP' '$Filename'
cd ..
if test -e $Filename; then rm -R $Filename; fi
if test -d $Filename 2>/dev/null
then rm -R $Filename 2>/dev/null
fi
mv TMP $Filename
cd $Filename
#T ls -al
cat $Filename|grep "<li><a href=">extract-li
cat extract-li | sed "s/title=\"/\n[[/g" | grep -v "<li><a href=" |sed "s/\">/]]\n/g"|grep -v "</a>\|Cat\|<div" >extract-li1
cat $Filename|grep "<dd><a href=">extract-dd
cat extract-dd | sed "s/title=\"/\n[[/g" | grep -v "<dd><a href=" |sed "s/\">/]]\n/g"|grep -v "</a>" >extract-dd1
cat extract-dd1 > $Bookname.$Suffix
cat extract-li1 >> $Bookname.$Suffix
#T echo "$Bookname.$Suffix = "
cp $Bookname.$Suffix $Projectdir/$Bookname.$Suffix
#T ***********************
if test -e $Projectdir/$Bookname.$Suffix
then
echo -n -e "\033[1;32m"
echo -n "$Bookname.$Suffix : "
echo -e "\033[0m"
cat $Projectdir/$Bookname.$Suffix
fi
#O Download the book in html form
#O Télécharger le site récursivement avec une profondeur infinie ( -linf ), \
#O convertit les liens pour une consultation en local ( -k ), \
#O rapatrie tous les fichiers nécessaires à l'affichage convenable d'une page HTML ( -p ) \
#O et renomme toutes les pages HTML avec l'extension .html ( -E )
echo; echo "Dowload $1"
wget -r -linf -k -p -E "$1" -o $Workdir/temp/wget-log-télécharger.txt
# Create lists
if test -e /usr/local/datas/content_cleaner.dat; then Datasdir=/usr/local/datas
else
echo -n -e "\033[12;31m"
echo -n $"content_cleaner.dat not found in /usr/local/datas"
echo -e "\33[0m"
exit -1
fi
if test -e "$Projectdir/$Bookname.compiled"
then
{
echo "$(gettext ' Found Compiled page : ')$Projectdir/$Bookname.compiled"; echo
echo " Create $Projectdir/$Bookname.list with :"; echo " $Projectdir/$Bookname.compiled"; echo
cat "$Projectdir/$Bookname.compiled" | sed -f $Datasdir/content_cleaner.dat > $Projectdir/$Bookname.compiled.cleaned
cat "$Projectdir/$Bookname.compiled.cleaned" | grep -v '=' | sed "s/\[\[/https:\/\/$Site\/wiki\//g" | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' | cut -d '|' -f1 > $Projectdir/$Bookname.list
cat "$Projectdir/$Bookname.compiled.cleaned" | grep -v '=' | sed "s/\[\[//g" | sed "s/\]\]//g" | cut -d '|' -f1 > $Projectdir/$Bookname.prj
}
fi
#T Print $Projectdir/$Bookname.prj
cat $Projectdir/$Bookname.prj
#O Download the complete book structure in project directory
cd $Projectdir
echo $"download all sub-directories of the book '$Bookname'"
wget -r -linf -k -p -E -i $Bookname.list -o $Workdir/temp/wget-log-download.txt
echo "----------"
#T Testspoint exit 0
#O Move the html pages into working sub-directories to document the pages and sub pages
#O create a local list to the downloaded directories $ Projectdir/$1.locale.list
echo "create the complete concatenated hierarchy of the directories of the book '$Bookname'"
cat $Projectdir/$Bookname.list | sed "s/https:\/\///g" | sed "s/\ /\\\ /g" | tr '\n' ',' > $Projectdir/$Bookname.locale.list
echo " Concatenated local list $Projectdir/$Bookname.locale.list :"
echo ""
cat $Projectdir/$Bookname.locale.list
echo "----------"
#O Copy the html files to respective directories
#O Create a file with the pagename $Projectdir/$Bookname.mainPage
echo "créer la page du lien local vers la page principale, 'le livre'."
echo "create the page from the local link to the main page, 'the book'"
cat $Projectdir/$Bookname.locale.list | sed "s/ /\\ /g" | cut -d ',' -f1 > $Projectdir/$Bookname.mainPage
echo "----------"
#O Initialize the variable $mainPage
read mainPage < $Projectdir/$Bookname.mainPage
echo "variable mainPage = $mainPage"
#T cat $Projet/$1.mainPage | awk -F"/" '{print NF}' > nbchamps
#T read NbChamps < nbchamps
#T echo "Variable NbChamps = $NbChamps"
echo "----------"
#O Create a file of the working directories to be created.
ls "$mainPage" | sed "s/.html//g" > $Projectdir/$Bookname.dirs
echo "sub-working-diectories : "
cat $Projectdir/$Bookname.dirs
echo "----------"
#O Copy the html pages and subpages in the respective directories
while read line
do
echo "$line".html | sed "s/https:\/\///g" | tr '\n' ' ' > source
read Source < source
echo "Source = $Source"
echo "$line" | awk -F"/" '{ print $NF }'| tr '\n' '/' > destination
read dir < destination
mkdir $dir
echo "$line".html | awk -F"/" '{ print $NF }' >> destination
read Destination < destination
echo "Destination = $Destination"
echo "To copy : 'cp -f ./$Source $Destination'"
cp -f "./$Source" "$Destination"
done < $Projectdir/$Bookname.list
rm source ; rm destination
#O Create variable PageSclt
PageSclt=$Projectdir/$Bookname.sclt
#O File creation '$Bookname.sclt' and print the contents.
echo "----------"
echo "$(gettext '= Appendix = ')" > $PageSclt
echo >> $PageSclt
#O Add <references />
echo "$(gettext '== References == ')" >> $PageSclt
echo "$(gettext '<references /> ')" >> $PageSclt
echo >> $PageSclt
echo "<div style='page-break-before:always'></div>" >> $PageSclt
#O Add the link to printable book and to articles.
echo "$(gettext '== Contents == ')" >> $PageSclt
echo "<div style="font-zize:85%">" >> $PageSclt
cat $Projectdir/$Bookname.list | tr ' ' '_' | tr '\n' '%' | sed "s/%/\n\n/g" >> $PageSclt
echo "</div>" >> $PageSclt
#0 Add the link to the source of this edition.
echo "$(gettext '=== Source for this edition === ')" >> $PageSclt
echo "<div style="font-zize:85%";>" >> $PageSclt
echo -n "https://" >> $PageSclt
cat $Projectdir/$Bookname.mainPage | sed "s/\\\ /_/g" >> $PageSclt
#P other version : cat $Projectdir/Bookname".list" | tr ' ' '_' | tr '\n' '%' | sed "s/%/%\n/g" | grep $1% | tr -d % >> $PageSclt
echo "</div>" >> $PageSclt
echo " " >> $PageSclt
echo "<div style='page-break-before:always'></div>" >> $PageSclt
#O Create section 'Article', 'Source', 'License', 'Contributors(?)'
echo "$(gettext '== Articles Sources, and contributors == ')" >> $PageSclt
#O add the text : style PediaPress or personalized.
#O The ''sources'' listed for each article provide more detailled licencing
#O information including the copyright status, the copyleft owner and the license conditions.
echo -n "<span style="font-zize:85%";>" >> $PageSclt
echo "$(gettext 'The ''sources'' listed for each article provide more detailled licencing information including the copyright status, the copyleft owner and the license conditions..</span> ')" >> $PageSclt
#O or, validate one or the other of these texts :
# echo $"The texts are available with their respective licenses, however other terms may apply.<br />See the terms of use for more details : <br />https://wikimediafoundation.org/wiki/Conditions_d'utilisation.</span>" >> $PageSclt
echo " " >> $PageSclt
echo "<div style="font-zize:72%";>" >> $PageSclt
echo "----------"
#O Create or recreate the list-file $Projectdir/$1.pj
cat $Projectdir/$Bookname.list | awk -F"/" '{ print $NF }' > $Projectdir/$Bookname.pj
Pjlist=$Projectdir/$Bookname.pj
echo "Pjlist : "$PjList
#O While exist line in file $PjList ,
while read line
do
#O Print the line read,
echo
echo "$(gettext ' line read = ')"$line
echo
#O Extract and copy all strings from the html file
#O $line.html in the file $line.str and add to screen
#T pwd
mkd -pws '**' "$line/$line.html" $Projectdir/$line/$line.tmp | tr ',' '\n' > $Projectdir/$line/$line.str
#T break
#O Create the documentation file of pages :
echo "*** References : articles, src, lic, contrib. "
#O Print article,
if [ $line != $Bookname ]
then
echo "'''$line'''" >> $PageSclt
fi
echo "'''"$line"'''" > $Projectdir/$line/$line.article
cat $Projectdir/$line/$line.article
#O Print source,
echo -n "$(gettext ', ''source :'' ')https://"$Site"/w/index.php?oldid=" > $Projectdir/$line/$line.RevisionId
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e wgRevisionId | tr -d ':' | sed "s/\"/%/g" | cut -d'%' -f3 >> $Projectdir/$line/$line.RevisionId
if [ "$line" != "$Bookname" ]
then
cat $Projectdir/$line/$line.RevisionId >> $PageSclt
fi
cat $Projectdir/$line/$line.RevisionId
#P license du bas de page :
#P <li id="footer-info-copyright">Les textes sont disponibles sous <a href="https://creativecommons.org/licenses/by-sa/3.0/">license Creative Commons attribution partage à l’identique</a> ; d’autres termes peuvent s’appliquer.<br/>
#P Voyez les <a href="https://wikimediafoundation.org/wiki/Conditions_d'utilisation">termes d’utilisation</a> pour plus de détails.<br/></li>
#P
#P Print license :
#P <link rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/"/>
#T echo ", ''Copyright :''" >> ArticleUn.tmp
#T cat ArticleUn.str | grep -n -m 1 -i -e license | sed "s/\"\//%\//g" | cut -d'%' -f2 |sed "s/\/\//https:\/\//g" >> ArticleUn.tmp
#O Print license :
echo -n "$(gettext ', ''license :'' ')" > $Projectdir/$line/$line.license
#T cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e license | sed "s/\"\//%\//g" | cut -d'%' -f4 >> $Projectdir/$line/$line.license
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e license | sed "s/\"\//%\//g" | tr '"' '%' | cut -d'%' -f4 >> $Projectdir/$line/$line.license
#T cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e license | sed "s/\"\//%\//g" | cut -d'%' -f2 | sed "s/\/\//https:\/\//g" >> $Projectdir/$line/$line.license
if [ $line != $Bookname ]
then
cat $Projectdir/$line/$line.license >> $PageSclt
fi
cat $Projectdir/$line/$line.license
#
#P spécial pour bas de page fr ##
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e footer-info-copyright | sed "s/\"\//%\//g" | tr '"' '%' | cut -d'%' -f4 > $Projectdir/$line/$line.license
#O Author(s).
echo -n "$(gettext ', ''author(s) : '' ')" > $Projectdir/$line/$line.author
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e wgRelevantUserName | sed "s/\"/%/g" | cut -d'%' -f4 > tmp
if test -s tmp
then cat tmp >> $Projectdir/$line/$line.author; rm tmp
else
echo "Author(s) not found ! " >> $Projectdir/$line/$line.author
if wget --spider https://xtools.wmflabs.org/articleinfo/en.wikibooks.org/$line 2>/dev/null
then
echo "$(gettext '. -see :') https://xtools.wmflabs.org/articleinfo/$Sitename/$line" >> $Projectdir/$line/$line.author
elif wget --spider https://xtools.wmflabs.org/articleinfo/$Sitename/$Bookname/$line 2>/dev/null
then
echo "$(gettext '. -see :') https://xtools.wmflabs.org/articleinfo/$Sitename/$Bookname/$line" >> $Projectdir/$line/$line.author
else
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e wgRelevantPageName | sed "s/\"/%/g" | cut -d'%' -f4 > tmp
if test -s tmp
then
#T echo "&action=history" >> tmp
echo -n "$(gettext '. -see ''contributors'' in book, history page of ')" >> $Projectdir/$line/$line.author
cat tmp >> $Projectdir/$line/$line.author; rm tmp
fi
fi
fi
#https://xtools.wmflabs.org/articleinfo/en.wikibooks.org/Guide_to_Unix/Introduction
if [ $line != $Bookname ]
then
cat $Projectdir/$line/$line.author >> $PageSclt
cat $Projectdir/$line/$line.author
fi
echo >> $PageSclt
#O end of while.
done < $Pjlist
exit 0
#O Script end
script tests_addappendix.bash
#!/bin/bash
#!/bin/bash
#H Header doc
#H -------------------------------
#H File : tests/addappendix/tests_addapendix.bash
#H Syntax : ./tests_addapendix.bash
#H Created : 220113 by GC
#H Updated : 220113 by ... for
#O Organizational chart
#O -------------------------------
#P Programmers notes
#P -------------------------------
VERSION=220119
#P Before execute this tests, execute tests/preinstall-usr-local.bash to install datas directory in /usr/local
echo -e "\033[1;033mtest addappendix.sh with first param empty\033[0m"
./addappendix.sh
sleep 3
echo "----"
echo -e "\033[1;033mtest addappendix.sh with first param = '?'\033[0m"
./addappendix.sh ?
sleep 3
echo "----"
echo -e "\033[1;033mtest addappendix.sh with first param = '--v'\033[0m"
./addappendix.sh --v
sleep 3
echo "----"
echo -e "\033[1;033mtest addappendix.sh with param = https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel\033[0m"
./addappendix.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
Résultat des tests
- Au Terminal
cardabela@jpl-W230SS:~/addappendix-211219/tests/addapendix$ ./tests_addapendix.bash test addappendix.sh with first param empty No parameter. addappendix [ <full url of book> | ? | -v ] ---- test addappendix.sh with first param = '?' Syntax: addappendix [ <full url of book> | -v ] Example 1 : addappendix https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix Example 2 : addappendix https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel ---- test addappendix.sh with first param = '-v' addapendix version : 220117 ---- test addappendix.sh with param = https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel is a wiki-books File https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel is found Book name : Faire_sa_fleur_de_sel Compilations name: Wikilivres:Compilations Suffix = compiled Faire_sa_fleur_de_sel.compiled : [[Faire fleurir le sel/Couverture]] [[Faire fleurir le sel/Introduction]] [[Faire fleurir le sel/Préparation]] [[Faire fleurir le sel/Filtrer et aseptiser]] [[Faire fleurir le sel/Récolter]] Dowload https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
- List of files created
cardabela@jpl-W230SS:~$ find Add_appendix/ Add_appendix/ Add_appendix/temp Add_appendix/temp/wget-log-télécharger.txt Add_appendix/books Add_appendix/books/Faire_sa_fleur_de_sel Add_appendix/books/Faire_sa_fleur_de_sel/Faire_sa_fleur_de_sel.compiled Add_appendix/books/Faire_sa_fleur_de_sel/resources Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/fr.wikibooks.org Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/fr.wikibooks.org/robots.txt Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/fr.wikibooks.org/wiki Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/fr.wikibooks.org/wiki/Wikilivres:Compilations Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel.html Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/Faire_sa_fleur_de_sel Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/extract-dd1 Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/Faire_sa_fleur_de_sel.compiled Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/extract-li1 Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/extract-dd Add_appendix/books/Faire_sa_fleur_de_sel/resources/Faire_sa_fleur_de_sel/extract-li