use standards-compliant tags php
[mdv_bs_web.git] / package.php
blob5844d59a61ff829bab713a6f14315615853090d7
1 <?php
2 /* vim: set ts=4 expandtab: */
4 /* Sanity check for key param before any work */
5 if (!preg_match ('/^\d{14}\.\w+\.\w+\.\d{1,5}$/', $_GET['key'])) {
6 die ("Invalid key.");
9 require_once "common.inc.php";
10 require_once "package.inc.php";
12 class BuildingStatus {
13 // steps
14 const BT_ASSIGN_TO_BBOT = 0x000000;
15 const BT_UPLOAD_TO_BHOST = 0x000001;
16 const BT_INSTALLING_BREQUIRES = 0x000002;
17 const BT_BPACKAGE = 0x000003;
18 const BT_WAITING = 0x000004;
19 const BT_UPLOAD_TO_MASTER = 0x000005;
21 // status
22 const BS_OK = 0x000101;
23 const BS_PROCESSING = 0x000102;
24 const BS_EMPTY = 0x000103;
25 const BS_FAILED = 0x000104;
26 const BS_NOT_QUEUED = 0x000105;
27 const BS_EXCLUDED = 0x000106;
28 const BS_PENDING = 0x000107;
29 const BS_TEMP_FAILURE = 0x000108;
30 const BS_REJECTED = 0x000109;
32 /**
33 * Package object
35 * @var Package
37 protected $package;
39 /**
40 * Available archs to process
42 * @var array
44 protected $archs;
45 protected $directories = array(
46 'done' => '',
47 'queue' => '',
48 'rejected' => ''
50 protected $_currentArch;
52 /**
53 * Constructor, check the required parameters to process the data.
55 * @param Package $package
56 * @param array $required_archs
57 * @param array $directories
59 public function __construct(Package $package, array $required_archs, array $directories) {
60 $this->package = $package;
62 if ($this->package->archs) {
63 $this->archs = array_unique(array_merge($required_archs, $this->package->archs));
64 } else {
65 if (empty($required_archs)) {
66 throw new Exception('No archictecture to process. Abording.');
68 $this->archs = $required_archs;
70 natsort($this->archs);
73 if (!array_key_exists('donedir', $directories) ||
74 !array_key_exists('queuedir', $directories) ||
75 !array_key_exists('rejecteddir', $directories)
76 ) {
77 throw new InvalidArgumentException('Missing directory in argument 3');
78 } else {
79 $this->directories = $directories;
83 /**
85 * @param int $step
87 protected function get_building_status($step) {
88 if (!array_key_exists($this->archs, $this->_currentArch)) {
89 return self::BS_EMPTY;
92 $status = $this->package->builds[$this->_currentArch][3];
94 // Offset to our index
95 $step--;
96 switch($status[$step]) {
97 case 1:
98 if ($status[$step+1] != 0) {
99 return self::BS_OK;
100 } elseif ($status[$step+1] != 1) {
101 return (array_key_exists($this->_currentArch,$this->package->failed)) ? self::BS_FAILED : self::BS_PROCESSING;
103 break;
104 case 0:
105 return self::BS_EMPTY;
106 case 2:
107 return self::BS_FAILED;
113 * @param int $step
115 protected function get_status($step) {
116 if ($step > self::BT_ASSIGN_TO_BHOST) {
117 if (self::get_status($step-1) != self::BS_OK) {
118 return self::BS_EMPTY;
122 if ($step == self::BT_ASSIGN_TO_BBOT) {
123 if (self::get_status (self::BT_UPLOAD_TO_BHOST) != self::BS_EMPTY) {
124 return self::BS_OK;
126 elseif (in_array ($this->_currentArch, $this->package->excluded)) {
127 return self::BS_EXCLUDED;
129 else {
130 return self::BS_PENDING;
132 } elseif ($step <= self::BT_BPACKAGE) {
133 if (array_key_exists ($this->_currentArch, $this->package->done)) {
134 return self::BS_OK;
136 else {
137 $status = self::get_building_status ($step);
138 if ($status == self::BS_FAILED && !array_key_exists ($this->_currentArch, $this->package->failed)) {
139 $status = self::BS_TEMP_FAILURE;
141 return $status;
143 } elseif ($step == self::BT_WAITING) {
144 if (array_key_exists ($this->_currentArch, $this->package->done)) {
145 return self::BS_OK;
146 } elseif (array_key_exists ($this->_currentArch, $this->package->failed)) {
147 return self::BS_FAILED;
148 } elseif (in_array ($this->_currentArch, $this->package->excluded)) {
149 return self::BS_EXCLUDED;
150 } else {
151 $status = self::get_building_status ($step-1);
152 if ($status == self::BS_OK) {
153 return self::BS_PENDING;
155 return self::BS_EMPTY;
157 } elseif ($pos == self::BT_UPLOAD_TO_MASTER) {
158 $prev_status = self::get_status ($step-1);
159 if ($prev_status != self::BS_OK or count($this->package->failed)) {
160 return self::BS_EMPTY;
162 if (file_exists ($this->directories['rejected'] . '/' . $this->package->base . ".youri")) {
163 return self::BS_REJECTED;
165 if (!file_exists ($this->directories['done'] . '/' . $this->package->srpm) &&
166 !file_exists ($this->directories['queue'] . '/' . $this->package->srpm)
168 foreach ($this->archs as $reqarch) {
169 if (!in_array ($reqarch, $package->archs)) {
170 return self::BS_PENDING;
173 return self::BS_OK;
175 return self::BS_PENDING;
180 * Main method to call after the constructor.
182 * This method populate $_currentArch and call self::get_status
183 * to
185 * @param int $step step to process
187 public function show_all_status($step) {
188 foreach ($this->archs as $this->_currentArch) {
189 echo "<td>";
190 $status = self::get_status($step);
191 switch ($status) {
192 case self::BS_FAILED:
193 printf('<a href="/queue/failure/' . $package->base . '/">%s</a>', self::get_string($status));
194 break;
195 case self::BS_REJECTED:
196 printf('<a href="/queue/rejected/' . $package->base . '/">%s</a>', self::get_string($status));
197 break;
198 default:
199 if ($step == self::BT_ASSIGN_TO_BBOT &&
200 $status == self::BS_OK &&
201 array_key_exists($this->_currentArch, $this->package->builds)
203 printf('Host: %s', $this->package->builds[$this->_currentArch][0]);
204 } else {
205 echo self::get_string($status);
207 break;
209 echo "</td>";
214 * translate the status id into a string
216 * @param int $status
217 * @return string
219 static public function get_string($status) {
220 switch ($status) {
221 case self::BS_OK:
222 return 'Ok';
223 case self::BS_PROCESSING:
224 return 'Processing';
225 case self::BS_EMPTY:
226 return '&nbsp;';
227 case self::BS_FAILED:
228 return 'Failed';
229 case self::BS_NOT_QUEUED:
230 return 'Not queued';
231 case self::BS_EXCLUDED:
232 return 'Excluded';
233 case self::BS_PENDING:
234 return 'Pending';
235 case self::BS_TEMP_FAILURE:
236 return 'Temporary failure';
237 case self::BS_REJECTED:
238 return 'Rejected';
243 * Give the $archs array
245 * @return array
247 function show_archs() {
248 return $this->archs;
251 public function getArchNumber() {
252 return count($this->archs);
256 // Build the page
257 page_header("package");
258 $pkg = new Package($_GET['key'], False);
260 $buildingStatus = new BuildingStatus($pkg, $requiredarchs,
261 array('done' => $donedir, 'queue' => $queuedir, 'rejected' => $rejecteddir)
264 $archcount = count($archs);
268 <center>
269 <h3>Build Status</h3>
270 <table cellspacing="8">
271 <tr>
272 <td><strong>Package:</strong> <?php echo $pkg->pkgname;?></td>
273 <td><strong>Version:</strong> <?php echo $pkg->version;?></td>
274 </tr>
275 <tr>
276 <td><strong>Submitter:</strong> <?php echo $pkg->submitter;?></td>
277 <td><strong>Commit:</strong> <a href="http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages?view=rev&revision=<?php echo $pkg->commit;?>"><?php echo $pkg->commit;?></a></td>
278 </tr>
279 <tr>
280 <td><strong>Distro:</strong> <?php echo $pkg->distro;?></td>
281 <td><strong>Repository:</strong> <?php echo $pkg->repository;?></td>
282 </tr>
283 <tr>
284 <td><strong>Submitted from:</strong> <?php echo $pkg->submithost;?></td>
285 <td><strong>Submitted on:</strong> <?php echo format_time (substr ($pkg->id, 0, 14))." GMT";?></td>
286 </tr>
287 <tr>
288 <td colspan="2"><strong>Summary:</strong> <?php echo $pkg->summary;?></td>
289 </tr>
290 </table>
292 <table cellspacing="8">
293 <tr>
294 <th rowspan="2">Step</th>
295 <th colspan="<?php echo $buildingStatus->getArchNumber();?>">Arch</th>
296 </tr>
297 <tr>
298 <?php
299 foreach($buildingStatus->show_archs() as $arch) {
300 echo " <th>$arch</th>\n";
303 </tr>
304 <tr>
305 <td>Assigning package to a build bot</td>
306 <?php echo $buildingStatus->show_all_status($buildingStatus::BT_ASSIGN_TO_BBOT);?>
307 </tr>
308 <tr>
309 <td>Uploading to build host</td>
310 <?php echo $buildingStatus->show_all_status($buildingStatus::BT_ASSIGN_TO_BHOST);?>
311 </tr>
312 <tr>
313 <td>Installing BuildRequires</td>
314 <?php echo $buildingStatus->show_all_status($buildingStatus::BT_INSTALLING_BREQUIRES);?>
315 </tr>
316 <tr>
317 <td>Building package</td>
318 <?php echo $buildingStatus->show_all_status($buildingStatus::BT_BPACKAGE);?>
319 </tr>
320 <tr>
321 <td>Waiting for kenobi pop</td>
322 <?php echo $buildingStatus->show_all_status($buildingStatus::BT_WAITING);?>
323 </tr>
324 <tr>
325 <td>Uploading to master repository</td>
326 <?php echo $buildingStatus->show_all_status($buildingStatus::BT_UPLOAD_TO_MASTER);?>
327 </tr>
328 </table>
332 foreach (array_keys($pkg->builds) as $arch) {
333 if (array_key_exists ($arch, $pkg->failed)) {
334 continue;
336 if ($pkg->builds[$arch][3][2] and !$pkg->builds[$arch][3][3]) {
337 printf('<div style="width: 99%"><pre>Last 15 lines from build.log for %s:'."\n",$arch);
338 echo $pkg->tail_buildlog($arch);
339 echo "(...)\n";
340 echo "</pre></div>\n";
344 if (count ($pkg->done) and file_exists ("$donedir/".$pkg->srpm)) {
345 echo "<table><tr><td><pre>Packages generated so far for archs";
346 foreach (array_keys ($pkg->done) as $arch) {
347 echo " $arch";
349 echo ":\n";
350 @exec ("find -L $donedir -type f -name '".$_GET['key']."_*.rpm' | sed 's@^[^_]\+_@@;s/^@[0-9]\+:\(.*.src.rpm\)/\\1/'", $rpmlist);
351 natsort($rpmlist);
352 echo join ("\n", $rpmlist);
353 echo "</pre></td></tr></table>";
356 if (count ($pkg->failed)) {
357 @exec ("$script_path/analyse-rpmbuild-failures $faileddir/{$pkg->base}/log/*/build.*.log", $loglist);
358 if (count ($loglist)) {
359 echo "<table><tr><td><pre>Build failure reason(s):\n";
360 echo join ("\n", $loglist);
361 echo "</pre></td></tr></table>";
365 //echo "<pre>";
366 //var_dump($pkg);
367 //echo "</pre>";
368 echo "</center>";
369 page_footer();