Aller au contenu

Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/list.sh

Un livre de Wikilivres.
Remarquelink={{{link}}}

Les messages en anglais sont introduits pour l'internalisation avec gettext.
les commentaires #P pour les programmeurs sont en anglais, les autres commentaires ont été réduits au minimum.

#! /bin/bash
#H File list.sh
#H Syntax in console : "./bin/list.sh <bookname>"
#H Example : "./liste.sh LivreTest" à la console.
#H Creation date : 2020-03-26
#H Modified : 2020-04-26 by GC
#H Modified : 2020-05-30 by GC for automatic installation
#H Modified : 2020-06-30 by GC to include Summary pages at the list files
#H Modified : 2021-03-17 by GC for internationalization
#H modified : 2021-03-21 by GC for for layout
#H modified : 2021-05-21 by GC Reconstructed version
#H modified by Clara 23/05/2021 résolution provisoire du problème de la 
#H   variable $Projectdir pour les livres avec des Sommaires
#H
#D list.sh documentation
#D Creates the list of files included in the pages
#D header.inc is included and there is no need to recreate the environment
#D   variables
#D Suffix available for bookname.suffix : compiled, summary, contents
#D
VERSION=210523
#O . gettext.sh for translation
   . gettext.sh
#O Include the file header.inc
    if test -e ~/Add_appendix/bin/header.inc; then source ~/Add_appendix/bin/header.inc
    else echo "$Bindir/header.inc not found. Execute sbin/cp-src2bin.sh"; exit -1
    fi
#w Initialize the project list in project directory 
#w  If the book is included at the root of wikibooks
#w   echo "https://$Site/wiki/$1" > $Project/$1.list
#w  Else take the url into account
#O Code extraction as appropriate case  
#O   Case compiled pages for PediaPress. Lines syntax :[[Book article]]
    SitePrefix=https:\/\/$Site\/wiki\/
    if test -e "$Projectdir/$1.compiled"
    then 
      {
        echo "$(gettext ' Found Compiled page : ')$Project/$1.compiled"; echo
        echo " create $Projectdir/$1.list with :"; echo "    $Projectdir/$1.compiled"; echo
        cat "$Projectdir/$1.compiled" | sed -f ~/Add_appendix/datas/content_cleaner.dat > $Projectdir/$1.compiled.cleaned
        cat "$Projectdir/$1.compiled.cleaned" | grep -v '=' | sed "s/\[\[/https:\/\/$Site\/wiki\//g" | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' | cut -d '|' -f1 > $Projectdir/$1.list
        cat "$Projectdir/$1.compiled.cleaned" | grep -v '=' | sed "s/\[\[//g" | sed "s/\]\]//g" | cut -d '|' -f1 > $Projectdir/$1.prj
      }
#O   Case contents suffix  
    elif test -e "$Projectdir/$1.contents"
    then 
      {
        echo "$(gettext ' Found contents page : ')$Projectdir/$1.contents"; echo
        echo " create $Projectdir/$1.list with :"; echo "    $Projectdir/$1.contents"; echo
#O     The book must be included at the root of wikibooks
        echo "$Bookfullurl" > $Project/$1.list
        echo " Do not use {{BASEPAGENAME}} in Contents page"
        cat "$Projectdir/$1.contents" | sed -f ~/Add_appendix/datas/content_cleaner.dat > $Projectdir/$1.contents.cleaned
        cat "$Projectdir/$1.contents.cleaned" | grep -v '=' | sed "s/\[\[/https:\/\/$Site\/wiki\//g" | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' | cut -d '|' -f1 > $Projectdir/$1.list
        cat "$Projectdir/$1.contents.cleaned" | grep -v '=' | sed "s/\[\[//g" | sed "s/\]\]//g" | cut -d '|' -f1 > $Projectdir/$1.prj
      }
#O   Case Summary suffix
    elif test -e "$Workdir/books/$1/$1.summary"
    then
      {
#w      Check upstream $Projectdir is not validaded for 'summary'
        Projets=$Workdir/books
        echo "$(gettext ' Found Summary page : ')"$Projets/$1/$1.summary; echo
        echo " create $Projets/$1/$1.list with :"; echo "    $Projets/$1/$1.summary"; echo
#O     The book must be included at the root of wikibooks
        echo "$Bookfullurl" > $Projets/$1/$1.list
        echo " Do not use {{BASEPAGENAME}} in Summary page"
        cat "$Projets/$1/$1.summary" | sed -f ~/Add_appendix/datas/content_cleaner.dat > "$Projets/$1/$1".summary.cleaned
        cat "$Projets/$1/$1.summary.cleaned" | grep -v '=' | sed "s/\[\[/https:\/\/$Site\/wiki\//g" | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' | cut -d '|' -f1 >> $Projets/$1/$1.list
        cat "$Projets/$1/$1.summary.cleaned" | grep -v '=' | sed "s/\[\[//g" | sed "s/\]\]//g" | cut -d '|' -f1  > "$Projets/$1/$1".prj
      }
    #else echo "bookname.suffix : $1.$Suffix not found"
    fi
#O Print file Project.list and file Project.prj
    echo
    echo "$(gettext '  File Project.list')"
    cat $Workdir/books/$1/$1.list
    echo
    echo "$(gettext '  File Project.prj')"
    cat $Workdir/books/$1/$1.prj
    echo " "
    read -p "If all OK : return to continue, Ctrl-C to quit > "
# End list.sh

tests_list.bash

[modifier | modifier le wikicode]
#! /bin/bash
#P file : tests_list.bash
#P Syntax ./tests_list.bash

VERSION=210522

#O Clean screen
    clear
#O 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 directory not found"; exit -1;fi
    rm pwd.txt    
#O Download global variables
    source $Workdir/vars/installdir.var
#O Print test_header.inc.bash version
    echo " test_list.bash version = $VERSION"
    sleep 2
#T    echo "----"
#O Control if the test list.sh file is clean
    echo -e "\033[1;33m Control list.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" list.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
#O test list.sh in test-mode
    echo "Command ./list.sh - --t to verify environnement variables"
    echo "  in test mode with first param empty"
    ./list.sh - --t
    echo;echo " wait for 2 sec"
    sleep 5; echo "----"
#O Test with first param empty
    echo "Command ./list.sh without parameter"
    ./list.sh
    echo;echo " wait for 2 sec"
    sleep 2; echo "----"
#O Test, all with option --t 
   echo " All tests whith parameter --t"   
#O List local 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 ./list.sh LivreTest --t
      elif [ "$Inkey" = "2" ]; then ./list.sh Hélices_de_navires_à_déplacement --t
      elif [ "$Inkey" = "3" ]; then ./list.sh TestBook --t
      elif [ "$Inkey" = "4" ]; then ./list.sh Mkd_\(Extracteur_de_documents\) --t
      elif [ "$Inkey" = "5" ]; then ./list.sh Faire_fleurir_le_sel --t
      elif [ "$Inkey" = "6" ]; then ./list.sh Faire_sa_fleur_de_sel --t      
      elif [ "$Inkey" = "7" ]; then ./list.sh Guide_to_Unix --t
      elif [ "$Inkey" = "8" ]; then ./list.sh Tests_de_la_capacité_des_batteries_d%27accumulateurs
      elif [ "$Inkey" = "9" ]; then ./list.sh LivreTest --t
      else echo "$inkey local url of site not found"; exit 0
      fi
    done
#O End tests_header.inc.bash

content_cleaner.dat

[modifier | modifier le wikicode]

Ce fichier supprime l'espace après ';' et ": ", ':', "* ", '*' "# ", '#' devant la parenthèse '['

S'utilise de la façon suivante :

echo "Chaîne de caractères" | sed -f $Datasdir/content_cleaner.dat

ou :

cat "$Bookname.$Suffix" | sed -f $Datasdir/content_cleaner.dat > "$Bookname.$Suffix.cleaned"

s/: \[/\[/g;s/:\[/\[/g
s/# \[/[/g;s/#\[/\[/g
s/* \[/[/g;s/*\[/\[/g
s/; /;/g