slitaz-base-files rev 164

Improve libtaz.sh doc and log function + add log to testsuite.sh
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 12 02:31:39 2012 +0200 (2012-05-12)
parents 1c9fc309b4ad
children 36f0fc63720c
files doc/libtaz.txt rootfs/lib/libtaz.sh testsuite.sh
line diff
     1.1 --- a/doc/libtaz.txt	Sat May 12 01:55:20 2012 +0200
     1.2 +++ b/doc/libtaz.txt	Sat May 12 02:31:39 2012 +0200
     1.3 @@ -6,20 +6,29 @@
     1.4  DESCRIPTION
     1.5  	LibTaz is the base SliTaz SHell library used by almost all tools and
     1.6  	utilities. It provide common SHell script functions, parse the cmdline
     1.7 -	options and store values in a variable. The output messages can be 
     1.8 +	options and store values in a variable. The output messages can be
     1.9  	formated for raw/text, gtk, html and by default they are formated for
    1.10  	a standard terminal supporting colors. LibTaz is in the directory
    1.11  	/lib/libtaz.sh since it is used when /usr may not be mounted.
    1.12 -	
    1.13 +
    1.14  FUNCTIONS
    1.15 -	status
    1.16 -	separator
    1.17 -	boldify [string]
    1.18 -	check_root
    1.19 +	status             Return command status [Done|Failed]
    1.20 +	separator          Display a line separator
    1.21 +	newline            Echo a new line if gettext or echo -n is used
    1.22 +	boldify [string]   Usae bold font for term, html or GTK output
    1.23 +	indent             Ident text in term mode
    1.24 +	check_root         Check if user is logged as root
    1.25 +	confirm            Read anser to confirm an action
    1.26 +	log [string]       Log activity, $activity must be set
    1.27  
    1.28  OPTIONS
    1.29  	--output=[raw|gtk|html]
    1.30 +	--activity=/path/files/activity
    1.31 +
    1.32 +EXAMPLES
    1.33 +	log "Message"
    1.34 +	check_root
    1.35  
    1.36  AUTHOR
    1.37  	Written by Christophe Lincoln
    1.38 -	
    1.39 +
     2.1 --- a/rootfs/lib/libtaz.sh	Sat May 12 01:55:20 2012 +0200
     2.2 +++ b/rootfs/lib/libtaz.sh	Sat May 12 02:31:39 2012 +0200
     2.3 @@ -68,6 +68,11 @@
     2.4  	done && echo ""
     2.5  }
     2.6  
     2.7 +# New line for echo -n or gettext.
     2.8 +newline() {
     2.9 +	echo ""
    2.10 +}
    2.11 +
    2.12  # Display a bold message. GTK Yad: Works only in --text=""
    2.13  boldify() {
    2.14  	case $output in
    2.15 @@ -113,16 +118,9 @@
    2.16  	[ "$answer" == "$(translate_query y)" ]
    2.17  }
    2.18  
    2.19 -# New line for echo -n or gettext.
    2.20 -newline() {
    2.21 -	echo ""
    2.22 -}
    2.23 -
    2.24 -# Log activities, we want first letter capitalized. $activity should be set
    2.25 -# by the script. The log format is suitable for web interfaces like cook.
    2.26 -# Usage: echo "Message" | log
    2.27 +# Log activities. $activity should be set by the script. The log format
    2.28 +# is suitable for web interfaces like cook. Usage: log "String"
    2.29  log() {
    2.30  	[ "$activity" ] || activity=/var/log/slitaz/libtaz.log
    2.31 -	grep ^[A-Z] | \
    2.32 -		sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
    2.33 +	echo "$(date '+%Y-%m-%d %H:%M') : $@" >> $activity
    2.34  }
     3.1 --- a/testsuite.sh	Sat May 12 01:55:20 2012 +0200
     3.2 +++ b/testsuite.sh	Sat May 12 02:31:39 2012 +0200
     3.3 @@ -5,18 +5,25 @@
     3.4  check_libtaz() {
     3.5  	echo -n "Checking libtaz.sh: status() 0"
     3.6  	status
     3.7 -	
     3.8 +
     3.9  	echo -n "Checking libtaz.sh: status() 1"
    3.10  	touch /tmp/1/2/2/4 2>/dev/null
    3.11  	status
    3.12 -	
    3.13 +
    3.14  	echo -n "Checking libtaz.sh: boldify() "
    3.15  	boldify "Message"
    3.16 -	
    3.17 +
    3.18  	echo "Checking libtaz.sh: separator"
    3.19  	separator
    3.20  }
    3.21  
    3.22 +echo -n "Checking libtaz.sh: log()"
    3.23 +activity=/tmp/testsuite.log
    3.24 +log "Message from SliTaz testsuite"
    3.25 +status
    3.26 +cat $activity
    3.27 +rm -f $activity
    3.28 +
    3.29  check_libtaz
    3.30  output="raw"
    3.31  check_libtaz