# HG changeset patch # User Christophe Lincoln # Date 1336782699 -7200 # Node ID dd17cc10cd6dea3df8a9bda309d99e531fbcb8d3 # Parent 1c9fc309b4ade2be5bc3df237d437c8dd960f89d Improve libtaz.sh doc and log function + add log to testsuite.sh diff -r 1c9fc309b4ad -r dd17cc10cd6d doc/libtaz.txt --- a/doc/libtaz.txt Sat May 12 01:55:20 2012 +0200 +++ b/doc/libtaz.txt Sat May 12 02:31:39 2012 +0200 @@ -6,20 +6,29 @@ DESCRIPTION LibTaz is the base SliTaz SHell library used by almost all tools and utilities. It provide common SHell script functions, parse the cmdline - options and store values in a variable. The output messages can be + options and store values in a variable. The output messages can be formated for raw/text, gtk, html and by default they are formated for a standard terminal supporting colors. LibTaz is in the directory /lib/libtaz.sh since it is used when /usr may not be mounted. - + FUNCTIONS - status - separator - boldify [string] - check_root + status Return command status [Done|Failed] + separator Display a line separator + newline Echo a new line if gettext or echo -n is used + boldify [string] Usae bold font for term, html or GTK output + indent Ident text in term mode + check_root Check if user is logged as root + confirm Read anser to confirm an action + log [string] Log activity, $activity must be set OPTIONS --output=[raw|gtk|html] + --activity=/path/files/activity + +EXAMPLES + log "Message" + check_root AUTHOR Written by Christophe Lincoln - + diff -r 1c9fc309b4ad -r dd17cc10cd6d rootfs/lib/libtaz.sh --- a/rootfs/lib/libtaz.sh Sat May 12 01:55:20 2012 +0200 +++ b/rootfs/lib/libtaz.sh Sat May 12 02:31:39 2012 +0200 @@ -68,6 +68,11 @@ done && echo "" } +# New line for echo -n or gettext. +newline() { + echo "" +} + # Display a bold message. GTK Yad: Works only in --text="" boldify() { case $output in @@ -113,16 +118,9 @@ [ "$answer" == "$(translate_query y)" ] } -# New line for echo -n or gettext. -newline() { - echo "" -} - -# Log activities, we want first letter capitalized. $activity should be set -# by the script. The log format is suitable for web interfaces like cook. -# Usage: echo "Message" | log +# Log activities. $activity should be set by the script. The log format +# is suitable for web interfaces like cook. Usage: log "String" log() { [ "$activity" ] || activity=/var/log/slitaz/libtaz.log - grep ^[A-Z] | \ - sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity + echo "$(date '+%Y-%m-%d %H:%M') : $@" >> $activity } diff -r 1c9fc309b4ad -r dd17cc10cd6d testsuite.sh --- a/testsuite.sh Sat May 12 01:55:20 2012 +0200 +++ b/testsuite.sh Sat May 12 02:31:39 2012 +0200 @@ -5,18 +5,25 @@ check_libtaz() { echo -n "Checking libtaz.sh: status() 0" status - + echo -n "Checking libtaz.sh: status() 1" touch /tmp/1/2/2/4 2>/dev/null status - + echo -n "Checking libtaz.sh: boldify() " boldify "Message" - + echo "Checking libtaz.sh: separator" separator } +echo -n "Checking libtaz.sh: log()" +activity=/tmp/testsuite.log +log "Message from SliTaz testsuite" +status +cat $activity +rm -f $activity + check_libtaz output="raw" check_libtaz