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'])) {
9 require_once "common.inc.php";
10 require_once "package.inc.php";
12 class BuildingStatus
{
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;
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;
40 * Available archs to process
45 protected $directories = array(
50 protected $_currentArch;
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
));
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)
77 throw new InvalidArgumentException('Missing directory in argument 3');
79 $this->directories
= $directories;
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
96 switch($status[$step]) {
98 if ($status[$step+
1] != 0) {
100 } elseif ($status[$step+
1] != 1) {
101 return (array_key_exists($this->_currentArch
,$this->package
->failed
)) ? self
::BS_FAILED
: self
::BS_PROCESSING
;
105 return self
::BS_EMPTY
;
107 return self
::BS_FAILED
;
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
) {
126 elseif (in_array ($this->_currentArch
, $this->package
->excluded
)) {
127 return self
::BS_EXCLUDED
;
130 return self
::BS_PENDING
;
132 } elseif ($step <= self
::BT_BPACKAGE
) {
133 if (array_key_exists ($this->_currentArch
, $this->package
->done
)) {
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
;
143 } elseif ($step == self
::BT_WAITING
) {
144 if (array_key_exists ($this->_currentArch
, $this->package
->done
)) {
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
;
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
;
175 return self
::BS_PENDING
;
180 * Main method to call after the constructor.
182 * This method populate $_currentArch and call self::get_status
185 * @param int $step step to process
187 public function show_all_status($step) {
188 foreach ($this->archs
as $this->_currentArch
) {
190 $status = self
::get_status($step);
192 case self
::BS_FAILED
:
193 printf('<a href="/queue/failure/' . $package->base
. '/">%s</a>', self
::get_string($status));
195 case self
::BS_REJECTED
:
196 printf('<a href="/queue/rejected/' . $package->base
. '/">%s</a>', self
::get_string($status));
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]);
205 echo self
::get_string($status);
214 * translate the status id into a string
219 static public function get_string($status) {
223 case self
::BS_PROCESSING
:
227 case self
::BS_FAILED
:
229 case self
::BS_NOT_QUEUED
:
231 case self
::BS_EXCLUDED
:
233 case self
::BS_PENDING
:
235 case self
::BS_TEMP_FAILURE
:
236 return 'Temporary failure';
237 case self
::BS_REJECTED
:
243 * Give the $archs array
247 function show_archs() {
251 public function getArchNumber() {
252 return count($this->archs
);
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);
269 <h3
>Build Status
</h3
>
270 <table cellspacing
="8">
272 <td
><strong
>Package
:</strong
> <?php
echo $pkg->pkgname
;?
></td
>
273 <td
><strong
>Version
:</strong
> <?php
echo $pkg->version
;?
></td
>
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
>
280 <td
><strong
>Distro
:</strong
> <?php
echo $pkg->distro
;?
></td
>
281 <td
><strong
>Repository
:</strong
> <?php
echo $pkg->repository
;?
></td
>
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
>
288 <td colspan
="2"><strong
>Summary
:</strong
> <?php
echo $pkg->summary
;?
></td
>
292 <table cellspacing
="8">
294 <th rowspan
="2">Step
</th
>
295 <th colspan
="<?php echo $buildingStatus->getArchNumber();?>">Arch
</th
>
299 foreach($buildingStatus->show_archs() as $arch) {
300 echo " <th>$arch</th>\n";
305 <td
>Assigning package to a build bot
</td
>
306 <?php
echo $buildingStatus->show_all_status($buildingStatus::BT_ASSIGN_TO_BBOT
);?
>
309 <td
>Uploading to build host
</td
>
310 <?php
echo $buildingStatus->show_all_status($buildingStatus::BT_ASSIGN_TO_BHOST
);?
>
313 <td
>Installing BuildRequires
</td
>
314 <?php
echo $buildingStatus->show_all_status($buildingStatus::BT_INSTALLING_BREQUIRES
);?
>
317 <td
>Building package
</td
>
318 <?php
echo $buildingStatus->show_all_status($buildingStatus::BT_BPACKAGE
);?
>
321 <td
>Waiting
for kenobi pop
</td
>
322 <?php
echo $buildingStatus->show_all_status($buildingStatus::BT_WAITING
);?
>
325 <td
>Uploading to master repository
</td
>
326 <?php
echo $buildingStatus->show_all_status($buildingStatus::BT_UPLOAD_TO_MASTER
);?
>
332 foreach (array_keys($pkg->builds
) as $arch) {
333 if (array_key_exists ($arch, $pkg->failed
)) {
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);
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) {
350 @exec
("find -L $donedir -type f -name '".$_GET['key']."_*.rpm' | sed 's@^[^_]\+_@@;s/^@[0-9]\+:\(.*.src.rpm\)/\\1/'", $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>";