diff options
Diffstat (limited to 'shared/classes')
-rw-r--r-- | shared/classes/build.php | 80 | ||||
-rw-r--r-- | shared/classes/configuration.php | 2 | ||||
-rw-r--r-- | shared/classes/gentoo_profile.php | 12 | ||||
-rw-r--r-- | shared/classes/task.php | 10 |
4 files changed, 59 insertions, 45 deletions
diff --git a/shared/classes/build.php b/shared/classes/build.php index 8212d56..d14deb0 100644 --- a/shared/classes/build.php +++ b/shared/classes/build.php @@ -26,10 +26,9 @@ class sql_build extends conf_build_common { 'default' => '' ), 'status' => array ( - 'type' => 'VARCHAR', - 'length' => 255, - 'not_null' => true, - 'default' => '' + 'type' => 'TINYINT', + 'length' => 4, + 'not_null' => true ), 'ctime' => array ( 'type' => 'INT', @@ -51,39 +50,47 @@ class sql_build extends conf_build_common { function display() { global $S; $format='D j M Y G:i:s T'; + $OoA=owner_or_admin($this->id); $html='<div class="build"><span class="name">'.(isset($this->name) && strlen($this->name)?htmlentities($this->name):'Unnamed Build').'</span> '; - $status=explode('/', $this->status, 2); - if ($status[0] == 'config') { - $status[1]=substr($status[1], strpos($status[1], 'p')+1); - $html.='<span class="status config">[Configuration step '.$status[1].']</span><br/><span class="links"><a href="'.url('create/'.$this->id).'">Continue configuring</a></span>'; - } elseif ($status[0] == 'build') { - if ($status[1] == 'ready') { - $total=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`="build/ready"')->fetch(PDO::FETCH_COLUMN); - $num=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`="build/ready" AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN); - $html.="<span class=\"status queued\">[Queued ($num/$total)]</span>"; - } elseif ($status[1]='running') { - // Add link to regular log viewer? - // Build stage X - $html.='<span class="status building">[building]</span><br/><span class="links"><a href="'.url('logs/'.$this->id.'/live').'">Watch</a> • <a href="'.url('logs/'.$this->id).'"> Build log</a></span>'; - } else { - throw_exception('Unrecognized build status '.$this->status); + $links=array(); + if ($this->status == -128) { + $total=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128')->fetch(PDO::FETCH_COLUMN); + $num=$S['pdo']->query('SELECT COUNT(*) FROM `builds` WHERE `status`=-128 AND `ctime` <= '.$this->ctime)->fetch(PDO::FETCH_COLUMN); + $html.="<span class=\"status queued\">[Queued ($num/$total)]</span>"; + } elseif ($this->status == -127) { + $html.='<span class="status successful">[uploading]</span>'; + if ($OoA) $links['Build log']=url("logs/$this->id"); + } elseif ($this->status < 0) { + // TODO Build stage X + $html.='<span class="status building">[building]</span>'; + if ($OoA) { + //$links['Watch']=url("logs/$this->id/live"); + $links['Build Log']=url("logs/$this->id"); } - } elseif ($status[0] == 'finished') { - $status=explode(': ', $status[1], 2); - if ($status[0] == 'success') { - $r=$S['pdo']->query('SELECT COUNT(*) as `count`, MAX(`time`) as `time` FROM `downloads` WHERE `build`="'.$this->id.'"'); - $r=$r->fetch(PDO::FETCH_ASSOC); - $d=$r['count'].' download'.($r['count'] != 1?'s':'').($r['count']?'<br/><span class="time">(last at '.date($format, $r['time']).')</span>':''); - $html.='<span class="downloads">'.$d.'</span><span class="status successful">[successful]</span><br/><span class="links"><a href="'.url('download/'.$this->id).'">Download image</a> • <a href="'.url('logs/'.$this->id).'">Build log</a></span>'; - } elseif ($status[0] == 'failed') { - $html.='<span class="status failed">[failed: '.htmlentities($status[1]).']</span><br/><span class="links"><a href="'.url('logs/'.$this->id.'/failure').'">View output of failed command</a> • <a href="'.url('logs/'.$this->id).'">Build log</a></span>'; - } elseif ($status[0] == 'uploading') { - $html.='<span class="status successful">[uploading]</span><br/><span class="links"><a href="'.url('logs/'.$this->id).'">Build log</a></span>'; - } else { - throw_exception('Unrecognized build status '.$this->status); + } elseif ($this->status == 0) { + $r=$S['pdo']->query('SELECT COUNT(*) as `count`, MAX(`time`) as `time` FROM `downloads` WHERE `build`="'.$this->id.'"')->fetch(PDO::FETCH_ASSOC); + $d=($OoA && $r['count']?'<a href="'.url("download/$this->id/history").'">':'').$r['count'].' download'.($r['count'] != 1?'s':'').($r['count']?($OoA?'</a>':'').'<br/><span class="time">(last at '.date($format, $r['time']).')</span>':''); + $html.='<span class="downloads">'.$d.'</span><span class="status successful">[successful]</span>'; + $links['Download image']=url("download/$this->id"); + if ($OoA) $links['Build log']=url("logs/$this->id"); + } elseif ($this->status == 127) { + $html.='<span class="status failed">[upload failed]</span>'; + if ($OoA) $links['Build log']=url("logs/$this->id"); + } elseif ($this->status == 126) { + $html.='<span class="status failed">[failed]</span>'; + if ($OoA) { + //$links['View output of failed command']=url("logs/$this->id/failure"); + $links['Build log']=url("logs/$this->id"); } } else { - throw_exception('Unrecognized build status '.$this->status); + $html.='<span class="status failed">[failed: got signal '.$this->status.']</span>'; + if ($OoA) $links['Build log']=url('logs/'.$this->id); + } + if ($links) { + foreach ($links as $label => $url) { + $links[$label]='<a href="'.$url.'">'.htmlentities($label).'</a>'; + } + $html.='<br/><span class="links">'.implode(' • ', $links).'</span>'; } if (isset($this->ctime)) { $html.='<div class="time">Submitted for build at: <span class="time">'.date($format, $this->ctime).'</span><br/>'; @@ -102,5 +109,12 @@ class sql_build extends conf_build_common { $html.='</div>'; return $html; } + function queued_tasks() { + global $S; + static $cache; + if (!isset($cache)) + $cache=$S['pdo']->query('SELECT COUNT(`order`) FROM `tasks` WHERE `start` IS NULL AND `build`="'.$this->id.'"')->fetch(PDO::FETCH_COLUMN); + return $cache; + } } ?> diff --git a/shared/classes/configuration.php b/shared/classes/configuration.php index 157610b..e315047 100644 --- a/shared/classes/configuration.php +++ b/shared/classes/configuration.php @@ -53,7 +53,7 @@ class sql_configuration extends conf_build_common { $opt->write(); } $build->ctime=time(); - $build->status='build/ready'; + $build->status=1; $build->write(); return $build; } diff --git a/shared/classes/gentoo_profile.php b/shared/classes/gentoo_profile.php index 5657ed1..0cf071d 100644 --- a/shared/classes/gentoo_profile.php +++ b/shared/classes/gentoo_profile.php @@ -138,16 +138,17 @@ class sql_gentoo_profile extends sql_row_obj { $file=realpath(BACKEND.'/../gentoo_pkgsets.csv'); if (!is_readable($file)) return false; $file=fopen($file, 'r'); + if ($update) $exists=array(); while (!feof($file)) { $add=array(); - $pkgs=explode("\t", rtrim(fgets($file))); + $pkgs=explode("\t", trim(fgets($file))); + if (substr($pkgs[0], 0, 1) == '#') continue; $name=array_shift($pkgs); $obj=new sql_gentoo_pkgset(); if ($update) { $r=$S['pdo']->query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.' AND `name`="'.$name.'" LIMIT 1'); - if ($r->rowCount()) { + if ($r->rowCount()) $obj->from_array($r->fetch(PDO::FETCH_ASSOC), true); - } } foreach ($pkgs as $pkg) { if ($pkg=sql_gentoo_package::from_atom($pkg, $this)) @@ -158,10 +159,11 @@ class sql_gentoo_profile extends sql_row_obj { $obj->name=$name; $obj->packages=implode("\n", $add); $obj->write(); - } elseif (isset($obj->id)) { - $obj->delete(); + if ($update) $exists[]=$obj->id; } } + if ($update) + $S['pdo']->query('DELETE FROM `gentoo_pkgsets` WHERE `profile`='.$this->id.($exists?' AND `id` NOT IN ('.implode(',', $exists).')':'')); } public function &get_packages() { global $S; diff --git a/shared/classes/task.php b/shared/classes/task.php index 569d0fb..d5578b2 100644 --- a/shared/classes/task.php +++ b/shared/classes/task.php @@ -26,8 +26,7 @@ class sql_task extends sql_row_obj { 'default' => '' ), 'command' => array ( - 'type' => 'TEXT', - 'not_null' => true + 'type' => 'TEXT' ), 'start' => array ( 'type' => 'INT', @@ -46,7 +45,7 @@ class sql_task extends sql_row_obj { ); function display() { - $html='<div class="task"><div class="description">'.htmlentities($this->description).'</div><div class="info">[<a href="'.url('logs/'.$this->build.'/'.$this->order).'">log</a>] <span class="command">'.htmlentities($this->command).'</span> '; + $html='<div class="task"><div class="description">'.htmlentities($this->description).'</div><div class="info">[<a href="'.url('logs/'.$this->build.'/'.$this->order).'">log</a>] '.($this->command?'<span class="command">'.htmlentities($this->command).'</span> ':''); if (isset($this->start)) { if (isset($this->finish)) { $html.='<span class="status '; @@ -69,9 +68,8 @@ class sql_task extends sql_row_obj { $html.='<span class="status running">[running]</span> <span class="time">Running for <span class="time">'.display_time(time()-$this->start).'</span></span>'; } } else { - $total=$S['pdo']->query('SELECT COUNT(*) FROM `tasks` WHERE `build`="'.$this->build.'" AND `start` IS NULL')->fetch(PDO::FETCH_COLUMN); - $num=$S['pdo']->query('SELECT COUNT(*) FROM `tasks` WHERE `builds`="'.$this->build.'" AND `start` IS NULL AND `order` <= '.$this->order); - $html.="<span class=\"status queued\">[queued $num/$total]</span>"; + $num=$S['pdo']->query('SELECT COUNT(*) FROM `tasks` WHERE `builds`="'.$this->build.'" AND `start` IS NULL AND `order` <= '.$this->order)->fetch(PDO::FETCH_ASSOC); + $html.="<span class=\"status queued\">[queued $num/".$build->queued_tasks()."]</span>"; } $html.='</div></div>'; return $html; |