cookutils view web/cooker.cgi @ rev 123

web: add color to WARNING in logs
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 10 02:03:23 2011 +0200 (2011-05-10)
parents 47705cb85d12
children 7704053dce6e
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"
22 cooknotes="$CACHE/cooknotes"
24 #
25 # Functions
26 #
28 # Put some colors in log and DB files.
29 syntax_highlighter() {
30 case $1 in
31 log)
32 sed -e 's#OK$#<span class="span-ok">OK</span>#g' \
33 -e 's#yes$#<span class="span-ok">yes</span>#g' \
34 -e 's#no$#<span class="span-no">no</span>#g' \
35 -e 's#error$#<span class="span-error">error</span>#g' \
36 -e 's#ERROR:#<span class="span-error">ERROR:</span>#g' \
37 -e 's#WARNING:#<span class="span-error">WARNING:</span>#g' \
38 -e s"#^Executing:\([^']*\).#<span class='sh-val'>\0</span>#"g \
39 -e s"#^====\([^']*\).#<span class='span-line'>\0</span>#"g \
40 -e s"#^[a-zA-Z0-9]\([^']*\) :: #<span class='span-sky'>\0</span>#"g \
41 -e s"#ftp://\([^']*\).*#<a href='\0'>\0</a>#"g \
42 -e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g ;;
43 receipt)
44 sed -e s"#^\#\([^']*\)#<span class='sh-comment'>\0</span>#"g \
45 -e s"#\"\([^']*\)\"#<span class='sh-val'>\0</span>#"g ;;
46 esac
47 }
49 # Latest build pkgs.
50 list_packages() {
51 cd $PKGS
52 ls -1t *.tazpkg | head -20 | \
53 while read file
54 do
55 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
56 echo " : $file"
57 done
58 }
60 # xHTML header
61 cat << EOT
62 <!DOCTYPE html>
63 <html xmlns="http://www.w3.org/1999/xhtml">
64 <head>
65 <title>SliTaz Cooker</title>
66 <meta charset="utf-8" />
67 <link rel="stylesheet" type="text/css" href="style.css" />
68 </head>
69 <body>
71 <div id="header">
72 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
73 </div>
75 <!-- Content -->
76 <div id="content">
77 EOT
79 #
80 # Load requested page
81 #
83 case "${QUERY_STRING}" in
84 pkg=*)
85 pkg=${QUERY_STRING#pkg=}
86 log=$LOGS/$pkg.log
87 echo "<h2>Package: $pkg</h2>"
89 # Package info.
90 echo '<div id="info">'
91 if [ -f "$wok/$pkg/receipt" ]; then
92 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
93 else
94 echo "No package named: $pkg"
95 fi
96 echo '</div>'
98 # Check for a log file and display summary if it exists.
99 if [ -f "$log" ]; then
100 if grep -q "cook:$pkg$" $command; then
101 echo "<pre>The Cooker is currently building: $pkg</pre>"
102 fi
103 if fgrep -q "Summary " $LOGS/$pkg.log; then
104 echo "<h3>Cook summary</h3>"
105 echo '<pre>'
106 grep -A 8 "^Summary " $LOGS/$pkg.log | sed /^$/d | \
107 syntax_highlighter log
108 echo '</pre>'
109 fi
110 if fgrep -q "Debug " $LOGS/$pkg.log; then
111 echo "<h3>Cook failed</h3>"
112 echo '<pre>'
113 grep -A 8 "^Debug " $LOGS/$pkg.log | sed /^$/d | \
114 syntax_highlighter log
115 echo '</pre>'
116 fi
117 echo "<h3>Cook log</h3>"
118 echo '<pre>'
119 cat $log | syntax_highlighter log
120 echo '</pre>'
121 else
122 echo "<pre>No log: $pkg</pre>"
123 fi ;;
124 file=*)
125 # Dont allow all files on the system for security reasons.
126 file=${QUERY_STRING#file=}
127 case "$file" in
128 activity|cooknotes|cooklist)
129 [ "$file" == "cooklist" ] && \
130 nb="- Packages: $(cat $cooklist | wc -l)"
131 echo "<h2>DB: $file $nb</h2>"
132 echo '<pre>'
133 tac $CACHE/$file | \
134 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g
135 echo '</pre>' ;;
136 broken)
137 nb=$(cat $broken | wc -l)
138 echo "<h2>DB: broken - Packages: $nb</h2>"
139 echo '<pre>'
140 tac $CACHE/$file | \
141 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
142 echo '</pre>' ;;
143 *.log)
144 log=$LOGS/$file
145 name=$(basename $log)
146 echo "<h2>Log for: ${name%.log}</h2>"
147 if [ -f "$log" ]; then
148 if fgrep -q "Summary" $log; then
149 echo '<pre>'
150 grep -A 20 "^Summary" $log | sed /^$/d | \
151 syntax_highlighter log
152 echo '</pre>'
153 fi
154 echo '<pre>'
155 cat $log | syntax_highlighter log
156 echo '</pre>'
157 else
158 echo "<pre>No log file: $log</pre>"
159 fi ;;
160 esac ;;
161 receipt=*)
162 pkg=${QUERY_STRING#receipt=}
163 echo "<h2>Receipt for: $pkg</h2>"
164 if [ -f "$wok/$pkg/receipt" ]; then
165 echo '<pre>'
166 cat $wok/$pkg/receipt | syntax_highlighter receipt
167 echo '</pre>'
168 else
169 echo "<pre>No receipt for: $log</pre>"
170 fi ;;
171 *)
172 # Main page with summary.
173 inwok=$(ls $WOK | wc -l)
174 cooked=$(ls $PKGS/*.tazpkg | wc -l)
175 unbuilt=$(($inwok - $cooked))
176 [ "$cooked" -gt 0 ] && div=$(($inwok / 100))
177 [ "$div" -gt 0 ] && pct=$(($cooked / $div))
178 [ "$div" == 0 ] && pct=0
179 cat << EOT
180 <div style="float: right;">
181 <form method="get" action="$SCRIPT_NAME">
182 Package:
183 <input type="text" name="pkg" />
184 </form>
185 </div>
187 <h2>Summary</h2>
189 <pre>
190 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
191 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && \
192 hg head --template '{rev}\n' || echo "No Hg wok")</a>
193 Commits to cook : $(cat $commits | wc -l)
194 Current cooklist : $(cat $cooklist | wc -l)
195 Broken packages : $(cat $broken | wc -l)
196 Blocked packages : $(cat $blocked | wc -l)
197 </pre>
199 <p>
200 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt
201 </p>
202 <div class="pctbar">
203 <div class="pct" style="width: ${pct}%;">${pct}%</div>
204 </div>
206 <p>
207 Latest logs:
208 <a href="cooker.cgi?file=cookorder.log">cookorder</a>
209 <a href="cooker.cgi?file=commits.log">commits</a>
210 </p>
212 <h2>Activity</h2>
213 <pre>
214 $(tac $CACHE/activity | head -n 12 | \
215 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
216 </pre>
217 <a class="button" href="cooker.cgi?file=activity">More activity</a>
219 <h2>Cooknotes</h2>
220 <pre>
221 $(tac $cooknotes | head -n 12 | \
222 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g)
223 </pre>
224 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
226 <h2>Commits</h2>
227 <pre>
228 $(cat $commits)
229 </pre>
231 <h2>Cooklist</h2>
232 <pre>
233 $(cat $cooklist | head -n 20)
234 </pre>
235 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
237 <h2>Broken</h2>
238 <pre>
239 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
240 </pre>
241 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
243 <h2>Blocked</h2>
244 <pre>
245 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
246 </pre>
248 <h2>Latest cook</h2>
249 <pre>
250 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
251 </pre>
252 EOT
253 ;;
254 esac
256 # Close xHTML page
257 cat << EOT
258 </div>
260 <div id="footer">
261 <a href="http://www.slitaz.org/">SliTaz Website</a>
262 <a href="cooker.cgi">Cooker</a>
263 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
264 Documentation</a>
265 </div>
267 </body>
268 </html>
269 EOT
271 exit 0