cookutils diff web/cooker.cgi @ rev 728

Move to using short i18n functions with "printf", so rewrite sources and po files. Fix: stripping before list files (python packages listed missed .pyc files). Also remove few hacks from code, make pot and msgmerge.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu May 07 15:11:47 2015 +0300 (2015-05-07)
parents 851a2b8075dc
children d15a44a622f6
line diff
     1.1 --- a/web/cooker.cgi	Fri Apr 17 14:10:59 2015 +0200
     1.2 +++ b/web/cooker.cgi	Thu May 07 15:11:47 2015 +0300
     1.3 @@ -23,7 +23,7 @@
     1.4  # We're not logged and want time zone to display correct server date.
     1.5  export TZ=$(cat /etc/TZ)
     1.6  
     1.7 -if [ "${QUERY_STRING%%=*}" == "download" ]; then
     1.8 +if [ "${QUERY_STRING%%=*}" == 'download' ]; then
     1.9  	file=$(busybox httpd -d "$PKGS/${QUERY_STRING#*=}")
    1.10  	cat <<EOT
    1.11  Content-Type: application/octet-stream
    1.12 @@ -36,17 +36,17 @@
    1.13  fi
    1.14  
    1.15  echo -n "Content-Type: "
    1.16 -if [ "$QUERY_STRING" == "rss" ]; then
    1.17 -	echo "application/rss+xml"
    1.18 +if [ "$QUERY_STRING" == 'rss' ]; then
    1.19 +	echo 'application/rss+xml'
    1.20  else
    1.21 -	echo "text/html; charset=utf-8"
    1.22 +	echo 'text/html; charset=utf-8'
    1.23  fi
    1.24 -echo ""
    1.25 +echo ''
    1.26  
    1.27  # RSS feed generator
    1.28 -if [ "$QUERY_STRING" == "rss" ]; then
    1.29 +if [ "$QUERY_STRING" == 'rss' ]; then
    1.30  	pubdate=$(date -R)
    1.31 -	cat << EOT
    1.32 +	cat <<EOT
    1.33  <?xml version="1.0" encoding="utf-8" ?>
    1.34  <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    1.35  <channel>
    1.36 @@ -57,22 +57,24 @@
    1.37  	<pubDate>$pubdate</pubDate>
    1.38  	<atom:link href="http://cook.slitaz.org/cooker.cgi?rss" rel="self" type="application/rss+xml" />
    1.39  EOT
    1.40 -	for rss in $(ls -lt $FEEDS/*.xml | head -n 12)
    1.41 -	do
    1.42 +	for rss in $(ls -lt $FEEDS/*.xml | head -n 12); do
    1.43  		cat $rss | sed 's|<guid|& isPermaLink="false"|g;s|</pubDate| GMT&|g'
    1.44  	done
    1.45 -	cat << EOT
    1.46 +	cat <<EOT
    1.47  </channel>
    1.48  </rss>
    1.49  EOT
    1.50  	exit 0
    1.51  fi
    1.52  
    1.53 +
    1.54  #
    1.55  # Functions
    1.56  #
    1.57  
    1.58 +
    1.59  # Put some colors in log and DB files.
    1.60 +
    1.61  syntax_highlighter() {
    1.62  	case $1 in
    1.63  		log)
    1.64 @@ -89,49 +91,57 @@
    1.65  				-e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
    1.66  				-e s"#ftp://[^ '\"]*#<a href='\0'>\0</a>#"g	\
    1.67  				-e s"#http://[^ '\"]*#<a href='\0'>\0</a>#"g ;;
    1.68 +
    1.69  		receipt)
    1.70  			sed	-e s'|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|'g \
    1.71  				-e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
    1.72  				-e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
    1.73 +
    1.74  		diff)
    1.75  			sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
    1.76  				-e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
    1.77  				-e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
    1.78  				-e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
    1.79 +
    1.80  		activity)
    1.81  			sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
    1.82  	esac
    1.83  }
    1.84  
    1.85 +
    1.86  # Latest build pkgs.
    1.87 +
    1.88  list_packages() {
    1.89  	cd $PKGS
    1.90  	ls -1t *.tazpkg | head -20 | \
    1.91 -	while read file
    1.92 -	do
    1.93 +	while read file; do
    1.94  		echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
    1.95  		echo " : $file"
    1.96  	done
    1.97  }
    1.98  
    1.99 +
   1.100  # Optional full list button
   1.101 +
   1.102  more_button() {
   1.103  	[ $(wc -l < ${3:-$CACHE/$1}) -gt ${4:-12} ] &&
   1.104  	echo "<a class=\"button\" href=\"cooker.cgi?file=$1\">$2</a>"
   1.105  }
   1.106  
   1.107 +
   1.108  # xHTML header. Pages can be customized with a separated html.header file.
   1.109 +
   1.110  if [ -f "header.html" ]; then
   1.111  	cat header.html
   1.112  else
   1.113 -	cat << EOT
   1.114 +	cat <<EOT
   1.115  <!DOCTYPE html>
   1.116 -<html xmlns="http://www.w3.org/1999/xhtml">
   1.117 +<html lang="en">
   1.118  <head>
   1.119 +	<meta charset="utf-8"/>
   1.120  	<title>SliTaz Cooker</title>
   1.121 -	<meta charset="utf-8" />
   1.122 -	<link rel="shortcut icon" href="favicon.ico" />
   1.123 -	<link rel="stylesheet" type="text/css" href="style.css" />
   1.124 +	<link rel="shortcut icon" href="favicon.ico"/>
   1.125 +	<link rel="stylesheet" type="text/css" href="style.css"/>
   1.126  </head>
   1.127  <body>
   1.128  
   1.129 @@ -145,6 +155,7 @@
   1.130  EOT
   1.131  fi
   1.132  
   1.133 +
   1.134  #
   1.135  # Load requested page
   1.136  #
   1.137 @@ -161,8 +172,10 @@
   1.138  			echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
   1.139  			unset WEB_SITE
   1.140  			. $wok/$pkg/receipt
   1.141 +
   1.142  			[ -n "$WEB_SITE" ] && # busybox wget -s $WEB_SITE &&
   1.143  			echo "<a href='$WEB_SITE'>home</a>"
   1.144 +
   1.145  			if [ -f "$wok/$pkg/taz/$PACKAGE-$VERSION/receipt" ]; then
   1.146  				echo "<a href='cooker.cgi?files=$pkg'>files</a>"
   1.147  				unset EXTRAVERSION
   1.148 @@ -208,28 +221,29 @@
   1.149  				echo "<pre>The Cooker is currently building: $pkg</pre>"
   1.150  			fi
   1.151  			if fgrep -q "Summary for:" $LOGS/$pkg.log; then
   1.152 -				echo "<h3>Cook summary</h3>"
   1.153 +				echo '<h3>Cook summary</h3>'
   1.154  				echo '<pre>'
   1.155  				grep -A 12 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
   1.156  					syntax_highlighter log
   1.157  				echo '</pre>'
   1.158  			fi
   1.159  			if fgrep -q "Debug information" $LOGS/$pkg.log; then
   1.160 -				echo "<h3>Cook failed</h3>"
   1.161 +				echo '<h3>Cook failed</h3>'
   1.162  				echo '<pre>'
   1.163  				grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
   1.164  						syntax_highlighter log
   1.165  				echo '</pre>'
   1.166  			fi
   1.167 -			echo "<h3>Cook log</h3>"
   1.168 +			echo '<h3>Cook log</h3>'
   1.169  			echo '<pre>'
   1.170  			cat $log | syntax_highlighter log
   1.171  			echo '</pre>'
   1.172  		else
   1.173  			[ "$pkg" ] && echo "<pre>No log: $pkg</pre>"
   1.174  		fi ;;
   1.175 +
   1.176  	file=*)
   1.177 -		# Dont allow all files on the system for security reasons.
   1.178 +		# Don't allow all files on the system for security reasons.
   1.179  		file=${QUERY_STRING#file=}
   1.180  		case "$file" in
   1.181  			activity|cooknotes|cooklist)
   1.182 @@ -239,6 +253,7 @@
   1.183  				echo '<pre>'
   1.184  				tac $CACHE/$file | syntax_highlighter activity
   1.185  				echo '</pre>' ;;
   1.186 +
   1.187  			broken)
   1.188  				nb=$(cat $broken | wc -l)
   1.189  				echo "<h2>DB: broken - Packages: $nb</h2>"
   1.190 @@ -246,6 +261,7 @@
   1.191  				cat $CACHE/$file | sort | \
   1.192  					sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
   1.193  				echo '</pre>' ;;
   1.194 +
   1.195  			*.diff)
   1.196  				diff=$CACHE/$file
   1.197  				echo "<h2>Diff for: ${file%.diff}</h2>"
   1.198 @@ -255,6 +271,7 @@
   1.199  				echo '<pre>'
   1.200  				cat $diff | syntax_highlighter diff
   1.201  				echo '</pre>' ;;
   1.202 +
   1.203  			*.log)
   1.204  				log=$LOGS/$file
   1.205  				name=$(basename $log)
   1.206 @@ -273,12 +290,14 @@
   1.207  					echo "<pre>No log file: $log</pre>"
   1.208  				fi ;;
   1.209  		esac ;;
   1.210 +
   1.211  	stuff=*)
   1.212  		file=${QUERY_STRING#stuff=}
   1.213  		echo "<h2>$file</h2>"
   1.214  		echo '<pre>'
   1.215  		cat $wok/$file | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
   1.216  		echo '</pre>' ;;
   1.217 +
   1.218  	receipt=*)
   1.219  		pkg=${QUERY_STRING#receipt=}
   1.220  		echo "<h2>Receipt for: $pkg</h2>"
   1.221 @@ -294,6 +313,7 @@
   1.222  		else
   1.223  			echo "<pre>No receipt for: $pkg</pre>"
   1.224  		fi ;;
   1.225 +
   1.226  	files=*)
   1.227  		pkg=${QUERY_STRING#files=}
   1.228  		dir=$(ls -d $WOK/$pkg/taz/$pkg-*)
   1.229 @@ -306,6 +326,7 @@
   1.230  		else
   1.231  			echo "<pre>No files list for: $pkg</pre>"
   1.232  		fi ;;
   1.233 +
   1.234  	description=*)
   1.235  		pkg=${QUERY_STRING#description=}
   1.236  		echo "<h2>Description of $pkg</h2>"
   1.237 @@ -318,6 +339,7 @@
   1.238  		else
   1.239  			echo "<pre>No description for: $pkg</pre>"
   1.240  		fi ;;
   1.241 +
   1.242  	*)
   1.243  		# We may have a toolchain.cgi script for cross cooker's
   1.244  		if [ -f "toolchain.cgi" ]; then
   1.245 @@ -332,7 +354,7 @@
   1.246  		unbuilt=$(($inwok - $cooked))
   1.247  		pct=0
   1.248  		[ $inwok -gt 0 ] && pct=$(( ($cooked * 100) / $inwok ))
   1.249 -		cat << EOT
   1.250 +		cat <<EOT
   1.251  <div style="float: right;">
   1.252  	<form method="get" action="$SCRIPT_NAME">
   1.253  		Package:
   1.254 @@ -352,8 +374,8 @@
   1.255  </pre>
   1.256  
   1.257  <p class="info">
   1.258 -	Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt -
   1.259 -	Server date: $(date -u '+%Y-%m-%d %H:%M %Z')
   1.260 +	Packages: $inwok in the wok | $cooked cooked | $unbuilt unbuilt |
   1.261 +	Server date: $(date -u '+%F %R %Z')
   1.262  </p>
   1.263  <div class="pctbar">
   1.264  	<div class="pct" style="width: ${pct}%;">${pct}%</div>
   1.265 @@ -368,48 +390,48 @@
   1.266  	<a href="$toolchain">toolchain</a>
   1.267  </p>
   1.268  
   1.269 -<a name="activity"></a>
   1.270 -<h2>Activity</h2>
   1.271 +
   1.272 +<h2 id="activity">Activity</h2>
   1.273  <pre>
   1.274  $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
   1.275  </pre>
   1.276  $(more_button activity "More activity" $CACHE/activity 12)
   1.277  
   1.278 -<a name="cooknotes"></a>
   1.279 -<h2>Cooknotes</h2>
   1.280 +
   1.281 +<h2 id="cooknotes">Cooknotes</h2>
   1.282  <pre>
   1.283  $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
   1.284  </pre>
   1.285  $(more_button cooknotes "More notes" $cooknotes 12)
   1.286  
   1.287 -<a name="commits"></a>
   1.288 -<h2>Commits</h2>
   1.289 +
   1.290 +<h2 id="commits">Commits</h2>
   1.291  <pre>
   1.292  $(cat $commits)
   1.293  </pre>
   1.294  
   1.295 -<a name="cooklist"></a>
   1.296 -<h2>Cooklist</h2>
   1.297 +
   1.298 +<h2 id="cooklist">Cooklist</h2>
   1.299  <pre>
   1.300  $(cat $cooklist | head -n 20)
   1.301  </pre>
   1.302  $(more_button cooklist "Full cooklist" $cooklist 20)
   1.303  
   1.304 -<a name="broken"></a>
   1.305 -<h2>Broken</h2>
   1.306 +
   1.307 +<h2 id="broken">Broken</h2>
   1.308  <pre>
   1.309  $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
   1.310  </pre>
   1.311  $(more_button broken "All broken packages" $broken 20)
   1.312  
   1.313 -<a name="blocked"></a>
   1.314 -<h2>Blocked</h2>
   1.315 +
   1.316 +<h2 id="blocked">Blocked</h2>
   1.317  <pre>
   1.318  $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
   1.319  </pre>
   1.320  
   1.321 -<a name="lastcook"></a>
   1.322 -<h2>Latest cook</h2>
   1.323 +
   1.324 +<h2 id="lastcook">Latest cook</h2>
   1.325  <pre>
   1.326  $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
   1.327  </pre>
   1.328 @@ -417,8 +439,10 @@
   1.329  	;;
   1.330  esac
   1.331  
   1.332 +
   1.333  # Close xHTML page
   1.334 -cat << EOT
   1.335 +
   1.336 +cat <<EOT
   1.337  </div>
   1.338  
   1.339  <div id="footer">