Browse Source

Merge branch 'dev'

David Sniperovitch 8 years ago
parent
commit
0123a6be25
10 changed files with 229 additions and 69 deletions
  1. 3 7
      .travis.yml
  2. 4 0
      alltests
  3. 3 0
      build.sh
  4. 37 7
      cocktail
  5. 68 0
      mirror_pad.pl
  6. 2 0
      mirror_pad.yml.smp
  7. 23 6
      test_cocktail_01
  8. 46 22
      test_cocktail_02
  9. 41 27
      test_cocktail_03
  10. 2 0
      url_test.pub.txt

+ 3 - 7
.travis.yml

@@ -9,13 +9,10 @@ before_install:
   - wget https://github.com/jgm/pandoc/releases/download/1.19.2.1/pandoc-1.19.2.1-1-amd64.deb
   - wget https://github.com/jgm/pandoc/releases/download/1.19.2.1/pandoc-1.19.2.1-1-amd64.deb
   - sudo dpkg -i *.deb
   - sudo dpkg -i *.deb
   - sudo apt-get -qq update
   - sudo apt-get -qq update
-  - sudo apt-get install -y texlive-latex-base
-  - sudo apt-get install -y texlive-font-utils
-  - sudo apt-get install -y texlive-latex-recommended
-  - sudo apt-get install -y texlive-fonts-recommended
-  - sudo apt-get install -y texlive-latex-extra
+  - sudo apt-get install -y texlive-latex-base texlive-font-utils texlive-latex-recommended texlive-fonts-recommended texlive-latex-extra
   - sudo apt-get install -y python-pip
   - sudo apt-get install -y python-pip
   - sudo pip install pandoc-latex-environment
   - sudo pip install pandoc-latex-environment
+  - sudo ./build.sh
 notifications:
 notifications:
   irc:
   irc:
     channels:
     channels:
@@ -26,6 +23,5 @@ notifications:
       - "%{commit_message}"
       - "%{commit_message}"
     use_notice: true
     use_notice: true
 script:
 script:
-  - ./build.sh
-  - ./test_cocktail_01 && ./test_cocktail_02 && ./test_cocktail_03
+  - ./alltests
 
 

+ 4 - 0
alltests

@@ -0,0 +1,4 @@
+#!/bin/bash
+./test_cocktail_01 && ./test_cocktail_02 && ./test_cocktail_03 && echo [ALL TESTS OK] && exit 0
+echo [FAILED] && exit 1
+

+ 3 - 0
build.sh

@@ -2,4 +2,7 @@
 cd && git clone https://github.com/hugoroy/exegetesDoc.git
 cd && git clone https://github.com/hugoroy/exegetesDoc.git
 cd -
 cd -
 cp -v cocktail.conf.smp cocktail.conf
 cp -v cocktail.conf.smp cocktail.conf
+cp -v mirror_pad.yml.smp mirror_pad.yml
+curl -L https://cpanmin.us | perl - App::cpanminus
+cpanm --no-test URI::Encode Etherpad Config::YAML IO::Socket::SSL LWP::UserAgent
 
 

+ 37 - 7
cocktail

@@ -4,8 +4,9 @@ RC_OK=0
 RC_ERROR=1
 RC_ERROR=1
 RC_LOCK=2
 RC_LOCK=2
 RC_CONFIG_MISSED=3
 RC_CONFIG_MISSED=3
-RC_PANDOC_FILES=4
-RC_ARGS=5
+RC_CONFIG_PARAM=4
+RC_PANDOC_FILES=5
+RC_ARGS=6
 
 
 end_with_code() {
 end_with_code() {
   local rc=$1
   local rc=$1
@@ -28,7 +29,7 @@ die() {
   local message
   local message
   local rc
   local rc
 
 
-  if test $# == 2;
+  if test $# -eq 2;
   then
   then
     message=$1
     message=$1
     rc=$2
     rc=$2
@@ -42,9 +43,12 @@ die() {
 }
 }
 
 
 verbose() {
 verbose() {
-  if test "$VERBOSE" -ne 0;
+  if test -n "$VERBOSE";
   then
   then
-    echo "$$ $@"
+    if test "$VERBOSE" -ne 0;
+    then
+      echo "$$ $@"
+    fi
   fi
   fi
 }
 }
 
 
@@ -86,7 +90,7 @@ init_check() {
   fi
   fi
 
 
   # external tools
   # external tools
-  for tool in touch curl pandoc pdflatex
+  for tool in touch pandoc pdflatex
   do
   do
     local tool_location=$(command -v $tool)
     local tool_location=$(command -v $tool)
     if test "$tool_location";
     if test "$tool_location";
@@ -108,8 +112,10 @@ mirror_pad() {
   local url=$1
   local url=$1
   local filename=$2
   local filename=$2
   verbose "[$FUNCNAME] url=$url filename=$filename"
   verbose "[$FUNCNAME] url=$url filename=$filename"
-  RESPONSE=$(curl --silent --show-error $url --output $filename 2>&1)
+
+  RESPONSE=$(perl $base/mirror_pad.pl $url > "$filename")
   RC=$?
   RC=$?
+
   local errstr="[$FUNCNAME] RC=[$RC] $RESPONSE"
   local errstr="[$FUNCNAME] RC=[$RC] $RESPONSE"
   if test "$RC" -eq 0;
   if test "$RC" -eq 0;
   then
   then
@@ -383,6 +389,30 @@ base=$( cd $( dirname "${BASH_SOURCE[0]}" ) && pwd )
 if test -r "$base/cocktail.conf";
 if test -r "$base/cocktail.conf";
 then
 then
   source "$base/cocktail.conf"
   source "$base/cocktail.conf"
+  error_in_config=0
+  # Should be in config file
+  if test -z "$PANDOC_FILTER_BASE";
+  then
+    echo "$$ PANDOC_FILTER_BASE not found in config file"
+    error_in_config=1
+  fi
+  if test -z "$PANDOC_INCLUDE_BASE";
+  then
+    echo "$$ PANDOC_INCLUDE_BASE not found in config file"
+    error_in_config=1
+  fi
+  if test -z "$WORKING_FOLDER";
+  then
+    echo "$$ WORKING_FOLDER not found in config file"
+  fi
+  if test -z "$STORE";
+  then
+    echo "$$ STORE not found in config file"
+  fi
+  if test "$error_in_config" -eq 1;
+  then
+    die "Errors in config file, maybee empty ?" $RC_CONFIG_PARAM
+  fi
 else
 else
   die "cocktail.conf is missing, see config.conf.smp for example" $RC_CONFIG_MISSED
   die "cocktail.conf is missing, see config.conf.smp for example" $RC_CONFIG_MISSED
 fi
 fi

+ 68 - 0
mirror_pad.pl

@@ -0,0 +1,68 @@
+#!/usr/bin/env perl 
+use strict;
+use warnings;
+use Config::YAML;
+use Data::Dumper;
+use Encode ();
+use FindBin;
+use URI::Encode ();
+
+
+my $config_file = "$FindBin::Bin/mirror_pad.yml";
+die "'$config_file' introuvable\n" unless -r $config_file;
+my $config = Config::YAML->new(config => $config_file);
+
+my $pad_base = $config->get_apiurl or die "apiurl is missing in config file ?";
+
+my $pad_url = URI::Encode::uri_decode(shift);
+warn "PAD_URL=$pad_url";
+
+my $pad_content;
+if($pad_url =~ m{\Q$pad_base/group.html}) {
+    my $api_key = $config->get_apikey or die "apikey is missing in config file ?";
+    $pad_content = get_private_pad($pad_url, $pad_base, $api_key);
+    exit 1 if not defined $pad_content;
+}
+else {
+    $pad_content = get_public_pad($pad_url);
+}
+print $pad_content;
+
+sub get_private_pad {
+    require Etherpad;
+    my ($pad_url, $api_url, $api_key) = @_;
+    my $ep = Etherpad->new(
+      url    => $api_url,
+      apikey => $api_key,
+    );
+
+    my $pad_base = quotemeta $api_url;
+    warn "PAD_BASE=$pad_base";
+    # Extraction de l'id du pad à partir de l'url du pad
+    my $pad_id;
+    ($pad_id) = $pad_url =~ m{^$pad_base/.+?/(g\.[^/]+)}o;
+    warn "PADID=$pad_id\n";
+    if(my($pad_text) = $ep->get_text($pad_id)) {
+        $pad_text = Encode::encode('UTF-8', $pad_text);
+        return $pad_text;
+    }
+    else {
+        return;
+    }
+}
+
+
+sub get_public_pad {
+    require LWP::UserAgent;
+    my ($pad_url) = @_;
+    my $ua = LWP::UserAgent->new;
+    my $resp = $ua->get($pad_url);
+    if($resp->is_success) {
+        return $resp->decoded_content;
+    }
+    else {
+        warn $resp->status_line;
+        return
+    }
+}
+

+ 2 - 0
mirror_pad.yml.smp

@@ -0,0 +1,2 @@
+apiurl: 'https://pad.exegetes.eu.org'
+apikey: 'Le contenu de APIKEY.TXT de votre EtherPad'

+ 23 - 6
test_cocktail_01

@@ -1,7 +1,24 @@
 #!/bin/bash
 #!/bin/bash
-./cocktail -v -d MonDossier -p Abro2 \
-           -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' \
-           -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' && \
-./cocktail -v -d privacyshield -p PrivShield-DRI \
-           -b 'https://pad.exegetes.eu.org/p/g.LOe9KTSEtDDWQW3v-DRI-Interv-Garde/export/txt' \
-           -g 'https://pad.exegetes.eu.org/p/g.LOe9KTSEtDDWQW3v-DRI-Intervention/export/txt'
+
+if test "$TRAVIS" = "true";
+then
+  URL_FILE=url_test.pub.txt
+else
+  URL_FILE=url_test.priv.txt
+fi
+
+if test -r "$URL_FILE";
+then
+  URL_BASE=$(head -n1 "$URL_FILE")
+  URL_GARDE=$(tail -n1 "$URL_FILE")
+else
+  echo "'$URL_FILE' introuvable"
+  exit 1
+fi
+
+./cocktail -v \
+           -d MonDossier \
+           -p Abro2 \
+           -b "$URL_BASE" \
+           -g "$URL_GARDE"
+

+ 46 - 22
test_cocktail_02

@@ -1,11 +1,28 @@
 #!/bin/bash
 #!/bin/bash
 
 
-echo "Test 02: 2 compilations dans le même dossier, projets différents."
-echo "Les deux compilations doivent réussir"
+echo "Test 02: 2 compilations dans le même dossier, projets différents"
+echo "Les deux doivent correctement se dérouler"
+
+if test "$TRAVIS" = "true";
+then
+  URL_FILE=url_test.pub.txt
+else
+  URL_FILE=url_test.priv.txt
+fi
+
+if test -r "$URL_FILE";
+then
+  URL_BASE=$(head -n1 "$URL_FILE")
+  URL_GARDE=$(tail -n1 "$URL_FILE")
+else
+  echo "'$URL_FILE' introuvable"
+  exit 1
+fi
 
 
-RC1=99
-RC2=99
 
 
+
+# pids conserve la liste des pids
+# retcode conserve le code retour de chaque pid une fois terminé
 handle_child() {
 handle_child() {
   local tmp=()
   local tmp=()
   for((i=0;i<${#pids[@]};++i));
   for((i=0;i<${#pids[@]};++i));
@@ -13,17 +30,7 @@ handle_child() {
     if test ! -d /proc/${pids[i]};
     if test ! -d /proc/${pids[i]};
     then
     then
       wait ${pids[i]}
       wait ${pids[i]}
-      RC0=$?
-      echo "Stopped ${pids[i]}; exit code: $RC0"
-      if test "$RC1" -eq 99;
-      then
-        RC1="$RC0"
-      else
-        if test "$RC2" -eq 99;
-        then
-          RC2="$RC0"
-        fi
-      fi
+      retcode[${pids[i]}]=$?
     else
     else
       tmp+=(${pids[i]})
       tmp+=(${pids[i]})
     fi
     fi
@@ -36,10 +43,18 @@ trap "handle_child" CHLD
 
 
 
 
 # Start background processes
 # Start background processes
-./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+./cocktail -v \
+           -d MonDossier \
+           -p Abro2 \
+           -b "$URL_BASE" \
+           -g "$URL_GARDE" &
 pids+=($!)
 pids+=($!)
 
 
-./cocktail -v -d MonDossier -p Abro3 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+./cocktail -v \
+           -d MonDossier \
+           -p Abro3 \
+           -b "$URL_BASE" \
+           -g "$URL_GARDE" &
 pids+=($!)
 pids+=($!)
 
 
 # Wait until all background processes are stopped
 # Wait until all background processes are stopped
@@ -49,14 +64,23 @@ do
   sleep 2;
   sleep 2;
 done
 done
 echo STOPPED
 echo STOPPED
-echo "RC1=$RC1 RC2=$RC2"
 
 
-if test "$RC1" -eq 0 -a "$RC2" -eq 0;
+# affichage des code retour et generation de la chaine de test
+for pid in "${!retcode[@]}"
+do
+  statusstring="$statusstring $pid=${retcode[$pid]}"
+  retcodestr="${retcodestr}${retcode[$pid]}"
+done
+echo $statusstring
+
+if test $retcodestr -eq "00" -o $retcodestr -eq "00";
 then
 then
   echo "Test réussi"
   echo "Test réussi"
+  echo "Les deux processus se sont terminés en code 0"
   exit 0
   exit 0
+else
+  echo "Test échoué."
+  echo "Les deux processus doivent se terminer en code 0"
+  exit 1
 fi
 fi
 
 
-echo "Test échoué"
-exit 1
-

+ 41 - 27
test_cocktail_03

@@ -3,9 +3,24 @@
 echo "Test 03: 2 compilations dans le même dossier, même projet."
 echo "Test 03: 2 compilations dans le même dossier, même projet."
 echo "Un des deux doit tomber en erreur"
 echo "Un des deux doit tomber en erreur"
 
 
-RC1=99
-RC2=99
+if test "$TRAVIS" = "true";
+then
+  URL_FILE=url_test.pub.txt
+else
+  URL_FILE=url_test.priv.txt
+fi
+
+if test -r "$URL_FILE";
+then
+  URL_BASE=$(head -n1 "$URL_FILE")
+  URL_GARDE=$(tail -n1 "$URL_FILE")
+else
+  echo "'$URL_FILE' introuvable"
+  exit 1
+fi
 
 
+# pids conserve la liste des pids
+# retcode conserve le code retour de chaque pid une fois terminé
 handle_child() {
 handle_child() {
   local tmp=()
   local tmp=()
   for((i=0;i<${#pids[@]};++i));
   for((i=0;i<${#pids[@]};++i));
@@ -13,17 +28,7 @@ handle_child() {
     if test ! -d /proc/${pids[i]};
     if test ! -d /proc/${pids[i]};
     then
     then
       wait ${pids[i]}
       wait ${pids[i]}
-      RC0=$?
-      echo "Stopped ${pids[i]}; exit code: $RC0"
-      if test "$RC1" -eq 99;
-      then
-        RC1="$RC0"
-      else
-        if test "$RC2" -eq 99;
-        then
-          RC2="$RC0"
-        fi
-      fi
+      retcode[${pids[i]}]=$?
     else
     else
       tmp+=(${pids[i]})
       tmp+=(${pids[i]})
     fi
     fi
@@ -36,10 +41,18 @@ trap "handle_child" CHLD
 
 
 
 
 # Start background processes
 # Start background processes
-./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+./cocktail -v \
+           -d MonDossier \
+           -p Abro2 \
+           -b "$URL_BASE" \
+           -g "$URL_GARDE" &
 pids+=($!)
 pids+=($!)
 
 
-./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+./cocktail -v \
+           -d MonDossier \
+           -p Abro2 \
+           -b "$URL_BASE" \
+           -g "$URL_GARDE" &
 pids+=($!)
 pids+=($!)
 
 
 # Wait until all background processes are stopped
 # Wait until all background processes are stopped
@@ -49,22 +62,23 @@ do
   sleep 2;
   sleep 2;
 done
 done
 echo STOPPED
 echo STOPPED
-echo "RC1=$RC1 RC2=$RC2"
 
 
-# cocktail exits with rc 2 if error lock
-if test "$RC1" -eq 0 -a "$RC2" -eq 2;
-then
-  echo "Test réussi"
-  exit 0
-fi
+# affichage des code retour et generation de la chaine de test
+for pid in "${!retcode[@]}"
+do
+  statusstring="$statusstring $pid=${retcode[$pid]}"
+  retcodestr="${retcodestr}${retcode[$pid]}"
+done
+echo $statusstring
 
 
-# cocktail exits with rc 2 if error lock
-if test "$RC2" -eq 0 -a "$RC1" -eq 2;
+if test $retcodestr -eq "02" -o $retcodestr -eq "20";
 then
 then
   echo "Test réussi"
   echo "Test réussi"
+  echo "Un des 2 processus s'est terminé en code 0 et l'autre en code 2"
   exit 0
   exit 0
+else
+  echo "Test échoué."
+  echo "Un des 2 processus doit se terminer en code 0 et l'autre en code 2"
+  exit 1
 fi
 fi
 
 
-echo "Test échoué"
-exit 1
-

+ 2 - 0
url_test.pub.txt

@@ -0,0 +1,2 @@
+https%3A%2F%2Fpad.exegetes.eu.org%2Fp%2Fg.DSXI1kGFT1gjor66%24Abro-REP-Tele2-Principal%2Fexport%2Ftxt
+https%3A%2F%2Fpad.exegetes.eu.org%2Fp%2Fg.DSXI1kGFT1gjor66%24Abro-REP-Tele2-Garde%2Fexport%2Ftxt