cookutils rev 881

modules/compressor: rework time display.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Feb 21 21:54:37 2017 +0200 (2017-02-21)
parents 9474bf43c080
children ab9148a85031
files modules/compressor
line diff
     1.1 --- a/modules/compressor	Sat Feb 18 15:02:59 2017 +0200
     1.2 +++ b/modules/compressor	Tue Feb 21 21:54:37 2017 +0200
     1.3 @@ -27,18 +27,22 @@
     1.4  #
     1.5  
     1.6  
     1.7 -# Display time.
     1.8 +# Working with time (with hundredths precision)
     1.9  
    1.10 -disp_time() {
    1.11 -	div=$(( ($1 + 30) / 60))
    1.12 -	case $div in
    1.13 -		0) min='';;
    1.14 -		# L10n: 'm' is for minutes (approximate time)
    1.15 -		*) min=$(_n ' ~ %dm' "$div");;
    1.16 -	esac
    1.17 +get_time() {
    1.18 +	cut -d" " -f2 /proc/uptime
    1.19 +}
    1.20  
    1.21 -	# L10n: 's' is for seconds (cooking time)
    1.22 -	_ '%ds%s' "$1" "$min"
    1.23 +calc_time() {
    1.24 +	# L10n: 's' is for seconds, 'm' is for minutes
    1.25 +	awk -va="$1" -vb="$(get_time)" -vs="$(_ 's')" -vm="$(_ 'm')" '
    1.26 +	BEGIN{
    1.27 +		time = b - a;
    1.28 +		if (time < 30)
    1.29 +			printf("%.2f%s\n", time, s);
    1.30 +		else
    1.31 +			printf("%.2f%s ~ %.0f%s\n", time, s, time / 60, m);
    1.32 +	}'
    1.33  }
    1.34  
    1.35  
    1.36 @@ -46,18 +50,16 @@
    1.37  
    1.38  comp_summary() {
    1.39  	# "$time0" "$size0" "$size1"
    1.40 -	time1=$(date +%s)
    1.41  	status
    1.42  	[ "$2" -eq 0 ] && return
    1.43 -	time=$(($time1 - $1))
    1.44 -	saving=$(( ($2 - $3) / 1024 ))
    1.45 +	saving=$(awk -va="$2" -vb="$3" 'BEGIN{ printf("%.0f\n", (a - b) / 1024) }')
    1.46  	cache_msg=''
    1.47  	if [ -s "$cache_stat" ]; then
    1.48  		cache_msg=$(_n ' Cache hit: %d/%d.' "$(fgrep '+' $cache_stat | wc -l)" "$(wc -l < $cache_stat)")
    1.49  		echo -n > $cache_stat
    1.50  	fi
    1.51  	_ '  Time: %s. Size: %s B -> %s B. Save: %s KB.%s' \
    1.52 -		"$(disp_time $time)" "$2" "$3" "$saving" "$cache_msg"
    1.53 +		"$(calc_time $1)" "$2" "$3" "$saving" "$cache_msg"
    1.54  }
    1.55  
    1.56  
    1.57 @@ -110,7 +112,7 @@
    1.58  # Compressing can be disabled with COOKOPTS="!manz"
    1.59  
    1.60  compress_manpages() {
    1.61 -	time0=$(date +%s)
    1.62 +	time0=$(get_time)
    1.63  	[ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
    1.64  	manpath="$install/usr/share/man"
    1.65  	[ -d "$manpath" ] || return
    1.66 @@ -151,7 +153,7 @@
    1.67  # Recompressing can be disabled with COOKOPTS="!gz"
    1.68  
    1.69  recompress_gz() {
    1.70 -	time0=$(date +%s)
    1.71 +	time0=$(get_time)
    1.72  	[ "${COOKOPTS/!gz/}" != "$COOKOPTS" ] && return
    1.73  	size0=$(sizes gz); [ -z "$size0" ] && return
    1.74  
    1.75 @@ -176,7 +178,7 @@
    1.76  # Compressing can be disabled with COOKOPTS="!pngz"
    1.77  
    1.78  compress_png() {
    1.79 -	time0=$(date +%s)
    1.80 +	time0=$(get_time)
    1.81  	[ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
    1.82  	size0=$(sizes png); [ -z "$size0" ] && return
    1.83  
    1.84 @@ -215,7 +217,7 @@
    1.85  # Compressing can be disabled with COOKOPTS="!svgz"
    1.86  
    1.87  compress_svg() {
    1.88 -	time0=$(date +%s)
    1.89 +	time0=$(get_time)
    1.90  	[ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
    1.91  	size0=$(sizes svg); [ -z "$size0" ] && return
    1.92  
    1.93 @@ -255,7 +257,7 @@
    1.94  	action 'Compressing ui files...'
    1.95  
    1.96  	size0=$(sizes xml)
    1.97 -	time0=$(date +%s)
    1.98 +	time0=$(get_time)
    1.99  	temp_ui="$(mktemp)"
   1.100  	IFS=$'\n'
   1.101  	for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
   1.102 @@ -302,7 +304,7 @@
   1.103  	[ -z "$(find $deskpath -type f -name '*.desktop')" ] && return
   1.104  
   1.105  	size0=$(sizes des)
   1.106 -	time0=$(date +%s)
   1.107 +	time0=$(get_time)
   1.108  
   1.109  	if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
   1.110  		tazpkg -gi desktop-file-utils-extra --quiet --cookmode
   1.111 @@ -362,7 +364,7 @@
   1.112  	action 'Normalizing mo files...'
   1.113  
   1.114  	size0=$(sizes mo1)
   1.115 -	time0=$(date +%s)
   1.116 +	time0=$(get_time)
   1.117  
   1.118  	# Process all existing *.mo files
   1.119  	IFS=$'\n'
   1.120 @@ -485,7 +487,7 @@
   1.121  
   1.122  	action 'Stripping locale definitions...'
   1.123  	size0=$(sizes loc)
   1.124 -	time0=$(date +%s)
   1.125 +	time0=$(get_time)
   1.126  
   1.127  	for i in $(find $install/usr/share/i18n/locales -type f); do
   1.128  		sed -i 's|	| |g; s|  *| |g; s|^ ||; /^%/d' $i
   1.129 @@ -510,7 +512,7 @@
   1.130  	action 'Executing strip on all files...'
   1.131  	size0=0
   1.132  	size1=0
   1.133 -	time0=$(date +%s)
   1.134 +	time0=$(get_time)
   1.135  
   1.136  	# Strip executable files
   1.137  	for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
   1.138 @@ -551,7 +553,7 @@
   1.139  
   1.140  	action 'Thin out translation files...'
   1.141  	size0=$(sizes mo2)
   1.142 -	time0=$(date +%s)
   1.143 +	time0=$(get_time)
   1.144  
   1.145  	# The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
   1.146  	# Default value is "" (empty). That means for us that we'll use the full