use standards-compliant tags php
[mdv_bs_web.git] / common.inc.php
blob29e389c8335c35e43be91b03b3f61f2f9f8e7aaf
1 <?php
3 date_default_timezone_set ("GMT");
5 $script_path = '/var/www/bs/';
6 $bs_result_path = '/home/mandrake/uploads/';
8 /* Page creation start time */
9 $starttime = microtime(true);
11 /* BuildSystem paths */
12 $queuedir = "$bs_result_path/todo";
13 $faileddir = "$bs_result_path/failure";
14 $donedir = "$bs_result_path/done";
15 $rejecteddir = "$bs_result_path/rejected";
16 $builddir = "/home/mandrake/iurt";
18 /* Required archs for considering a package as 'built' */
19 $requiredarchs = array ("i586", "x86_64");
20 $sufficientarchs = array ("noarch");
22 /* SNMP configs */
23 $snmp_timeout = 1000000; /* miliseconds */
26 * format_time($timestamp)
27 * Formats a timestamp to a human-readable time
29 function format_time($timestamp)
31 return preg_replace("/(....)(..)(..)(..)(..)(..)/", '$1-$2-$3 $4:$5:$6', $timestamp);
35 * delta_time($timestamp)
36 * Provides a delta time from now to $timestamp.
38 function delta_time($timestamp, $reference = '')
40 $ftime = strptime ($timestamp, '%Y%m%d%H%M%S');
41 $stamp = gmmktime (
42 $ftime['tm_hour'],
43 $ftime['tm_min'],
44 $ftime['tm_sec'],
45 $ftime['tm_mon'] + 1,
46 $ftime['tm_mday'],
47 $ftime['tm_year'] + 1900
50 if (strlen ($reference)) {
51 $ftime = strptime ($reference, '%Y%m%d%H%M%S');
52 $reference = gmmktime (
53 $ftime['tm_hour'],
54 $ftime['tm_min'],
55 $ftime['tm_sec'],
56 $ftime['tm_mon'] + 1,
57 $ftime['tm_mday'],
58 $ftime['tm_year'] + 1900
61 else {
62 $reference = gmmktime();
64 $delta = $reference - $stamp;
65 $days = date ("z", $delta);
66 $hours = date("G", $delta);
67 $mins = date("i", $delta);
68 $secs = date("s", $delta);
69 $strdays = $days > 1 ? "days" : "day";
70 $strhours = $hours > 1 ? "hours" : "hour";
71 $strmins = $mins > 1 ? "minutes" : "minute";
72 $strsecs = $secs > 1 ? "seconds" : "second";
73 if ($days > 2) {
74 return "$days $strdays";
76 elseif ($days) {
77 return "$days $strdays $hours $strhours";
79 elseif ($hours) {
80 return "${hours}h ${mins}min";
82 elseif ($mins) {
83 return "${mins}min ${secs}s";
86 return "${secs}s";
89 /*
90 * page_header()
91 * Just like it sounds.
93 function page_header($title)
96 <html>
97 <head>
98 <link href="http://www.mandriva.com/archives/extension/mdkdesign/design/mdk/stylesheets/screen.css" rel="stylesheet" type="text/css">
99 <link href="http://www.mandriva.com/archives/design/mdk/stylesheets/target.css.php?t=none" rel="stylesheet" type="text/css">
100 <link href="http://www.mandriva.com/extension/mdkdesign/design/mdk/stylesheets/screen.css" rel="stylesheet" type="text/css">
101 <link href="http://www.mandriva.com/design/mdk/stylesheets/target.css.php?t=none" rel="stylesheet" type="text/css">
102 <link href="http://www.mandriva.com/extension/mdkdesign/design/mdk/stylesheets/welcome.css" rel="stylesheet" type="text/css">
103 <link href="style.css" rel="stylesheet" type="text/css">
104 <title>Mandriva Build System<?php ($title) ? print(" - ".$title) : "" ; ?></title>
105 </head>
106 <body>
107 <div id="header">
108 <div id="header-design">
109 <div id="header-is">
110 <h3 id="hide">Intersites Menu</h3>
111 <ul>
112 <li id="is_store"><a href="http://store.mandriva.com/"><span>Store</span></a></li>
113 <li id="is_club"><a href="http://club.mandriva.com/"><span>Club</span></a></li>
114 <li id="is_support"><a href="http://www.mandriva.com/en/support"><span>Support</span></a></li>
115 <li id="is_downloads"><a href="http://www.mandriva.com/en/download/free"><span>Downloads</span></a></li>
116 <li id="is_company"><a href="http://www.mandriva.com/enterprise/en/company"><span>Company</span></a></li>
117 </ul>
118 <div class="break"></div>
119 </div>
120 <div id="header-logo">
121 <h1><a href="http://www.mandriva.com/"><span>Mandriva</span></a></h1>
122 <div class="break"></div>
123 </div>
124 <div id="header-tools">
125 <table>
126 <tr>
127 <td><font size=+2>Mandriva Development Server</font></td>
128 </tr>
129 </table>
130 <div class="break"></div>
131 </div>
132 <div class="break"></div>
133 </div>
134 </div>
136 <?php
137 navigation_bar();
138 include 'motd.php';
143 * page_footer()
144 * Just like it sounds.
146 function page_footer()
149 Page generation time:
150 <?php
151 global $starttime;
152 printf ("%5.3fs", microtime(true)-$starttime);
154 </body>
155 </html>
156 <?php
161 * navigation_bar()
162 * Prints the navigation bar
164 function navigation_bar()
167 <table width="99%" cols=6 cellspacing=0 border=0>
168 <tr>
169 <td align="left">
170 <nobr><?php echo gmdate ("D, Y-m-d G:i:s T");?></nobr>
171 </td>
172 <!--
173 <td width="20%">
174 <center>
175 <a href="cluster.php">Cluster overview</a>
176 </center>
177 </td>
179 <td>
180 <center>
181 <a href="http://kenobi.mandriva.com/ganglia/">System Status</a>
182 </center>
183 </td>
184 <td>
185 <center>
186 <a href="queue.php">Queue</a>
187 </center>
188 </td>
189 <td>
190 <center>
191 <a href="build.php">Building</a>
192 </center>
193 </td>
194 <td>
195 <center>
196 <a href="output.php">Output</a>
197 </center>
198 </td>
199 <td align="right">
200 <form method="get">
201 <nobr>
202 <center>
203 Filter: <input type="text" name="filter" value="<?php echo $_GET['filter'];?>"><input type="submit" value="ok">
204 </center>
205 </nobr>
206 </form>
207 </td>
208 </tr>
209 </table>
210 <?php
215 * parse_filterstring($filterstr)
216 * Parse the requested filterstr and properly sets up the globals
217 * $mustbe, $mustbenot and $oneof. Parsing this before avoids reparsing
218 * for all table cells.
220 function parse_filterstring($filterstr)
222 global $mustbe, $mustbenot, $oneof;
223 $filterstr = $_GET['filter'];
224 $words = explode(' ', $filterstr);
225 $oneof = array();
226 $mustbe = array();
227 $mustbenot = array();
228 foreach ($words as $word) {
229 if ($word[0] == '-') {
230 $mustbenot[] = substr($word, 1);
232 elseif ($word[0] == '+') {
233 $mustbe[] = substr($word, 1);
235 else {
236 $oneof[] = $word;
243 * filter_item($item)
244 * Match a table row against the globals $mustbe, $mustbenot and $oneof.
245 * Returns False to rows not filling the request, otherelse True.
247 function filter_item ($item)
249 global $mustbe, $mustbenot, $oneof;
250 $foundmustbe = 0;
251 $foundoneof = 0;
252 foreach ($item as $element) {
253 foreach ($mustbenot as $badword) {
254 if (strstr($element, $badword)) {
255 return False;
258 foreach ($mustbe as $goodword) {
259 if (strstr($element, $goodword)) {
260 $foundmustbe++;
263 foreach ($oneof as $goodword) {
264 if (strstr($element, $goodword)) {
265 $foundoneof++;
269 return (
270 ($foundmustbe == count($mustbe)) and
271 (count($oneof) ? $foundoneof > 0 : 1)
277 * filter ($table)
278 * Filter the given array according to the filter expression
279 * requested via GET method.
280 * Returns the filtered table.
282 function filter ($table)
284 $filterstr = $_GET['filter'];
285 if (!$filterstr) {
286 return $table;
288 parse_filterstring($filterstr);
289 return array_filter($table, "filter_item");
294 * parse_lock_item($item)
295 * Parses a given lock and returns a fields array
296 * $item must be like this:
297 * (base)_x86_64.iurt.frohike.20061101163646.4273.lock
299 function parse_lock_item($item)
301 preg_match('/_([A-Za-z0-9-_]+).iurt.(\w+)\.([0-9]{14})\.([0-9]+)/', $item, $file);
302 // i586 frohike 20061101163646 4273
303 $arch = $file[1];
304 if (strstr ($arch, "-noarch")) {
305 $arch = "noarch";
307 return array (
308 $arch, // arch
309 $file[2], // buildhost
310 $file[3], // build start time
311 $file[4] // node pid
317 * parse_info($info)
318 * Parse the .info file, that contains .src.rpm informations
320 function parse_info($item)
322 global $queuedir;
323 $contents = @file("$queuedir/$item");
324 $contents = array_map ("trim", $contents);
327 * Hide epoch information.
329 if ($contents[1] != "(none)") {
330 $version = "${contents[1]}:${contents[2]}";
332 else {
333 $version = "${contents[2]}";
336 $version = "${contents[2]}";
338 preg_match('/^([^\/]+)\/([^\/]+)\/([^\/]+)\//', $item, $distrorepos);
339 // cooker contrib release
340 preg_match('/\/([0-9]{14})\.([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)/', $item, $author);
341 // 20061026140631 neoclust kenobi
342 preg_match('/\.([0-9]+)_@([0-9]+):(.+)/', $item, $file);
343 // 29995 @-73078 crimson..\
344 if (!$file) {
345 preg_match('/\.([0-9]+)_(.+)/', $item, $file);
346 // 29995 @-73078 crimson..
347 $file[2] = "";
350 return array (
351 $contents[0],
352 $version,
353 $file[2],
354 $distrorepos[1],
355 "${distrorepos[2]}/${distrorepos[3]}",
356 $author[2],
357 $author[1],
358 $file[1],
359 $author[3],
360 $contents[3]
365 * list_info_files
366 * Search and return the list of info files
368 function list_info_files()
370 global $queuedir;
372 @exec("find -L $queuedir -mindepth 4 -maxdepth 4 -type f -ctime -3 -name '*.src.rpm.info' |\
373 sed 's@$queuedir/*@@;".'s@.*/\([0-9]\{14\}\.\w\+\.\w\+\.[0-9]\{1,5\}\)_.*@\1 &@'."'", $rawlist);
374 $infolist = array();
375 foreach ($rawlist as $infoline) {
376 list ($id, $infofile) = split (" ", $infoline);
377 $infolist[$id] = $infofile;
380 $idlist = array_keys ($infolist);
381 natsort ($idlist);
382 return array (array_reverse ($idlist), $infolist);