summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-23 17:40:21 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-23 17:40:21 -0400
commitb05ad1ca39529ace7fc1c6a7cc05cfe587228c2f (patch)
tree4902d81ac0cce8e09fc790a553d76e762e86dbcf
parentUse stage3 tarballs instead of doing emerge system (diff)
downloadingenue-b05ad1ca39529ace7fc1c6a7cc05cfe587228c2f.tar.gz
ingenue-b05ad1ca39529ace7fc1c6a7cc05cfe587228c2f.tar.bz2
ingenue-b05ad1ca39529ace7fc1c6a7cc05cfe587228c2f.zip
Clean up backend API
-rwxr-xr-xbackend/backend.php2
-rw-r--r--backend/functions/api.php (renamed from backend/functions/execution.php)27
-rw-r--r--backend/functions/error_handling.php9
-rw-r--r--backend/functions/makedirs.php19
-rw-r--r--backend/functions/url.php2
-rw-r--r--backend/modules/gentoo_portage/setup.php6
-rw-r--r--todo7
7 files changed, 31 insertions, 41 deletions
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/execution.php b/backend/functions/api.php
index fbdb72f..843e410 100644
--- a/backend/functions/execution.php
+++ b/backend/functions/api.php
@@ -1,5 +1,5 @@
<?php
-function execute_command_with_all($description, $command, $fatal=true, $path=null, $env=null) {
+function execute_command_with_all($description, $command, $vital=true, $path=null, $env=null) {
global $build, $task;
if (isset($task))
end_internal_task();
@@ -10,7 +10,7 @@ function execute_command_with_all($description, $command, $fatal=true, $path=nul
$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 && $vital) {
if ($result > 0)
throw_exception($command.' returned with exit status '.$result);
elseif ($result == -128)
@@ -29,7 +29,7 @@ function execute_command_with_env($desc, $cmd, $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) {
+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) {
@@ -64,7 +64,7 @@ function log_msg($msg, $nl=true) {
$entry=new sql_buildlog_entry($build->id, $task->order, buildlog_entry_get_order(), time(), 'system', $msg);
$entry->write();
}
-function log_status($msg, $cmd) {
+function log_status($msg, $cmd, $vital=true) {
global $task;
if ($istask=!isset($task)) {
start_internal_task($msg);
@@ -76,6 +76,25 @@ function log_status($msg, $cmd) {
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<func_num_args(); $i++) {
+ $dir=func_get_arg($i);
+ if (is_array($dir)) {
+ call_user_func('makedirs', $dir);
+ } else {
+ makedir($dir);
+ }
+ }
+}
+function makedir($dir) {
+ global $workdir;
+ if (substr($dir, 0, 1) != '/')
+ $dir="$workdir/$dir";
+ if (!is_dir($dir))
+ log_status('Create '.$dir, mkdir($dir, 0700, true));
+}
?>
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 @@
-<?php
-function fatal($status) {
- if ($status === false) {
- throw new Exception('Failed');
- } else {
- 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 @@
-<?php
-function makedirs() {
- for ($i=0; $i<func_num_args(); $i++) {
- $dir=func_get_arg($i);
- if (is_array($dir)) {
- call_user_func('makedirs', $dir);
- } else {
- makedir($dir);
- }
- }
-}
-function makedir($dir) {
- global $workdir;
- if (substr($dir, 0, 1) != '/')
- $dir="$workdir/$dir";
- if (!is_dir($dir))
- fatal(log_status('Create '.$dir, mkdir($dir, 0700, true)));
-}
-?>
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 @@
<?php
-// TODO this needs to actually do something productive
+// FIXME TODO this needs to actually do something productive
function url($url) {
return 'http://soc/'.$url;
}
diff --git a/backend/modules/gentoo_portage/setup.php b/backend/modules/gentoo_portage/setup.php
index b9ca765..d946b81 100644
--- a/backend/modules/gentoo_portage/setup.php
+++ b/backend/modules/gentoo_portage/setup.php
@@ -2,7 +2,7 @@
start_internal_task('Create portage target environment');
$C=$W.'/config_root';
makedirs($I, $C, "$W/log", "$W/tmp");
-fatal(log_status("Making symlink $C/etc -> .", 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 ***