cookutils rev 14

Better CGI interface and a bunch a small improvment
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 05 03:12:10 2011 +0200 (2011-05-05)
parents fa9a36a8c1f4
children b6bbe55cd15e
files cooker web/cooker.cgi
line diff
     1.1 --- a/cooker	Thu May 05 00:06:01 2011 +0200
     1.2 +++ b/cooker	Thu May 05 03:12:10 2011 +0200
     1.3 @@ -18,7 +18,7 @@
     1.4  commits="$CACHE/commits"
     1.5  cooklist="$CACHE/cooklist"
     1.6  cookorder="$CACHE/cookorder"
     1.7 -status="$CACHE/status"
     1.8 +command="$CACHE/command"
     1.9  blocked="$CACHE/blocked"
    1.10  broken="$CACHE/broken"
    1.11  
    1.12 @@ -56,18 +56,29 @@
    1.13  		sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
    1.14  }
    1.15  
    1.16 +# Some message goes in activity but log verbose output when checking for commits
    1.17 +# into a log file.
    1.18 +log_commits() {
    1.19 +	tee -a $LOGS/commits.log
    1.20 +}
    1.21 +
    1.22  # Log broken packages
    1.23  broken() {
    1.24  	echo "$pkg" >> $broken
    1.25  }
    1.26  
    1.27 +# Clean up after cook sucess.
    1.28 +clean_status() {
    1.29 +	rm -f $command && touch $command
    1.30 +}
    1.31 +
    1.32  # Scan packages deps an fill up cookorder list.
    1.33  cook_order_scan() {
    1.34  	touch $cooklist $cookorder
    1.35  	for pkg in $(cat $cooklist)
    1.36  	do
    1.37  		unset DEPENDS BUILD_DEPENDS
    1.38 -		. $WOK/$pkg/receipt
    1.39 +		. $wok/$pkg/receipt
    1.40  		for dep in $DEPENDS $BUILD_DEPENDS
    1.41  		do
    1.42  			if grep -q "^$dep$" $cooklist; then
    1.43 @@ -125,7 +136,7 @@
    1.44  	for pkg in $(cat $cooklist)
    1.45  	do
    1.46  		unset WANTED
    1.47 -		. $WOK/$pkg/receipt
    1.48 +		. $wok/$pkg/receipt
    1.49  		if [ "$WANTED" ]; then
    1.50  			echo "$pkg: $WANTED"
    1.51  			sed -i -e "/^$pkg$/"d  \
    1.52 @@ -150,19 +161,39 @@
    1.53  	separator && echo ""
    1.54  }
    1.55  
    1.56 +# Remove blocked (faster this way than grepping before).
    1.57 +strip_blocked() {
    1.58 +	for pkg in $(cat $blocked)
    1.59 +	do
    1.60 +		sed -i /^${pkg}$/d $cooklist
    1.61 +	done && sed -i /^$/d $cooklist
    1.62 +}
    1.63 +
    1.64  # Uses in default mode and with all cmd.
    1.65  cook_commits() {
    1.66  	if [ -s "$commits" ]; then
    1.67  		for pkg in $(cat $commits)
    1.68  		do
    1.69  			echo "Cook started for: <a href='cooker.cgi?log=$pkg'>$pkg</a>" | log
    1.70 -			echo "cook:$pkg" > $status
    1.71 +			echo "cook:$pkg" > $command
    1.72  			cook $pkg || broken
    1.73  			sed -i /^${pkg}$/d $commits
    1.74  		done
    1.75  	fi
    1.76  }
    1.77  
    1.78 +# Cook all package in a cooklist.
    1.79 +cook_list() {
    1.80 +	for pkg in $(cat $cooklist)
    1.81 +	do
    1.82 +		if [ ! -d "$wok/$pkg/install" ]; then
    1.83 +			echo "Cook started for: <a href='cooker.cgi?log=$pkg'>$pkg</a>" | log
    1.84 +			cook $pkg || broken
    1.85 +			sed -i /^${pkg}$/d $cooklist
    1.86 +		fi
    1.87 +	done
    1.88 +}
    1.89 +
    1.90  #
    1.91  # Commands
    1.92  #
    1.93 @@ -186,17 +217,20 @@
    1.94  		# Directories and files
    1.95  		echo "mkdir's and touch files in: $SLITAZ"
    1.96  		mkdir -p $PKGS $LOGS $CACHE $SRC
    1.97 -		for f in $activity $blocked $broken $commits $cooklist $status
    1.98 +		for f in $activity $blocked $broken $commits $cooklist $command
    1.99  		do
   1.100  			touch $f
   1.101  		done
   1.102 -		hg clone $WOK_URL ${wok}-hg
   1.103 +		hg clone $WOK_URL ${wok}-hg || exit 1
   1.104  		hg clone $FLAVORS_URL flavors
   1.105  		cp -a ${wok}-hg $wok
   1.106  		separator && echo "" ;;
   1.107  	--reverse=*)
   1.108  		# Cook all reverse dependencies for a packages. This command let us
   1.109  		# control the Cooker manually for commit that will cook a lot of packages.
   1.110 +		#
   1.111 +		# Use hg commit ? Ex: hg commit -m "Message bla bla | cooker:--reverse"
   1.112 +		#
   1.113  		pkg=${1#--reverse=}
   1.114  		[ ! -d "$wok/$pkg" ] && echo "No package $2 found." && exit 0
   1.115  		cd $wok
   1.116 @@ -209,28 +243,27 @@
   1.117  	--pkg=*)
   1.118  		# Same as 'cook pkg' but with log for web interface.
   1.119  		pkg=${1#--pkg=}
   1.120 +		echo "cooker:$1" > $command
   1.121  		echo "Cook started for: <a href='cooker.cgi?log=$pkg'>$pkg</a>" | log
   1.122  		cook $pkg || broken ;;
   1.123  	--cat=*)
   1.124  		# Cook all packages of a category.
   1.125 -		rm -f $cooklist && touch $cooklist
   1.126 -		cat=${1#--cat=} && cd $WOK
   1.127 +		cat=${1#--cat=}
   1.128 +		echo "cooker:$1" > $command
   1.129 +		rm -f $cooklist && touch $cooklist && cd $wok
   1.130  		for pkg in *
   1.131  		do
   1.132  			unset CATEGORY && . $pkg/receipt
   1.133  			[ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist
   1.134  		done
   1.135 -		cook_order | tee $LOGS/cooker-order.log
   1.136 -		for pkg in $(cat $cooklist)
   1.137 -		do
   1.138 -			echo "Cook started for: <a href='cooker.cgi?log=$pkg'>$pkg</a>" | log
   1.139 -			cook $pkg || broken
   1.140 -		done
   1.141 -		;;
   1.142 +		strip_blocked
   1.143 +		cook_order | tee $LOGS/cookorder.log
   1.144 +		cook_list
   1.145 +		clean_status ;;
   1.146  	--all)
   1.147  		# Try to build all unbuilt packages except blocked's.
   1.148 +		echo "cooker:--all" > $command
   1.149  		rm -f $cooklist && touch $cooklist
   1.150 -		
   1.151  		echo "" && cd $wok
   1.152  		echo "Cooker cooklist"
   1.153  		separator
   1.154 @@ -244,54 +277,47 @@
   1.155  				echo $pkg >> $cooklist
   1.156  		done
   1.157  
   1.158 -		# Remove blocked (faster this way than grepping before).
   1.159 -		for pkg in $(cat $blocked)
   1.160 -		do
   1.161 -			sed -i /^${pkg}$/d $cooklist
   1.162 -		done && sed -i /^$/d $cooklist
   1.163 -
   1.164 -		echo "Packages to cook: $(cat $cooklist | wc -l)"
   1.165 +		strip_blocked
   1.166  		echo "Packages to cook: $(cat $cooklist | wc -l)" | log
   1.167 -		cook_order | tee $LOGS/cooker-order.log
   1.168 -
   1.169 -		# Clean DB files
   1.170 -		echo "Cleaning cached DB files" | log
   1.171 -		#sed /^$/ $cooklist > $cooklist.tmp
   1.172 -		#uniq $cooklist.tmp > $cooklist && rm -f $cooklist.tmp
   1.173 -		#echo "Cooklist: $(cat $cooklist | wc -l)"
   1.174 -		echo "" ;;
   1.175 +		cook_order | tee $LOGS/cookorder.log
   1.176 +		cook_list
   1.177 +		clean_status ;;
   1.178  	*)
   1.179  		# Default is to cook all commits.
   1.180  		[ "$1" ] && usage
   1.181  		cooklist=$CACHE/commits
   1.182 -		echo -e "\nChecking for commits"
   1.183 -		separator
   1.184 +		rm -f $LOGS/commits.log
   1.185 +		echo ""
   1.186 +		echo "Checking for commits" | log_commits
   1.187 +		separator | tee -a $LOGS/commits.log
   1.188  		
   1.189  		# Get revisions.
   1.190 -		cd $wok || ( echo "" && exit 1 )
   1.191 +		cd $wok || ( echo "No wok found: $wok" && exit 1 )
   1.192  		cur=$(hg head --template '{rev}\n')
   1.193  		echo "Updating Hg wok: ${wok}-hg" | log
   1.194 -		echo "hg:pull" > $status
   1.195 -		cd ${wok}-hg && hg pull -u
   1.196 +		echo "hg:pull" > $command
   1.197 +		cd ${wok}-hg && hg pull -u | log_commits
   1.198  		new=$(hg head --template '{rev}\n')
   1.199 -		echo "Hg wok revision : $cur"
   1.200 -		echo "Pulled revision : $new"
   1.201 -	
   1.202 +		echo "Hg wok revision : $cur" | log_commits
   1.203 +		echo "Pulled revision : $new" | log_commits
   1.204 +		
   1.205  		# Sync build wok with rsync so we dont take care about removing old
   1.206  		# files as before.
   1.207  		if [ "$new" -gt "$cur" ]; then
   1.208  			echo "Changes found from: $cur to $new" | log
   1.209 -			echo "Syncing build work with Hg wok..."
   1.210 -			cp -a ${wok}-hg/* $wok
   1.211 -			cp -a ${wok}-hg/.hg $wok
   1.212 +			echo "Syncing build wok with Hg wok..."
   1.213 +			#cp -a ${wok}-hg/* $wok
   1.214 +			#cp -a ${wok}-hg/.hg $wok
   1.215 +			rsync -r -t -c -l -u -D -E --delete ${wok}-hg/ $wok/ | log_commits
   1.216  		else
   1.217  			echo "No revision changes: $cur vs $new" | log
   1.218 -			separator && echo "" && exit 0
   1.219 +			separator | log_commits
   1.220 +			clean_status && echo "" && exit 0
   1.221  		fi
   1.222  		
   1.223  		# Get modifications
   1.224  		cd ${wok}-hg
   1.225 -		cur=$(($cur+1))
   1.226 +		cur=$(($cur + 1))
   1.227  		msg="from revision $cur to $new"
   1.228  		[ "$new" == "$cur" ] && msg="revision: $new"
   1.229  		echo -e "Will cook $msg\n"
   1.230 @@ -299,6 +325,7 @@
   1.231  		for rev in $(seq $cur $new); do
   1.232  			log=$(hg log --rev=$rev --template "{files}\n" | cut -d "/" -f 1)
   1.233  			for file in $log; do
   1.234 +				echo "Commited file: $file" log_commits
   1.235  				echo $file >> $commits.tmp
   1.236  			done
   1.237  		done
   1.238 @@ -306,10 +333,12 @@
   1.239  		# Keep previews commit and discard duplicate lines
   1.240  		cat $commits $commits.tmp | sed /"^$"/d > $commits.new
   1.241  		uniq $commits.new > $commits && rm $commits.*
   1.242 -		echo "Packages to cook: $(cat $commits | wc -l)"
   1.243 -		cook_order | tee $LOGS/cooker-order.log
   1.244 +		echo "Packages to cook: $(cat $commits | wc -l)" | log
   1.245 +		separator && echo "" | log_commits
   1.246 +		strip_blocked
   1.247 +		cook_order | tee $LOGS/cookorder.log
   1.248  		cook_commits
   1.249 -		echo "" > $status ;;
   1.250 +		clean_status ;;
   1.251  esac
   1.252  
   1.253  exit 0
     2.1 --- a/web/cooker.cgi	Thu May 05 00:06:01 2011 +0200
     2.2 +++ b/web/cooker.cgi	Thu May 05 03:12:10 2011 +0200
     2.3 @@ -16,7 +16,7 @@
     2.4  commits="$CACHE/commits"
     2.5  cooklist="$CACHE/cooklist"
     2.6  cookorder="$CACHE/cookorder"
     2.7 -status="$CACHE/status"
     2.8 +command="$CACHE/command"
     2.9  blocked="$CACHE/blocked"
    2.10  broken="$CACHE/broken"
    2.11  
    2.12 @@ -73,8 +73,13 @@
    2.13  	log=*)
    2.14  		pkg=${QUERY_STRING#log=}
    2.15  		if [ -f "$LOGS/$pkg.log" ]; then
    2.16 +			echo "<h2>Log for: $pkg</h2>"
    2.17 +			if [ "$pkg" == "commits" ]; then
    2.18 +				echo '<pre>' && cat $LOGS/$pkg.log | syntax_highlighter
    2.19 +				echo '</pre>' && exit 0
    2.20 +			fi
    2.21  			echo '<pre>'
    2.22 -			if grep -q "cook:$pkg$" $status; then
    2.23 +			if grep -q "cook:$pkg$" $command; then
    2.24  				echo "$pkg currently cooking"
    2.25  			fi
    2.26  			grep -A 8 "Summary" $LOGS/$pkg.log | sed /^$/d | syntax_highlighter
    2.27 @@ -103,6 +108,11 @@
    2.28  Broken packages  : $(cat $broken | wc -l)
    2.29  </pre>
    2.30  
    2.31 +<div>
    2.32 +Latest logs: <a href="cooker.cgi?log=cookorder">cookorder</a>
    2.33 +<a href="cooker.cgi?log=commits">commits</a>
    2.34 +</div>
    2.35 +
    2.36  <h2>Activity</h2>
    2.37  <pre>
    2.38  $(tac $CACHE/activity | sed s"#^\([^']* : \)#<span class='span-date'>\0</span>#"g)
    2.39 @@ -118,6 +128,11 @@
    2.40  $(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
    2.41  </pre>
    2.42  
    2.43 +<h2>Bloked</h2>
    2.44 +<pre>
    2.45 +$(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
    2.46 +</pre>
    2.47 +
    2.48  <h2>Latest cook</h2>
    2.49  <pre>
    2.50  $(list_packages | sed s"#^\([^']* \)#<span class='span-date'>\0</span>#"g)