cookutils view web/cooker.cgi @ rev 149

web: make sure we display pkg summary or debug info
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 12 11:25:13 2011 +0200 (2011-05-12)
parents a7dfa7d95891
children cd039ff446c4
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-red">error</span>#g' \
36 -e 's#ERROR:#<span class="span-red">ERROR:</span>#g' \
37 -e 's#WARNING:#<span class="span-red">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 diff)
47 sed -e 's|&|\&amp;|g' -e 's|<|\&lt;|g' -e 's|>|\&gt;|g' \
48 -e s"#^-\([^']*\).#<span class='span-red'>\0</span>#"g \
49 -e s"#^+\([^']*\).#<span class='span-ok'>\0</span>#"g \
50 -e s"#@@\([^']*\)@@#<span class='span-sky'>@@\1@@</span>#"g ;;
51 activity)
52 sed s"#^\([^']* : \)#<span class='log-date'>\0</span>#"g ;;
53 esac
54 }
56 # Latest build pkgs.
57 list_packages() {
58 cd $PKGS
59 ls -1t *.tazpkg | head -20 | \
60 while read file
61 do
62 echo -n $(stat -c '%y' $PKGS/$file | cut -d . -f 1 | sed s/:[0-9]*$//)
63 echo " : $file"
64 done
65 }
67 # xHTML header
68 cat << EOT
69 <!DOCTYPE html>
70 <html xmlns="http://www.w3.org/1999/xhtml">
71 <head>
72 <title>SliTaz Cooker</title>
73 <meta charset="utf-8" />
74 <link rel="stylesheet" type="text/css" href="style.css" />
75 </head>
76 <body>
78 <div id="header">
79 <h1><a href="cooker.cgi">SliTaz Cooker</a></h1>
80 </div>
82 <!-- Content -->
83 <div id="content">
84 EOT
86 #
87 # Load requested page
88 #
90 case "${QUERY_STRING}" in
91 pkg=*)
92 pkg=${QUERY_STRING#pkg=}
93 log=$LOGS/$pkg.log
94 echo "<h2>Package: $pkg</h2>"
96 # Package info.
97 echo '<div id="info">'
98 if [ -f "$wok/$pkg/receipt" ]; then
99 echo "<a href='cooker.cgi?receipt=$pkg'>receipt</a>"
100 else
101 echo "No package named: $pkg"
102 fi
103 echo '</div>'
105 # Check for a log file and display summary if it exists.
106 if [ -f "$log" ]; then
107 if grep -q "cook:$pkg$" $command; then
108 echo "<pre>The Cooker is currently building: $pkg</pre>"
109 fi
110 if fgrep -q "Summary for:" $LOGS/$pkg.log; then
111 echo "<h3>Cook summary</h3>"
112 echo '<pre>'
113 grep -A 8 "^Summary for:" $LOGS/$pkg.log | sed /^$/d | \
114 syntax_highlighter log
115 echo '</pre>'
116 fi
117 if fgrep -q "Debug information" $LOGS/$pkg.log; then
118 echo "<h3>Cook failed</h3>"
119 echo '<pre>'
120 grep -A 8 "^Debug information" $LOGS/$pkg.log | sed /^$/d | \
121 syntax_highlighter log
122 echo '</pre>'
123 fi
124 echo "<h3>Cook log</h3>"
125 echo '<pre>'
126 cat $log | syntax_highlighter log
127 echo '</pre>'
128 else
129 echo "<pre>No log: $pkg</pre>"
130 fi ;;
131 file=*)
132 # Dont allow all files on the system for security reasons.
133 file=${QUERY_STRING#file=}
134 case "$file" in
135 activity|cooknotes|cooklist)
136 [ "$file" == "cooklist" ] && \
137 nb="- Packages: $(cat $cooklist | wc -l)"
138 echo "<h2>DB: $file $nb</h2>"
139 echo '<pre>'
140 tac $CACHE/$file | syntax_highlighter activity
141 echo '</pre>' ;;
142 broken)
143 nb=$(cat $broken | wc -l)
144 echo "<h2>DB: broken - Packages: $nb</h2>"
145 echo '<pre>'
146 cat $CACHE/$file | sort | \
147 sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g
148 echo '</pre>' ;;
149 *.diff)
150 diff=$CACHE/$file
151 echo "<h2>Diff for: ${file%.diff}</h2>"
152 [ "$file" == "installed.diff" ] && echo \
153 "<p>This is the latest diff between installed packages \
154 and installed build dependencies to cook.</p>"
155 echo '<pre>'
156 cat $diff | syntax_highlighter diff
157 echo '</pre>' ;;
158 *.log)
159 log=$LOGS/$file
160 name=$(basename $log)
161 echo "<h2>Log for: ${name%.log}</h2>"
162 if [ -f "$log" ]; then
163 if fgrep -q "Summary" $log; then
164 echo '<pre>'
165 grep -A 20 "^Summary" $log | sed /^$/d | \
166 syntax_highlighter log
167 echo '</pre>'
168 fi
169 echo '<pre>'
170 cat $log | syntax_highlighter log
171 echo '</pre>'
172 else
173 echo "<pre>No log file: $log</pre>"
174 fi ;;
175 esac ;;
176 receipt=*)
177 pkg=${QUERY_STRING#receipt=}
178 echo "<h2>Receipt for: $pkg</h2>"
179 if [ -f "$wok/$pkg/receipt" ]; then
180 echo '<pre>'
181 cat $wok/$pkg/receipt | syntax_highlighter receipt
182 echo '</pre>'
183 else
184 echo "<pre>No receipt for: $log</pre>"
185 fi ;;
186 *)
187 # Main page with summary.
188 inwok=$(ls $WOK | wc -l)
189 cooked=$(ls $PKGS/*.tazpkg | wc -l)
190 unbuilt=$(($inwok - $cooked))
191 [ "$cooked" -gt 0 ] && div=$(($inwok / 100))
192 [ "$div" -gt 0 ] && pct=$(($cooked / $div))
193 [ "$div" == 0 ] && pct=0
194 cat << EOT
195 <div style="float: right;">
196 <form method="get" action="$SCRIPT_NAME">
197 Package:
198 <input type="text" name="pkg" />
199 </form>
200 </div>
202 <h2>Summary</h2>
204 <pre>
205 Running command : $([ -s "$command" ] && cat $command || echo "Not running")
206 Wok revision : <a href="http://hg.slitaz.org/wok">$(cd $WOK && \
207 hg head --template '{rev}\n' || echo "No Hg wok")</a>
208 Commits to cook : $(cat $commits | wc -l)
209 Current cooklist : $(cat $cooklist | wc -l)
210 Broken packages : $(cat $broken | wc -l)
211 Blocked packages : $(cat $blocked | wc -l)
212 </pre>
214 <p>
215 Packages: $inwok in the wok - $cooked cooked - $unbuilt unbuilt
216 </p>
217 <div class="pctbar">
218 <div class="pct" style="width: ${pct}%;">${pct}%</div>
219 </div>
221 <p>
222 Latest:
223 <a href="cooker.cgi?file=cookorder.log">cookorder.log</a>
224 <a href="cooker.cgi?file=commits.log">commits.log</a>
225 <a href="cooker.cgi?file=installed.diff">installed.diff</a>
226 </p>
228 <h2>Activity</h2>
229 <pre>
230 $(tac $CACHE/activity | head -n 12 | syntax_highlighter activity)
231 </pre>
232 <a class="button" href="cooker.cgi?file=activity">More activity</a>
234 <h2>Cooknotes</h2>
235 <pre>
236 $(tac $cooknotes | head -n 12 | syntax_highlighter activity)
237 </pre>
238 <a class="button" href="cooker.cgi?file=cooknotes">More notes</a>
240 <h2>Commits</h2>
241 <pre>
242 $(cat $commits)
243 </pre>
245 <h2>Cooklist</h2>
246 <pre>
247 $(cat $cooklist | head -n 20)
248 </pre>
249 <a class="button" href="cooker.cgi?file=cooklist">Full cooklist</a>
251 <h2>Broken</h2>
252 <pre>
253 $(cat $broken | head -n 20 | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
254 </pre>
255 <a class="button" href="cooker.cgi?file=broken">All broken packages</a>
257 <h2>Blocked</h2>
258 <pre>
259 $(cat $blocked | sed s"#^[^']*#<a href='cooker.cgi?pkg=\0'>\0</a>#"g)
260 </pre>
262 <h2>Latest cook</h2>
263 <pre>
264 $(list_packages | sed s"#^\([^']*\).* : #<span class='log-date'>\0</span>#"g)
265 </pre>
266 EOT
267 ;;
268 esac
270 # Close xHTML page
271 cat << EOT
272 </div>
274 <div id="footer">
275 <a href="http://www.slitaz.org/">SliTaz Website</a>
276 <a href="cooker.cgi">Cooker</a>
277 <a href="http://hg.slitaz.org/cookutils/raw-file/tip/doc/cookutils.en.html">
278 Documentation</a>
279 </div>
281 </body>
282 </html>
283 EOT
285 exit 0