cookutils view web/cooker.cgi @ 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 94ce2b5ad63a
children b6bbe55cd15e
line source
1 #!/bin/sh
2 #
3 # SliTaz Cooker CGI/web interface.
4 #
5 echo "Content-Type: text/html"
6 echo ""
8 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
9 [ -f "cook.conf" ] && . ./cook.conf
11 # The same wok as cook.
12 wok="$WOK"
14 # Cooker DB files.
15 activity="$CACHE/activity"
16 commits="$CACHE/commits"
17 cooklist="$CACHE/cooklist"
18 cookorder="$CACHE/cookorder"
19 command="$CACHE/command"
20 blocked="$CACHE/blocked"
21 broken="$CACHE/broken"
23 #
24 # Functions
25 #
27 # Put some colors in log and DB files.
28 syntax_highlighter() {
29 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
30 -e 's#yes$#<span class="span-ok">yes</span>#g' \
31 -e 's#no$#<span class="span-no">no</span>#g' \
32 -e 's#error$#<span class="span-error">error</span>#g' \
33 -e 's#ERROR:#<span class="span-error">ERROR</span>#g' \
34 -e s"#^Executing:\([^']*\).#<span class='span-sky'>\0</span>#"g \
35 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g
36 }
38 # Latest build pkgs.
39 list_packages() {
40 cd $PKGS
41 ls -1t *.tazpkg | head -20 | \
42 while read file
43 do
44 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
45 echo " : $file"
46 done
47 }
49 # xHTML header
50 cat << EOT
51 <!DOCTYPE html>
52 <html xmlns="http://www.w3.org/1999/xhtml">
53 <head>
54 <title>SliTaz Cooker</title>
55 <meta charset="utf-8" />
56 <link rel="stylesheet" type="text/css" href="style.css" />
57 </head>
58 <body>
60 <div id="header">
61 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
62 </div>
64 <!-- Content -->
65 <div id="content">
66 EOT
68 #
69 # Load requested page
70 #
72 case "${QUERY_STRING}" in
73 log=*)
74 pkg=${QUERY_STRING#log=}
75 if [ -f "$LOGS/$pkg.log" ]; then
76 echo "<h2>Log for: $pkg</h2>"
77 if [ "$pkg" == "commits" ]; then
78 echo '<pre>' && cat $LOGS/$pkg.log | syntax_highlighter
79 echo '</pre>' && exit 0
80 fi
81 echo '<pre>'
82 if grep -q "cook:$pkg$" $command; then
83 echo "$pkg currently cooking"
84 fi
85 grep -A 8 "Summary" $LOGS/$pkg.log | sed /^$/d | syntax_highlighter
86 echo '</pre>'
87 echo '<pre>'
88 cat $LOGS/$pkg.log | syntax_highlighter
89 echo '</pre>'
90 else
91 echo "<pre>No log file found for: $pkg</pre>"
92 fi ;;
93 *)
94 cat << EOT
95 <div style="float: right;">
96 <form method="get" action="$SCRIPT_NAME">
97 Show log:
98 <input type="text" name="log" />
99 </form>
100 </div>
102 <h2>Summary</h2>
103 <pre>
104 Cooked packages : $(ls $PKGS/*.tazpkg | wc -l)
105 Packages in wok : $(ls $WOK | wc -l)
106 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && hg head --template '{rev}\n')</a>
107 Commits to cook : $(cat $commits | wc -l)
108 Broken packages : $(cat $broken | wc -l)
109 </pre>
111 <div>
112 Latest logs: <a href="cooker.cgi?log=cookorder">cookorder</a>
113 <a href="cooker.cgi?log=commits">commits</a>
114 </div>
116 <h2>Activity</h2>
117 <pre>
118 $(tac $CACHE/activity | sed s"#^\([^']* : \)#<span class='span-date'>\0</span>#"g)
119 </pre>
121 <h2>Commits</h2>
122 <pre>
123 $(cat $commits)
124 </pre>
126 <h2>Broken</h2>
127 <pre>
128 $(cat $broken | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
129 </pre>
131 <h2>Bloked</h2>
132 <pre>
133 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?log=\0'>\0</a>#"g)
134 </pre>
136 <h2>Latest cook</h2>
137 <pre>
138 $(list_packages | sed s"#^\([^']* \)#<span class='span-date'>\0</span>#"g)
139 </pre>
140 EOT
141 ;;
142 esac
144 # Close xHTML page
145 cat << EOT
146 </div>
148 <div id="footer">
149 <a href="http://www.slitaz.org/">SliTaz Cooker</a>
150 </div>
152 </body>
153 </html>
154 EOT
156 exit 0