cookutils rev 751

cooker.cgi: show cook progress
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Sep 20 13:00:39 2015 +0200 (2015-09-20)
parents ff09ce1a0b9b
children ebd654564cf3
files cook lib/libcook.sh web/cooker.cgi
line diff
     1.1 --- a/cook	Tue Aug 25 11:59:58 2015 +0200
     1.2 +++ b/cook	Sun Sep 20 13:00:39 2015 +0200
     1.3 @@ -1676,6 +1676,8 @@
     1.4  		time=$(date +%s)
     1.5  		pkg="$1"
     1.6  		[ -z "$pkg" ] && usage
     1.7 +		lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
     1.8 +				$LOGS/$pkg.log 2> /dev/null)
     1.9  		receipt="$WOK/$pkg/receipt"
    1.10  		check_pkg_in_wok
    1.11  		newline
    1.12 @@ -1724,6 +1726,8 @@
    1.13  		# Log and source receipt.
    1.14  		_ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
    1.15  		echo "cook:$pkg" > $command
    1.16 +		[ "$lastcooktime" ] &&
    1.17 +		echo "cook:$pkg $lastcooktime $(date +%s)" > $cooktime
    1.18  
    1.19  		# Display and log info if cook process stopped.
    1.20  		# FIXME: gettext not working (in single quotes) here!
     2.1 --- a/lib/libcook.sh	Tue Aug 25 11:59:58 2015 +0200
     2.2 +++ b/lib/libcook.sh	Sun Sep 20 13:00:39 2015 +0200
     2.3 @@ -41,6 +41,7 @@
     2.4  broken="$cache/broken"
     2.5  wokrev="$cache/wokrev"
     2.6  cooknotes="$cache/cooknotes"
     2.7 +cooktime="$cache/cooktime"
     2.8  crontabs="/var/spool/cron/crontabs/root"
     2.9  
    2.10  
     3.1 --- a/web/cooker.cgi	Tue Aug 25 11:59:58 2015 +0200
     3.2 +++ b/web/cooker.cgi	Sun Sep 20 13:00:39 2015 +0200
     3.3 @@ -129,6 +129,22 @@
     3.4  }
     3.5  
     3.6  
     3.7 +# Show the running command and its progression
     3.8 +
     3.9 +running_command()
    3.10 +{
    3.11 +	local state="Not running"
    3.12 +	if [ -s "$command" ]; then
    3.13 +		state="$(cat $command)"
    3.14 +		if grep -q "^$state" $cooktime ; then
    3.15 +			set -- $(cat $cooktime)
    3.16 +			state="$state $((($(date +%s)-$3)*100/$2))%"
    3.17 +		fi
    3.18 +	fi
    3.19 +	echo $state
    3.20 +}
    3.21 +
    3.22 +
    3.23  # xHTML header. Pages can be customized with a separated html.header file.
    3.24  
    3.25  if [ -f "header.html" ]; then
    3.26 @@ -365,7 +381,7 @@
    3.27  <h2>Summary</h2>
    3.28  
    3.29  <pre>
    3.30 -Running command  : $([ -s "$command" ] && cat $command || echo "Not running")
    3.31 +Running command  : $(running_command)
    3.32  Wok revision     : <a href="$WOK_URL">$(cat $wokrev)</a>
    3.33  Commits to cook  : $(cat $commits | wc -l)
    3.34  Current cooklist : $(cat $cooklist | wc -l)