Aller au contenu

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

Un livre de Wikilivres.[modifier | modifier le wikicode]

#! /bin/bash
#H File
#H Syntax in console : "./bin/dowload <bookname>"
#H Example : "./ LivreTest" in test mode in a terminal
#H Creation date : 28/03/2020
#H Modified : 26 april 2020 par GC
#H Modified : 30 may 2020 par GC for automatic insrallation
#H Modified : 27 may 2021 for Add_Appendix
#H Documentation version de la documentation on WikiLivres le : 26 april 2020
#D documentation
#D is included and there is no need to recreate the environment
#D   variables
#D Download creates or recreates a local html book with html subdirectories of all articles
#D Create a concatenated sub-list locale.list of the book from book articles-list 
#D To document the book with its subpages :
#D Create a directory containing the main html page of the book and local directories 
#D   containing an html version of the articles 
#O . for translation
#O Include the file
    if test -e ~/Add_appendix/bin/; then source ~/Add_appendix/bin/
    else echo "$Bindir/ not found. Execute sbin/"; exit -1
#O Download the complete book structure in working directory
    cd $Projectdir
    mkdir temp
    if [ "$2" = "--t" ]; then echo "current dir : "; pwd; fi
    echo "download all directories of the book '$1'"
    wget -r -linf -k -p -E  -i $1.list -o $Projectdir/temp/wget-log-download.txt
    echo "----------"
#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 '$1'"
      cat $Projectdir/$1.list | sed "s/https:\/\///g" | sed "s/\ /\\\ /g" | tr '\n' ',' > $Projectdir/$1.locale.list
      echo "   Concatenated local list $Projectdir/$1.locale.list :"
      echo ""
      cat $Projectdir/$1.locale.list
      echo "----------"
#O Copy the html files to respective directories
#O   Create a file with the pagename $Projectdir/$1.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/$1.locale.list | sed "s/ /\\ /g" | cut -d ',' -f1 > $Projectdir/$1.mainPage
      echo "----------"
#O   Initialize the variable $mainPage
      read mainPage < $Projectdir/$1.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/$1.dirs
      echo "sub-working-diectories : "
      cat  $Projectdir/$1.dirs
      echo "----------" 
#O   Copy the html pages and subpages in the respective directories
      while read line
        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/$1.list
      rm source ; rm destination
#O Quitter le programme d'essai et passer à la création de la page "Annexe" des articles.
    echo "----------"
# echo -en "\033[31mRetour-chariot une pour créer l'Annexe des articles, Ctrl-C pour quitter.\033[0m "
# read -p ">"
# "\033[31mRetour-chariot une pour créer l'Annexe, Ctrl-C pour quitter >"
# exit 0
# End[modifier | modifier le wikicode]

#! /bin/bash
#P file : tests_download.bash
#P Syntax ./tests_download.bash


#O Clean screen
#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 tests_download.bash version
    echo " tests_download.bash version = $VERSION"
    sleep 2
#T    echo "----"
#O Control if the test file is clean
    echo -e "\033[1;33m Control 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" >> 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 in test-mode
    echo "Command ./ - --t to verify environnement variables"
    echo "  in test mode with first param empty"
    ./ - --t
    echo;echo " wait for 2 sec"
    sleep 5; echo "----"
#O Test with first param empty
    echo "Command ./ without parameter"
    echo;echo " wait for 2 sec"
    sleep 2; echo "----"
#O Test, all with option --t 
   echo " All tests whith parameter --t"   
#O download local books for tests
    for i in 'seq 1 9'
      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 ./ LivreTest --t
      elif [ "$Inkey" = "2" ]; then ./ Hélices_de_navires_à_déplacement --t
      elif [ "$Inkey" = "3" ]; then ./ TestBook --t
      elif [ "$Inkey" = "4" ]; then ./ Mkd_\(Extracteur_de_documents\) --t
      elif [ "$Inkey" = "5" ]; then ./ Faire_fleurir_le_sel --t
      elif [ "$Inkey" = "6" ]; then ./ Faire_sa_fleur_de_sel --t      
      elif [ "$Inkey" = "7" ]; then ./ Guide_to_Unix --t
      elif [ "$Inkey" = "8" ]; then ./ Tests_de_la_capacité_des_batteries_d%27accumulateurs
      elif [ "$Inkey" = "9" ]; then ./ LivreTest --t
      else echo "$inkey local url of site not found"; exit 0
#O End tests_download.bash