Browse Source

Merge branch 'dev'

Sniperovitch 8 years ago
parent
commit
4112fd9385
1 changed files with 42 additions and 35 deletions
  1. 42 35
      cocktail

+ 42 - 35
cocktail

@@ -9,6 +9,7 @@ end_with_code() {
 
 
   cleanup_working_folder
   cleanup_working_folder
   unlock_project
   unlock_project
+  verbose "[$FUNCNAME] exiting with RC=[$rc]"
   exit $rc
   exit $rc
 }
 }
 
 
@@ -34,31 +35,31 @@ debug() {
 init_check() {
 init_check() {
   if test -e $LOCK_FILE;
   if test -e $LOCK_FILE;
   then
   then
-    die "$FUNCNAME lock=$LOCK_FILE exists. Wait compilation or erase it"
+    die "[$FUNCNAME] lock=$LOCK_FILE exists. Wait compilation or erase it"
   fi
   fi
 
 
   # PANDOC_FILTER_BASE should exists
   # PANDOC_FILTER_BASE should exists
   if test ! -d "$PANDOC_FILTER_BASE";
   if test ! -d "$PANDOC_FILTER_BASE";
   then
   then
-    die "$FUNCNAME: PANDOC_FILTER_BASE=$PANDOC_FILTER_BASE unavailable"
+    die "[$FUNCNAME]: PANDOC_FILTER_BASE=$PANDOC_FILTER_BASE unavailable"
   fi
   fi
 
 
   # PANDOC_INCLUDE_BASE should exists
   # PANDOC_INCLUDE_BASE should exists
   if test ! -d "$PANDOC_INCLUDE_BASE";
   if test ! -d "$PANDOC_INCLUDE_BASE";
   then
   then
-    die "$FUNCNAME: PANDOC_INCLUDE_BASE=$PANDOC_INCLUDE_BASE unavailable"
+    die "[$FUNCNAME]: PANDOC_INCLUDE_BASE=$PANDOC_INCLUDE_BASE unavailable"
   fi
   fi
 
 
   # STORE should exists
   # STORE should exists
   if test ! -d "$STORE" -o ! -w "$STORE";
   if test ! -d "$STORE" -o ! -w "$STORE";
   then
   then
-    die "$FUNCNAME: STORE=$STORE should be a writable folder"
+    die "[$FUNCNAME]: STORE=$STORE should be a writable folder"
   fi
   fi
 
 
   # WORKING_FOLDER should exists
   # WORKING_FOLDER should exists
   if test ! -d "$WORKING_FOLDER" -o ! -w "$WORKING_FOLDER";
   if test ! -d "$WORKING_FOLDER" -o ! -w "$WORKING_FOLDER";
   then
   then
-    die "$FUNCNAME: WORKING_FOLDER=$WORKING_FOLDER should be a writable folder"
+    die "[$FUNCNAME]: WORKING_FOLDER=$WORKING_FOLDER should be a writable folder"
   fi
   fi
 
 
   # external tools
   # external tools
@@ -67,26 +68,26 @@ init_check() {
     local tool_location=$(command -v $tool)
     local tool_location=$(command -v $tool)
     if test "$tool_location";
     if test "$tool_location";
     then
     then
-      verbose "init_check() $tool=$tool_location"
+      verbose "[$FUNCNAME] $tool=$tool_location"
     else
     else
-      die "init_check() $tool unavailable"
+      die "[$FUNCNAME] $tool unavailable"
     fi
     fi
   done
   done
 }
 }
 
 
 mirror_pad() {
 mirror_pad() {
-  debug "$FUNCNAME ARGS:$@"
+  debug "[$FUNCNAME] ARGS:$@"
   if test $# -ne 2;
   if test $# -ne 2;
   then
   then
-    die 'usage: $FUNCNAME url filename'
+    die 'usage: [$FUNCNAME] url filename'
   fi
   fi
 
 
   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=$(curl --silent --show-error $url --output $filename 2>&1)
   RC=$?
   RC=$?
-  local errstr="$FUNCNAME url=$url filename$filename [RC:$RC] $RESPONSE"
+  local errstr="[$FUNCNAME] url=$url filename$filename [RC:$RC] $RESPONSE"
   if test "$RC" -gt 0;
   if test "$RC" -gt 0;
   then
   then
     die "$errstr"
     die "$errstr"
@@ -96,15 +97,15 @@ mirror_pad() {
 }
 }
 
 
 pad2json() {
 pad2json() {
-  debug "$FUNCNAME ARGS:$@"
+  debug "[$FUNCNAME] ARGS:$@"
   if test $# -ne 2;
   if test $# -ne 2;
   then
   then
-    die "usage: $FUNCNAME input_file output_file"
+    die "usage: [$FUNCNAME] input_file output_file"
   fi
   fi
 
 
   local input=$1
   local input=$1
   local output=$2
   local output=$2
-  verbose "$FUNCNAME input=$input output=$output"
+  verbose "[$FUNCNAME] input=$input output=$output"
 
 
   pandoc \
   pandoc \
     -f markdown "$input" \
     -f markdown "$input" \
@@ -112,20 +113,20 @@ pad2json() {
 }
 }
 
 
 pad2docx() {
 pad2docx() {
-  debug "$FUNCNAME PWD:$PWD ARGS:$@"
+  debug "[$FUNCNAME] PWD:$PWD ARGS:$@"
   if test $# -ne 2;
   if test $# -ne 2;
   then
   then
-    die 'usage: $FUNCNAME input_file output_file'
+    die 'usage: [$FUNCNAME] input_file output_file'
   fi
   fi
 
 
   local input=$1
   local input=$1
   local output=$2
   local output=$2
   local refdoc="$PANDOC_INCLUDE_BASE/exegetes.docx"
   local refdoc="$PANDOC_INCLUDE_BASE/exegetes.docx"
-  verbose "$FUNCNAME input=$input output=$output"
+  verbose "[$FUNCNAME] input=$input output=$output"
 
 
   if ! test -e "$refdoc";
   if ! test -e "$refdoc";
   then
   then
-    die "$FUNCNAME refdoc=$refdoc unavailable"
+    die "[$FUNCNAME] refdoc=$refdoc unavailable"
   fi
   fi
 
 
   pandoc \
   pandoc \
@@ -139,15 +140,15 @@ pad2docx() {
 }
 }
 
 
 pad2html() {
 pad2html() {
-  debug "$FUNCNAME ARGS:$@"
+  debug "[$FUNCNAME] ARGS:$@"
   if test $# -ne 2;
   if test $# -ne 2;
   then
   then
-    die 'usage: $FUNCNAME input_file output_file'
+    die 'usage: [$FUNCNAME] input_file output_file'
   fi
   fi
 
 
   local input=$1
   local input=$1
   local output=$2
   local output=$2
-  verbose "$FUNCNAME input=$input output=$output"
+  verbose "[$FUNCNAME] input=$input output=$output"
 
 
   pandoc \
   pandoc \
     -f markdown "$input" \
     -f markdown "$input" \
@@ -159,15 +160,15 @@ pad2html() {
 }
 }
 
 
 pad2markdown() {
 pad2markdown() {
-  debug "$FUNCNAME ARGS:$@"
+  debug "[$FUNCNAME] ARGS:$@"
   if test $# -ne 2;
   if test $# -ne 2;
   then
   then
-    die 'usage: $FUNCNAME input_file output_file'
+    die 'usage: [$FUNCNAME] input_file output_file'
   fi
   fi
 
 
   local input=$1
   local input=$1
   local output=$2
   local output=$2
-  verbose "$FUNCNAME input=$input output=$output"
+  verbose "[$FUNCNAME] input=$input output=$output"
 
 
   pandoc \
   pandoc \
     -f markdown "$input" \
     -f markdown "$input" \
@@ -180,15 +181,15 @@ pad2markdown() {
 }
 }
 
 
 pad2tex() {
 pad2tex() {
-  debug "$FUNCNAME ARGS:$@"
+  debug "[$FUNCNAME] ARGS:$@"
   if test $# -ne 2;
   if test $# -ne 2;
   then
   then
-    die 'usage: $FUNCNAME input_file output_file'
+    die 'usage: [$FUNCNAME] input_file output_file'
   fi
   fi
 
 
   local input=$1
   local input=$1
   local output=$2
   local output=$2
-  verbose "$FUNCNAME input=$input output=$output"
+  verbose "[$FUNCNAME] input=$input output=$output"
 
 
   pandoc \
   pandoc \
     -f markdown "$input" \
     -f markdown "$input" \
@@ -202,36 +203,42 @@ pad2tex() {
 }
 }
 
 
 tex2pdf() {
 tex2pdf() {
-  debug "$FUNCNAME ARGS:$@"
+  debug "[$FUNCNAME] ARGS:$@"
   if test $# -ne 2;
   if test $# -ne 2;
   then
   then
-    die 'usage: $FUNCNAME input_file output_file'
+    die 'usage: [$FUNCNAME] input_file output_file'
   fi
   fi
 
 
   local input=$1
   local input=$1
   local output=$2
   local output=$2
-  verbose "$FUNCNAME input=$input output=$output"
+  verbose "[$FUNCNAME] input=$input output=$output"
 
 
   pdflatex -interaction=nonstopmode -output-directory="$WORKING_FOLDER" "$input" >/dev/null
   pdflatex -interaction=nonstopmode -output-directory="$WORKING_FOLDER" "$input" >/dev/null
   pdflatex -interaction=nonstopmode -output-directory="$WORKING_FOLDER" "$input" >/dev/null
   pdflatex -interaction=nonstopmode -output-directory="$WORKING_FOLDER" "$input" >/dev/null
 }
 }
 
 
 lock_project() {
 lock_project() {
-  verbose "$FUNCNAME $PROJET locked with $LOCK_FILE"
+  verbose "[$FUNCNAME] $PROJET locked with $LOCK_FILE"
   touch $LOCK_FILE
   touch $LOCK_FILE
 }
 }
 
 
 unlock_project() {
 unlock_project() {
   if test -e "$LOCK_FILE";
   if test -e "$LOCK_FILE";
   then
   then
-    verbose "$FUNCNAME lock=$LOCK_FILE exists, delete"
+    verbose "[$FUNCNAME] lock=$LOCK_FILE exists, delete"
     rm -f "$LOCK_FILE"
     rm -f "$LOCK_FILE"
+    if test ! -e "$LOCK_FILE";
+    then
+      verbose "[$FUNCNAME] $PROJET unlocked, $LOCK_FILE removed."
+    else
+      # we can'nt call die inside a function called by die
+      verbose "[$FUNCNAME] we can not unlock $PROJET, $LOCK_FILE still on disk."
+    fi
   fi
   fi
-  verbose "$FUNCNAME $PROJET unlocked"
 }
 }
 
 
 cleanup_working_folder() {
 cleanup_working_folder() {
-  verbose "$FUNCNAME WORKING_FOLDER=$WORKING_FOLDER"
+  verbose "[$FUNCNAME] WORKING_FOLDER=$WORKING_FOLDER"
   if test -n "$WORKING_FOLDER" -a -d "$WORKING_FOLDER";
   if test -n "$WORKING_FOLDER" -a -d "$WORKING_FOLDER";
   then
   then
     if test "$VERBOSE" -eq 1;
     if test "$VERBOSE" -eq 1;
@@ -242,7 +249,7 @@ cleanup_working_folder() {
     fi
     fi
     if test ! -d "$WORKING_FOLDER";
     if test ! -d "$WORKING_FOLDER";
     then
     then
-      verbose "$FUNCNAME $WORKING_FOLDER removed"
+      verbose "[$FUNCNAME] $WORKING_FOLDER removed"
     fi
     fi
     # rmdir "$WORKING_FOLDER"
     # rmdir "$WORKING_FOLDER"
   fi
   fi