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

Un livre de Wikilivres.

File for development of the function ecfpc ecfpc.bash, and test-ecfpc.bash to tests the function included in annex.lib

Fichier de mise au point de la fonction ecfpc ecfpc.bash, et test-ecfpc.bash pour éprouver la fonction en librairie annex.lib

function ecfpc[modifier | modifier le wikicode]

Development of the function

function ecfpc ()
#H Function ecfpc
#H first param : url of collection (compiled book)
#H Return value : no return value
#H VERSION 210424

#O Affect the variable $Projectdir
#T Print the project directory echo "Project directory = $Projectdir"; exit 0

#O Test if the file is a version Collections
    if [ -n $Site ] && [ "$Suffix" = "compiled" ]; 
      echo "url is a version Collections."; 	 
#O   Download script from the file $Lastfield
	  #wget $1
#T Test break exit 0

#O 	 Find the contents of file named '$Lastfield' is the downloaded html code
     cat $Lastfield | grep /$Bookname/  > beforelastfield.txt

#T	 cat beforelastfield.txt and select 
	 cat beforelastfield.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
#O If project '$Bookname' exist
    if test -d $Projectdir 
	  echo "Project directory = $Projectdir"
      if [ -r "$Projectdir/$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 ! ... Continue ... ')"
      else cp $Bookname.$Suffix $Projectdir/.

test-ecfpc.bash with function in annex.lib[modifier | modifier le wikicode]

#H File : ecfpc.bash function ecfpc 'extract contents from printable book'
#H Syntax for tests ecfpc <book url>, example in tests directory :
#H ./
#H (à faire ?: ./
#H ./

#P print prog, version and Why
echo " $Version for testing ecfpc in annex.lib"

#P initialization of variables
    Return_value="non available"

#P find the current directory
     pwd > pwd.txt
     read Currentdir < pwd.txt
#P find the user home directory
     echo -n "/" > homedir.txt
     cat pwd.txt | head -n 3 | cut -d '/' -f 2-3 >> homedir.txt
     read Homedir < homedir.txt
     echo -n "/" > workdir.txt
     cat pwd.txt | head -n 4 | cut -d '/' -f 2-4 >> workdir.txt
     read Workdir < workdir.txt
    # rm pwd.txt homedir.txt workdir.txt
#P print current, home, working directories
    echo "Current directory = $Currentdir"
    echo ""
    echo "Home directory = $Homedir"
    echo ""
    echo "Working directory = $Workdir"
#T Test break exit 0

#P Find lib directory
    if test -a /usr/local/lib/annex.lib; then Libdir=/usr/local/lib; Bindir=/usr/local/bin; Sharedir=/usr/local/share
    elif test -a $Workdir/lib/annex.lib; then Libdir=$Workdir/lib; Bindir=Workdir/bin; Sharedir=$Workdir/share
    elif test -a $Workdir/tests/1-annex.lib/annex.lib; then Libdir=$Workdir/tests/1-annex.lib/
    else echo "Lib directory is not found, exit -1"; exit -1
#P Find datas directory
    if test -a $Workdir/datas/conversions.dat; then Datadir=$Workdir/datas; else echo "Datas directory is not found in $Workdir/datas"; fi

# print directories and if OK
   echo -n "Working directory = $Workdir"
   if [ -d $Workdir ]; then echo " found"; else echo "notfound";fi
   echo -n "Lib directory = $Libdir"
   if [ -d $Libdir ]; then echo " found"; else echo "notfound";fi
   echo -n "bin directory = $Bindir"
   if [ -d $Bindir ]; then echo " found"; else echo "notfound";fi
   echo -n "share directory = $Sharedir"
   if [ -d $Sharedir ]; then echo " found"; else echo "notfound";fi
   echo "----"
#T Testbreak exit 0
#O If the test file funtion_ecfpc is in current directory then include this file
    #if test -a function_ecfpc ; then source function_ecfpc; echo "function ecfpc is in current directory";fi
#O Include the lib annex.lib which contains funtion findbook and ecfpc()
    source $Libdir/annex.lib
#O Print syntax if the first parameter is no entry in test mode
	#if test -z $1; then echo "Syntax : ecfpc <book url> or ./ecfpc <book url>"; exit 1; fi

#O Test url with collections version
	echo "Test for $1"
	findbook $1
	echo ""
	echo "* Bookfullurl: "$Bookfullurl
	echo "* mw book url: "$MWbookurl
    echo "* Site name  : "$Site
    echo "* Last field : "$Lastfield
    echo "* Bookname   : "$Bookname
    echo "* Suffix     : "$Suffix
    echo "* Bookname.Suffix : "$Bookname.$Suffix
#T Test break exit 0
#O Test the function ecfpc 
    ecfpc $1
#T Print bookname.suffix in test mode
    if [ $0="./" ] || [ $0="$Testsdir/1-annex.lib/13-ecfpc/" ]; then echo "$Bookname.$Suffix :"; cat $Bookname.$Suffix; fi