diff options
author | Eudyptula <eitan@mosenkis.net> | 2009-06-19 16:33:50 -0400 |
---|---|---|
committer | Eudyptula <eitan@mosenkis.net> | 2009-06-19 16:33:50 -0400 |
commit | 62e2432de3c2fb3bcd14faee86029c1c0eefdb23 (patch) | |
tree | 6f52ea4d6babdff4ff0d45420fa133bd70cab0f1 /backend | |
parent | Transitioned to support multiple profiles, chosen in the frontend, to use dat... (diff) | |
download | ingenue-62e2432de3c2fb3bcd14faee86029c1c0eefdb23.tar.gz ingenue-62e2432de3c2fb3bcd14faee86029c1c0eefdb23.tar.bz2 ingenue-62e2432de3c2fb3bcd14faee86029c1c0eefdb23.zip |
Finished infrastructure for 1st gen. build wizard, enhanced backend logging
Diffstat (limited to 'backend')
-rwxr-xr-x | backend/backend.php | 6 | ||||
-rw-r--r-- | backend/functions/build.php | 2 | ||||
-rw-r--r-- | backend/functions/execution.php | 12 | ||||
-rw-r--r-- | backend/functions/log.php | 2 |
4 files changed, 16 insertions, 6 deletions
diff --git a/backend/backend.php b/backend/backend.php index 1cb1cdb..0dbd8a9 100755 --- a/backend/backend.php +++ b/backend/backend.php @@ -19,15 +19,19 @@ if (isset($opts['f'])) { } while (true) { // TODO check first for builds that need to be resumed - $r=$pdo->query('SELECT * FROM `builds` WHERE `status`="build/ready" LIMIT 1'); // TODO ORDER BY `ctime` ASC + $r=$pdo->query('SELECT * FROM `builds` WHERE `status`="build/ready" ORDER BY `ctime` ASC LIMIT 1'); if ($r->rowCount()) { $build=new sql_build($r->fetch(PDO::FETCH_ASSOC)); + $build->start=time(); + $build->write(); echo 'Starting build id='.$build->id."\n"; try { build($build); } catch (Exception $e) { echo 'Caught exception: '.$e->getMessage()."\n"; } + $build->finish=time(); + $build->write(); echo 'Finished with build id='.$build->id."\n"; } echo 'Sleeping...'; diff --git a/backend/functions/build.php b/backend/functions/build.php index 3346218..84b2a77 100644 --- a/backend/functions/build.php +++ b/backend/functions/build.php @@ -32,7 +32,7 @@ function build(&$build) { $contents.=strtoupper($name).'="'.$val.'"'."\n"; } unset($makeconf); - fatal(log_status('Writing '.$C.'/make.conf:'."\n".indent($contents), file_put_contents($C.'/etc/make.conf', $contents))); + fatal(log_status('Writing '.$C.'/make.conf', file_put_contents($C.'/etc/make.conf', $contents))); unset($contents); fatal(log_status('Making make.profile symlink to '.$conf['portdir'].'/profiles/'.$headers['profile'], symlink($conf['portdir'].'/profiles/'.$headers['profile'], $C.'/etc/make.profile'))); $env=array( diff --git a/backend/functions/execution.php b/backend/functions/execution.php index c201adf..73cef31 100644 --- a/backend/functions/execution.php +++ b/backend/functions/execution.php @@ -1,11 +1,14 @@ <?php +// TODO this should be part of the task class function log_command(&$build, $command, $path=null, $env=null) { + log_msg("Executing $command... ", false); $descriptorspec=array( 0 => array('pipe', 'r'), // STDIN 1 => array('pipe', 'w'), // STDOUT 2 => array('pipe', 'w') // STDERR ); $task=new sql_task(null, $build->id, $command, null); + $task->start=time(); $task->write(); $p=proc_open($command, $descriptorspec, $pipes, $path, $env); foreach ($pipes as $pipe) { @@ -20,19 +23,16 @@ function log_command(&$build, $command, $path=null, $env=null) { $s=stream_select($outs, $null, $null, 1); if ($s) { $c=stream_get_contents($pipes[2]); - // TODO this really needs to go to the DB and carry metadata if ($c) { // STDERR $entry=new sql_buildlog_entry($task->id, $msg++, time(), 'stderr', $c); $entry->write(); - //log_msg($c, false); } $c=stream_get_contents($pipes[1]); if ($c) { // STDOUT $entry=new sql_buildlog_entry($task->id, $msg++, time(), 'stdout', $c); $entry->write(); - //log_msg($c, false); } } if ($status['running'] === false) { @@ -40,6 +40,7 @@ function log_command(&$build, $command, $path=null, $env=null) { break; } } + $task->finish=time(); foreach ($pipes as $pipe) { fclose($pipe); } @@ -48,6 +49,11 @@ function log_command(&$build, $command, $path=null, $env=null) { } $task->exit=$exit_status; $task->write(); + if ($exit_status == 0) { + log_msg(color('[success]', 'green')); + } else { + log_msg(color('[exit code '.$exit_status.']', 'red')); + } // Handle end status return $exit_status; } diff --git a/backend/functions/log.php b/backend/functions/log.php index c07fd73..1a40a43 100644 --- a/backend/functions/log.php +++ b/backend/functions/log.php @@ -17,6 +17,6 @@ function color($msg, $color) { } } function indent($msg, $tabs=1) { - return str_replace("\n", "\n".str_repeat("\t", $tabs), $msg); + return str_repeat("\t", $tabs).str_replace("\n", "\n".str_repeat("\t", $tabs), trim($msg)); } ?> |