From b05ad1ca39529ace7fc1c6a7cc05cfe587228c2f Mon Sep 17 00:00:00 2001 From: Eudyptula Date: Thu, 23 Jul 2009 17:40:21 -0400 Subject: Clean up backend API --- backend/backend.php | 2 +- backend/functions/api.php | 100 +++++++++++++++++++++++++++++++ backend/functions/error_handling.php | 9 --- backend/functions/execution.php | 81 ------------------------- backend/functions/makedirs.php | 19 ------ backend/functions/url.php | 2 +- backend/modules/gentoo_portage/setup.php | 6 +- todo | 7 +-- 8 files changed, 108 insertions(+), 118 deletions(-) create mode 100644 backend/functions/api.php delete mode 100644 backend/functions/error_handling.php delete mode 100644 backend/functions/execution.php delete mode 100644 backend/functions/makedirs.php diff --git a/backend/backend.php b/backend/backend.php index c88f971..3e85c90 100755 --- a/backend/backend.php +++ b/backend/backend.php @@ -70,7 +70,7 @@ while (true) { require_once(BACKEND."/modules/$build->module/build.php"); // TODO check that build_proc exists $workdir=WORK.'/build-'.$build->id; - fatal(log_status('Creating work directory '.$workdir, mkdir($workdir, 0700))); + log_status('Creating work directory '.$workdir, mkdir($workdir, 0700)); $image=$build_proc($build, $opts, $workdir); require_once(BACKEND."/bundlers/{$opts['bundler']}.php"); $proc='bundle_'.$opts['bundler']; diff --git a/backend/functions/api.php b/backend/functions/api.php new file mode 100644 index 0000000..843e410 --- /dev/null +++ b/backend/functions/api.php @@ -0,0 +1,100 @@ + $_ENV['PATH'] + ); + $env=is_array($env)?array_merge($default_env, $env):$default_env; + $task=new sql_task($build->id, task_get_order(), 'exec', $description, $command); + $result=$task->execute($path, $env); + unset($GLOBALS['task']); + if ($result != 0 && $vital) { + if ($result > 0) + throw_exception($command.' returned with exit status '.$result); + elseif ($result == -128) + throw_exception($command.' received an unknown signal'); + else + throw_exception($command.' received signal '.-$result); + } + return $result; +} +function execute_command($desc, $cmd) { + return execute_command_with_all($desc, $cmd, true, null, null); +} +function execute_command_with_env($desc, $cmd, $env) { + return execute_command_with_all($desc, $cmd, true, null, $env); +} +function execute_command_with_path($desc, $cmd, $path) { + return execute_command_with_all($desc, $cmd, true, $path, null); +} +function execute_non_vital_command($desc, $cmd, $path=null, $env=null) { + return execute_command_with_all($desc, $cmd, false, $path, $env); +} +function start_internal_task($desc) { + global $build, $task; + if (isset($task)) + end_internal_task(); + debug($desc); + $task=new sql_task($build->id, task_get_order(), 'internal', $desc); + $task->start=time(); + $task->write(); +} +function end_internal_task($status=0) { + global $task; + if (isset($task)) { + if (!isset($task->finish)) + $task->finish=time(); + if (!isset($task->exit)) + $task->exit=$status; + $task->write(); + unset($GLOBALS['task']); + } +} +function log_msg($msg, $nl=true) { + global $build, $task; + if (!isset($task)) { + start_internal_task($msg); + debug('log_msg creating task... this is bad'); + return; + } + $msg.=$nl?"\n":''; + debug($msg); + $entry=new sql_buildlog_entry($build->id, $task->order, buildlog_entry_get_order(), time(), 'system', $msg); + $entry->write(); +} +function log_status($msg, $cmd, $vital=true) { + global $task; + if ($istask=!isset($task)) { + start_internal_task($msg); + } else { + log_msg($msg, false); + } + $status=is_string($cmd)?eval((strpos($cmd, 'return') === false?'return ':'').$cmd):$cmd; + if ($istask) + end_internal_task($status?0:1); + else + log_msg("... ".($status?color('[success]', 'green'):color('[failure]', 'red'))); + if ($vital && $status === false) + throw new Exception('Failed'); + return $status; +} +function makedirs() { + for ($i=0; $i diff --git a/backend/functions/error_handling.php b/backend/functions/error_handling.php deleted file mode 100644 index 945f556..0000000 --- a/backend/functions/error_handling.php +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/backend/functions/execution.php b/backend/functions/execution.php deleted file mode 100644 index fbdb72f..0000000 --- a/backend/functions/execution.php +++ /dev/null @@ -1,81 +0,0 @@ - $_ENV['PATH'] - ); - $env=is_array($env)?array_merge($default_env, $env):$default_env; - $task=new sql_task($build->id, task_get_order(), 'exec', $description, $command); - $result=$task->execute($path, $env); - unset($GLOBALS['task']); - if ($result != 0 && $fatal) { - if ($result > 0) - throw_exception($command.' returned with exit status '.$result); - elseif ($result == -128) - throw_exception($command.' received an unknown signal'); - else - throw_exception($command.' received signal '.-$result); - } - return $result; -} -function execute_command($desc, $cmd) { - return execute_command_with_all($desc, $cmd, true, null, null); -} -function execute_command_with_env($desc, $cmd, $env) { - return execute_command_with_all($desc, $cmd, true, null, $env); -} -function execute_command_with_path($desc, $cmd, $path) { - return execute_command_with_all($desc, $cmd, true, $path, null); -} -function execute_non_fatal_command($desc, $cmd, $path=null, $env=null) { - return execute_command_with_all($desc, $cmd, false, $path, $env); -} -function start_internal_task($desc) { - global $build, $task; - if (isset($task)) - end_internal_task(); - debug($desc); - $task=new sql_task($build->id, task_get_order(), 'internal', $desc); - $task->start=time(); - $task->write(); -} -function end_internal_task($status=0) { - global $task; - if (isset($task)) { - if (!isset($task->finish)) - $task->finish=time(); - if (!isset($task->exit)) - $task->exit=$status; - $task->write(); - unset($GLOBALS['task']); - } -} -function log_msg($msg, $nl=true) { - global $build, $task; - if (!isset($task)) { - start_internal_task($msg); - debug('log_msg creating task... this is bad'); - return; - } - $msg.=$nl?"\n":''; - debug($msg); - $entry=new sql_buildlog_entry($build->id, $task->order, buildlog_entry_get_order(), time(), 'system', $msg); - $entry->write(); -} -function log_status($msg, $cmd) { - global $task; - if ($istask=!isset($task)) { - start_internal_task($msg); - } else { - log_msg($msg, false); - } - $status=is_string($cmd)?eval((strpos($cmd, 'return') === false?'return ':'').$cmd):$cmd; - if ($istask) - end_internal_task($status?0:1); - else - log_msg("... ".($status?color('[success]', 'green'):color('[failure]', 'red'))); - return $status; -} -?> diff --git a/backend/functions/makedirs.php b/backend/functions/makedirs.php deleted file mode 100644 index de5f243..0000000 --- a/backend/functions/makedirs.php +++ /dev/null @@ -1,19 +0,0 @@ - diff --git a/backend/functions/url.php b/backend/functions/url.php index 42c197f..7aae32f 100644 --- a/backend/functions/url.php +++ b/backend/functions/url.php @@ -1,5 +1,5 @@ .", symlink('.', "$C/etc"))); +log_status("Making symlink $C/etc -> .", symlink('.', "$C/etc")); $makeconf=array( 'pkgdir' => $conf['pkgdir_root'].'/'.$profile->pkgdir, 'chost' => $headers['chost'], @@ -16,9 +16,9 @@ $contents=''; foreach ($makeconf as $name => $val) $contents.=strtoupper($name).'='.escapeshellarg($val)."\n"; unset($makeconf); -fatal(log_status('Writing '.$C.'/make.conf', file_put_contents($C.'/etc/make.conf', $contents))); +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'))); +log_status('Making make.profile symlink to '.$conf['portdir'].'/profiles/'.$headers['profile'], symlink($conf['portdir'].'/profiles/'.$headers['profile'], $C.'/etc/make.profile')); global $prtg_cfgrt; $prtg_cfgrt=array('PORTAGE_CONFIGROOT' => $C); end_internal_task(0); diff --git a/todo b/todo index 6c52996..a01c4e9 100644 --- a/todo +++ b/todo @@ -11,15 +11,14 @@ Add STDERR (maybe STDOUT) only option to log viewer Move bundler selection out of gentoo module and generalize it Allow config viewing for builds, not just configurations Add `flags` column to configurations, builds, use it to implement public and private things -Clean up backend API Add 'cancel', 'delete' options to builds Add build->configuration and configuration duplication Add map file for liveCD, load it into DB, etc. -*** Switch over to use stage3's instead of doing emerge system *** - Write script for fetching latest stage3's from the desired FTP dirs - Add ability to trim the stage3 to a minimum set of packages automatically (cached) or manually (present db-cached list of packages present in stage3 and allow user to select which to remove) +Write script for fetching latest stage3's from the desired FTP dirs +Add ability to trim the stage3 to a minimum set of packages automatically (cached) or manually (present db-cached list of packages present in stage3 and allow user to select which to remove) Only offer bundlers that will work - profiles without CD in map file can't make livecd, installcd, etc. Add option to remove default runscripts Add option to add arbitrary runscripts Add option to upload a kernel Add option to upload an arbitrary tar.gz/bz2 to be unzipped over the finished image +*** Fix backend url() function *** -- cgit v1.2.3-65-gdbad