cookutils rev 5

Added: cooker.cgi web interface
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 03 22:32:00 2011 +0200 (2011-05-03)
parents eb9aa705b8ed
children 46fd01a7f6a1
files web/cooker.cgi web/style.css
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/web/cooker.cgi	Tue May 03 22:32:00 2011 +0200
     1.3 @@ -0,0 +1,141 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# SliTaz Cooker CGI/web interface.
     1.7 +#
     1.8 +echo "Content-Type: text/html"
     1.9 +echo ""
    1.10 +
    1.11 +[ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
    1.12 +[ -f "cook.conf" ] && . ./cook.conf
    1.13 +
    1.14 +# The same wok as cook.
    1.15 +wok="$WOK"
    1.16 +
    1.17 +# Cooker DB files.
    1.18 +activity="$CACHE/activity"
    1.19 +commits="$CACHE/commits"
    1.20 +cooklist="$CACHE/cooklist"
    1.21 +cookorder="$CACHE/cookorder"
    1.22 +status="$CACHE/status"
    1.23 +blocked="$CACHE/blocked"
    1.24 +broken="$CACHE/broken"
    1.25 +
    1.26 +#
    1.27 +# Functions
    1.28 +#
    1.29 +
    1.30 +# Put some colors in log and DB files.
    1.31 +syntax_highlighter() {
    1.32 +	sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
    1.33 +		-e 's#yes$#<span class="span-ok">yes</span>#g' \
    1.34 +		-e 's#no$#<span class="span-no">no</span>#g' \
    1.35 +		-e 's#error$#<span class="span-error">error</span>#g' \
    1.36 +		-e 's#ERROR:#<span class="span-error">ERROR</span>#g' \
    1.37 +		-e s"#^Executing:\([^']*\).#<span class='span-sky'>\0</span>#"g \
    1.38 +		-e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g
    1.39 +}
    1.40 +
    1.41 +# Latest build pkgs.
    1.42 +list_packages() {
    1.43 +	cd $PKGS
    1.44 +	ls -1t *.tazpkg | head -20 | \
    1.45 +	while read file
    1.46 +	do
    1.47 +		echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
    1.48 +		echo " : $file"
    1.49 +	done
    1.50 +}
    1.51 +
    1.52 +# xHTML header
    1.53 +cat << EOT
    1.54 +<!DOCTYPE html>
    1.55 +<html xmlns="http://www.w3.org/1999/xhtml">
    1.56 +<head>
    1.57 +	<title>SliTaz Cooker</title>
    1.58 +	<meta charset="utf-8" />
    1.59 +	<link rel="stylesheet" type="text/css" href="style.css" />
    1.60 +</head>
    1.61 +<body>
    1.62 +
    1.63 +<div id="header">
    1.64 +	<h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
    1.65 +</div>
    1.66 +
    1.67 +<!-- Content -->
    1.68 +<div id="content">
    1.69 +EOT
    1.70 +
    1.71 +#
    1.72 +# Load requested page
    1.73 +#
    1.74 +
    1.75 +case "${QUERY_STRING}" in
    1.76 +	log=*)
    1.77 +		pkg=${QUERY_STRING#log=}
    1.78 +		if [ -f "$LOGS/$pkg.log" ]; then
    1.79 +			echo '<pre>'
    1.80 +			if grep -q "cook:$pkg$" $status; then
    1.81 +				echo "$pkg currently cooking"
    1.82 +			fi
    1.83 +			grep -A 8 "Summary" $LOGS/$pkg.log | sed /^$/d | syntax_highlighter
    1.84 +			echo '</pre>'
    1.85 +			echo '<pre>'
    1.86 +			cat $LOGS/$pkg.log | syntax_highlighter
    1.87 +			echo '</pre>'
    1.88 +		else
    1.89 +			echo "<pre>No log file found for: $pkg</pre>"
    1.90 +		fi ;;
    1.91 +	*)
    1.92 +		cat << EOT
    1.93 +<div style="float: right;">
    1.94 +	<form method="get" action="$SCRIPT_NAME">
    1.95 +		Show log:
    1.96 +		<input type="text" name="log" />
    1.97 +	</form>
    1.98 +</div>
    1.99 +
   1.100 +<h2>Summary</h2>
   1.101 +<pre>
   1.102 +Cooked packages  : $(ls $PKGS/*.tazpkg | wc -l)
   1.103 +Packages in wok  : $(ls $WOK | wc -l)
   1.104 +Wok revision     : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
   1.105 +Commits to cook  : $(cat $commits | wc -l)
   1.106 +Broken packages  : $(cat $broken | wc -l)
   1.107 +</pre>
   1.108 +
   1.109 +<h2>Activity</h2>
   1.110 +<pre>
   1.111 +$(tac $CACHE/activity | sed s"#^\([^']* : \)#<span class='span-date'>\0</span>#"g)
   1.112 +</pre>
   1.113 +
   1.114 +<h2>Commits</h2>
   1.115 +<pre>
   1.116 +$(cat $commits)
   1.117 +</pre>
   1.118 +
   1.119 +<h2>Broken</h2>
   1.120 +<pre>
   1.121 +$(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
   1.122 +</pre>
   1.123 +
   1.124 +<h2>Latest cook</h2>
   1.125 +<pre>
   1.126 +$(list_packages | sed s"#^\([^']* \)#<span class='span-date'>\0</span>#"g)
   1.127 +</pre>
   1.128 +EOT
   1.129 +	;;
   1.130 +esac
   1.131 +
   1.132 +# Close xHTML page
   1.133 +cat << EOT
   1.134 +</div>
   1.135 +
   1.136 +<div id="footer">
   1.137 +	<a href="http://www.slitaz.org/">SliTaz Cooker</a>
   1.138 +</div>
   1.139 +
   1.140 +</body>
   1.141 +</html>
   1.142 +EOT
   1.143 +
   1.144 +exit 0
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/web/style.css	Tue May 03 22:32:00 2011 +0200
     2.3 @@ -0,0 +1,37 @@
     2.4 +/* CSS style for SliTaz Cooker */
     2.5 +
     2.6 +body { font: 96% sans-serif, vernada, arial; margin: 0; }
     2.7 +h1 { margin: 0; padding: 8px; color: #fff; font-size: 20px; }
     2.8 +h1 a { color: #fff; text-decoration: none; }
     2.9 +h2 { color: #444; } h3 { color: #666; font-size: 140%; }
    2.10 +a:hover { text-decoration: none; }
    2.11 +pre {
    2.12 +	background-color: #f8f8f8;
    2.13 +	border: 1px solid #ddd;
    2.14 +	padding: 10px;
    2.15 +	border-radius: 4px;
    2.16 +}
    2.17 +
    2.18 +#header {
    2.19 +	background: #351a0a;
    2.20 +	height: 40px;
    2.21 +	border-bottom: 8px solid #d66018;
    2.22 +}
    2.23 +
    2.24 +#content {
    2.25 +	margin: 40px 80px;
    2.26 +	text-align: justify;
    2.27 +}
    2.28 +
    2.29 +#footer {
    2.30 +	text-align: center;
    2.31 +	padding: 20px;
    2.32 +	border-top: 1px solid #ddd;
    2.33 +}
    2.34 +
    2.35 +.span-ok { color: green; }
    2.36 +.span-error { color: red; }
    2.37 +.span-sky { color: blue; }
    2.38 +.span-no { color: orange; }
    2.39 +.span-line { color: #888; }
    2.40 +.span-date { color: #666; font-size: 95%; }